-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into renovate/com.google.errorprone-error_prone_a…
…nnotations-2.x
- Loading branch information
Showing
14 changed files
with
431 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import click as click | ||
|
||
from library_generation.utils.pom_generator import generate_gapic_bom | ||
from library_generation.utils.pom_generator import generate_root_pom | ||
|
||
|
||
@click.group(invoke_without_command=False) | ||
@click.pass_context | ||
@click.version_option(message="%(version)s") | ||
def main(ctx): | ||
pass | ||
|
||
|
||
@main.command() | ||
@click.option( | ||
"--repository-path", | ||
required=True, | ||
type=str, | ||
help=""" | ||
Path to which the generated pom.xml goes. | ||
""", | ||
) | ||
@click.option( | ||
"--versions-file", | ||
required=True, | ||
type=str, | ||
help=""" | ||
The file containing version of libraries. | ||
Throw FileNotFoundError if the file doesn't exist. | ||
""", | ||
) | ||
def generate(repository_path: str, versions_file: str) -> None: | ||
generate_gapic_bom(repository_path=repository_path, versions_file=versions_file) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import click as click | ||
from library_generation.utils.pom_generator import generate_root_pom | ||
|
||
|
||
@click.group(invoke_without_command=False) | ||
@click.pass_context | ||
@click.version_option(message="%(version)s") | ||
def main(ctx): | ||
pass | ||
|
||
|
||
@main.command() | ||
@click.option( | ||
"--repository-path", | ||
required=True, | ||
type=str, | ||
help=""" | ||
Path to which the generated pom.xml goes. | ||
""", | ||
) | ||
def generate(repository_path: str) -> None: | ||
generate_root_pom(repository_path=repository_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import unittest | ||
from difflib import unified_diff | ||
from pathlib import Path | ||
|
||
from typing import List | ||
|
||
|
||
class FileComparator(unittest.TestCase): | ||
def compare_files(self, expect: str, actual: str): | ||
with open(expect, "r") as f: | ||
expected_lines = f.readlines() | ||
with open(actual, "r") as f: | ||
actual_lines = f.readlines() | ||
|
||
diff = list(unified_diff(expected_lines, actual_lines)) | ||
self.assertEqual( | ||
first=[], second=diff, msg="Unexpected file contents:\n" + "".join(diff) | ||
) | ||
|
||
|
||
def cleanup(files: List[str]): | ||
for file in files: | ||
path = Path(file).resolve() | ||
if path.is_file(): | ||
path.unlink() | ||
elif path.is_dir(): | ||
path.rmdir() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
library_generation/test/utils/monorepo_postprocessor_unit_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
import unittest | ||
|
||
from library_generation.test.test_utils import FileComparator | ||
from library_generation.test.test_utils import cleanup | ||
from library_generation.utils.monorepo_postprocessor import monorepo_postprocessing | ||
|
||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
resources_dir = os.path.join(script_dir, "..", "resources") | ||
file_comparator = FileComparator() | ||
|
||
|
||
class MonorepoPostprocessorTest(unittest.TestCase): | ||
def test_monorepo_postprocessing_valid_repository_success(self): | ||
repository_path = f"{resources_dir}/test_monorepo_postprocessing" | ||
versions_file = f"{repository_path}/versions.txt" | ||
files = [ | ||
f"{repository_path}/pom.xml", | ||
f"{repository_path}/gapic-libraries-bom/pom.xml", | ||
] | ||
cleanup(files) | ||
monorepo_postprocessing( | ||
repository_path=repository_path, versions_file=versions_file | ||
) | ||
file_comparator.compare_files( | ||
expect=f"{repository_path}/pom-golden.xml", | ||
actual=f"{repository_path}/pom.xml", | ||
) | ||
file_comparator.compare_files( | ||
expect=f"{repository_path}/gapic-libraries-bom/pom-golden.xml", | ||
actual=f"{repository_path}/gapic-libraries-bom/pom.xml", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
import unittest | ||
|
||
from library_generation.utils.pom_generator import get_version_from | ||
|
||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
resources_dir = os.path.join(script_dir, "..", "resources") | ||
|
||
|
||
class PomGeneratorTest(unittest.TestCase): | ||
def test_get_version_from_returns_current(self): | ||
versions_file = f"{resources_dir}/misc/versions.txt" | ||
artifact = "gax-grpc" | ||
self.assertEqual("2.33.1-SNAPSHOT", get_version_from(versions_file, artifact)) | ||
|
||
def test_get_version_from_returns_released(self): | ||
versions_file = f"{resources_dir}/misc/versions.txt" | ||
artifact = "gax-grpc" | ||
self.assertEqual("2.34.0", get_version_from(versions_file, artifact, True)) |
Oops, something went wrong.