Skip to content

Commit 56c7ca5

Browse files
authored
feat: add libraries_bom_version to generation configuration (#2639)
In this PR: - Add `libraries_bom_version` as a required parameter in generation config. The integration test is verified using a feature branch of synthtool: googleapis/synthtool#1956. The synthtool commit in integration test is changed to `63cc541da2c45fcfca2136c43e638da1fbae174d` after the above feature branch is merged.
1 parent e542af8 commit 56c7ca5

16 files changed

+113
-63
lines changed

library_generation/README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ They are shared by library level parameters.
9797
| protobuf_version | No | inferred from the generator if not specified |
9898
| grpc_version | No | inferred from the generator if not specified |
9999
| googleapis-commitish | Yes | |
100+
| libraries_bom_version | Yes | |
100101
| owlbot-cli-image | Yes | |
101102
| synthtool-commitish | Yes | |
102103
| template_excludes | Yes | |
@@ -147,6 +148,7 @@ The GAPIC level parameters define how to generate a GAPIC library.
147148
gapic_generator_version: 2.34.0
148149
protobuf_version: 25.2
149150
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
151+
libraries_bom_version: 26.37.0
150152
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
151153
synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5
152154
destination_path: google-cloud-java
@@ -192,11 +194,15 @@ libraries:
192194
193195
# Local Environment Setup before running `entry_point.py`
194196

195-
1. Assuming Python 3 is installed, follow official guide from [Python.org](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) to create a virtual environment. The virtual environment can be installed to any folder, usually it is recommended to be installed under the root folder of the project(`sdk-platform-java` in this case).
196-
2. Assuming the virtual environment is installed under `sdk-platform-java`. Run the following command under the root folder of `sdk-platform-java` to install the dependencies of `library_generation`
197+
1. Assuming Python 3 is installed, follow official guide from [Python.org](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) to create a virtual environment.
198+
The virtual environment can be installed to any folder, usually it is recommended to be installed under the root folder of the project(`sdk-platform-java` in this case).
199+
2. Assuming the virtual environment is installed under `sdk-platform-java`.
200+
Run the following command under the root folder of `sdk-platform-java` to install the dependencies of `library_generation`
201+
197202
```bash
198203
python -m pip install -r library_generation/requirements.txt
199204
```
205+
200206
3. Run the following command to install `library_generation` as a module, which allows the `library_generation` module to be imported from anywhere
201207
```bash
202208
python -m pip install library_generation/

library_generation/model/generation_config.py

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(
2929
self,
3030
gapic_generator_version: str,
3131
googleapis_commitish: str,
32+
libraries_bom_version: str,
3233
owlbot_cli_image: str,
3334
synthtool_commitish: str,
3435
template_excludes: List[str],
@@ -38,6 +39,7 @@ def __init__(
3839
):
3940
self.gapic_generator_version = gapic_generator_version
4041
self.googleapis_commitish = googleapis_commitish
42+
self.libraris_bom_version = libraries_bom_version
4143
self.owlbot_cli_image = owlbot_cli_image
4244
self.synthtool_commitish = synthtool_commitish
4345
self.template_excludes = template_excludes
@@ -116,6 +118,7 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig:
116118
grpc_version=__optional(config, "grpc_version", None),
117119
protobuf_version=__optional(config, "protobuf_version", None),
118120
googleapis_commitish=__required(config, "googleapis_commitish"),
121+
libraries_bom_version=__required(config, "libraries_bom_version"),
119122
owlbot_cli_image=__required(config, "owlbot_cli_image"),
120123
synthtool_commitish=__required(config, "synthtool_commitish"),
121124
template_excludes=__required(config, "template_excludes"),

library_generation/owlbot/src/apply_repo_templates.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def apply_repo_templates(configuration_yaml_path: str, monorepo: bool) -> None:
2424
excludes=config.template_excludes,
2525
template_path=Path(repo_templates_path),
2626
monorepo=monorepo,
27+
libraries_bom_version=config.libraris_bom_version,
2728
)
2829

2930

library_generation/owlbot/templates/java_library/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
4444
<dependency>
4545
<groupId>com.google.cloud</groupId>
4646
<artifactId>libraries-bom</artifactId>
47-
<version>{{ metadata['latest_bom_version'] }}</version>
47+
<version>{{ metadata['libraries_bom_version'] }}</version>
4848
<type>pom</type>
4949
<scope>import</scope>
5050
</dependency>

library_generation/test/generate_repo_unit_tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __get_an_empty_generation_config() -> GenerationConfig:
4545
return GenerationConfig(
4646
gapic_generator_version="",
4747
googleapis_commitish="",
48+
libraries_bom_version="",
4849
synthtool_commitish="",
4950
owlbot_cli_image="",
5051
template_excludes=[],

library_generation/test/model/config_change_unit_tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def __get_a_gen_config(
239239
return GenerationConfig(
240240
gapic_generator_version="",
241241
googleapis_commitish=googleapis_commitish,
242+
libraries_bom_version="",
242243
owlbot_cli_image="",
243244
synthtool_commitish="",
244245
template_excludes=[],

library_generation/test/model/generation_config_unit_test.py

+59-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import os
1515
import unittest
1616
from pathlib import Path
17-
1817
from library_generation.model.generation_config import from_yaml, GenerationConfig
1918
from library_generation.model.library_config import LibraryConfig
2019

@@ -39,6 +38,63 @@
3938

4039

4140
class GenerationConfigTest(unittest.TestCase):
41+
def test_from_yaml_succeeds(self):
42+
config = from_yaml(f"{test_config_dir}/generation_config.yaml")
43+
self.assertEqual("2.34.0", config.gapic_generator_version)
44+
self.assertEqual(25.2, config.protobuf_version)
45+
self.assertEqual(
46+
"1a45bf7393b52407188c82e63101db7dc9c72026", config.googleapis_commitish
47+
)
48+
self.assertEqual("26.37.0", config.libraris_bom_version)
49+
self.assertEqual(
50+
"sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409",
51+
config.owlbot_cli_image,
52+
)
53+
self.assertEqual(
54+
"6612ab8f3afcd5e292aecd647f0fa68812c9f5b5", config.synthtool_commitish
55+
)
56+
self.assertEqual(
57+
[
58+
".github/*",
59+
".kokoro/*",
60+
"samples/*",
61+
"CODE_OF_CONDUCT.md",
62+
"CONTRIBUTING.md",
63+
"LICENSE",
64+
"SECURITY.md",
65+
"java.header",
66+
"license-checks.xml",
67+
"renovate.json",
68+
".gitignore",
69+
],
70+
config.template_excludes,
71+
)
72+
library = config.libraries[0]
73+
self.assertEqual("cloudasset", library.api_shortname)
74+
self.assertEqual("Cloud Asset Inventory", library.name_pretty)
75+
self.assertEqual(
76+
"https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview",
77+
library.product_documentation,
78+
)
79+
self.assertEqual(
80+
"provides inventory services based on a time series database.",
81+
library.api_description,
82+
)
83+
self.assertEqual("asset", library.library_name)
84+
self.assertEqual("@googleapis/analytics-dpe", library.codeowner_team)
85+
self.assertEqual(
86+
"proto-google-iam-v1-bom,google-iam-policy,proto-google-iam-v1",
87+
library.excluded_poms,
88+
)
89+
self.assertEqual("google-iam-policy", library.excluded_dependencies)
90+
gapics = library.gapic_configs
91+
self.assertEqual(5, len(gapics))
92+
self.assertEqual("google/cloud/asset/v1", gapics[0].proto_path)
93+
self.assertEqual("google/cloud/asset/v1p1beta1", gapics[1].proto_path)
94+
self.assertEqual("google/cloud/asset/v1p2beta1", gapics[2].proto_path)
95+
self.assertEqual("google/cloud/asset/v1p5beta1", gapics[3].proto_path)
96+
self.assertEqual("google/cloud/asset/v1p7beta1", gapics[4].proto_path)
97+
4298
def test_get_proto_path_to_library_name_success(self):
4399
paths = from_yaml(
44100
f"{test_config_dir}/generation_config.yaml"
@@ -58,6 +114,7 @@ def test_is_monorepo_with_one_library_returns_false(self):
58114
config = GenerationConfig(
59115
gapic_generator_version="",
60116
googleapis_commitish="",
117+
libraries_bom_version="",
61118
owlbot_cli_image="",
62119
synthtool_commitish="",
63120
template_excludes=[],
@@ -69,6 +126,7 @@ def test_is_monorepo_with_two_libraries_returns_true(self):
69126
config = GenerationConfig(
70127
gapic_generator_version="",
71128
googleapis_commitish="",
129+
libraries_bom_version="",
72130
owlbot_cli_image="",
73131
synthtool_commitish="",
74132
template_excludes=[],

library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
gapic_generator_version: 2.37.0
1+
gapic_generator_version: 2.38.1
22
protobuf_version: 25.2
33
googleapis_commitish: a17d4caf184b050d50cacf2b0d579ce72c31ce74
4+
libraries_bom_version: 26.37.0
45
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
5-
synthtool_commitish: 5e1fb2032fa44bc170677b38713023b4fec51a4e
6+
synthtool_commitish: 63cc541da2c45fcfca2136c43e638da1fbae174d
67
template_excludes:
78
- ".github/*"
89
- ".kokoro/*"

library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
gapic_generator_version: 2.38.1
22
protobuf_version: 25.2
33
googleapis_commitish: 4ce0ff67a3d4509be641cbe47a35844ddc1268fc
4+
libraries_bom_version: 26.37.0
45
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
5-
synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5
6+
synthtool_commitish: 63cc541da2c45fcfca2136c43e638da1fbae174d
67
template_excludes:
78
- ".github/*"
89
- ".kokoro/*"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
gapic_generator_version: 2.34.0
2+
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
3+
libraries:
4+
- api_shortname: apigeeconnect
5+
name_pretty: Apigee Connect
6+
api_description: "allows the Apigee hybrid management"
7+
product_documentation: "https://cloud.google.com/apigee/docs/hybrid/v1.3/apigee-connect/"
8+
GAPICs:
9+
- proto_path: google/cloud/apigeeconnect/v1

library_generation/test/resources/test-config/config_without_owlbot.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
gapic_generator_version: 2.34.0
22
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
3+
libraries_bom_version: 26.37.0
34
libraries:
45
- api_shortname: apigeeconnect
56
name_pretty: Apigee Connect

library_generation/test/resources/test-config/config_without_synthtool.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
gapic_generator_version: 2.34.0
22
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
3+
libraries_bom_version: 26.37.0
34
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
45
libraries:
56
- api_shortname: apigeeconnect

library_generation/test/resources/test-config/config_without_temp_excludes.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
gapic_generator_version: 2.34.0
22
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
3+
libraries_bom_version: 26.37.0
34
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
45
synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5
56
libraries:

library_generation/test/resources/test-config/generation_config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
gapic_generator_version: 2.34.0
22
protobuf_version: 25.2
33
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
4+
libraries_bom_version: 26.37.0
45
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
56
synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5
67
template_excludes:

library_generation/test/utilities_unit_tests.py

+5-56
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ def test_eprint_valid_input_succeeds(self):
143143
"googleapis_commitish",
144144
f"{test_config_dir}/config_without_googleapis.yaml",
145145
),
146+
(
147+
"libraries_bom_version",
148+
f"{test_config_dir}/config_without_libraries_bom_version.yaml",
149+
),
146150
("owlbot_cli_image", f"{test_config_dir}/config_without_owlbot.yaml"),
147151
("synthtool_commitish", f"{test_config_dir}/config_without_synthtool.yaml"),
148152
(
@@ -159,62 +163,6 @@ def test_from_yaml_without_key_fails(self, error_message_contains, path_to_yaml)
159163
path_to_yaml,
160164
)
161165

162-
def test_from_yaml_succeeds(self):
163-
config = from_yaml(f"{test_config_dir}/generation_config.yaml")
164-
self.assertEqual("2.34.0", config.gapic_generator_version)
165-
self.assertEqual(25.2, config.protobuf_version)
166-
self.assertEqual(
167-
"1a45bf7393b52407188c82e63101db7dc9c72026", config.googleapis_commitish
168-
)
169-
self.assertEqual(
170-
"sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409",
171-
config.owlbot_cli_image,
172-
)
173-
self.assertEqual(
174-
"6612ab8f3afcd5e292aecd647f0fa68812c9f5b5", config.synthtool_commitish
175-
)
176-
self.assertEqual(
177-
[
178-
".github/*",
179-
".kokoro/*",
180-
"samples/*",
181-
"CODE_OF_CONDUCT.md",
182-
"CONTRIBUTING.md",
183-
"LICENSE",
184-
"SECURITY.md",
185-
"java.header",
186-
"license-checks.xml",
187-
"renovate.json",
188-
".gitignore",
189-
],
190-
config.template_excludes,
191-
)
192-
library = config.libraries[0]
193-
self.assertEqual("cloudasset", library.api_shortname)
194-
self.assertEqual("Cloud Asset Inventory", library.name_pretty)
195-
self.assertEqual(
196-
"https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview",
197-
library.product_documentation,
198-
)
199-
self.assertEqual(
200-
"provides inventory services based on a time series database.",
201-
library.api_description,
202-
)
203-
self.assertEqual("asset", library.library_name)
204-
self.assertEqual("@googleapis/analytics-dpe", library.codeowner_team)
205-
self.assertEqual(
206-
"proto-google-iam-v1-bom,google-iam-policy,proto-google-iam-v1",
207-
library.excluded_poms,
208-
)
209-
self.assertEqual("google-iam-policy", library.excluded_dependencies)
210-
gapics = library.gapic_configs
211-
self.assertEqual(5, len(gapics))
212-
self.assertEqual("google/cloud/asset/v1", gapics[0].proto_path)
213-
self.assertEqual("google/cloud/asset/v1p1beta1", gapics[1].proto_path)
214-
self.assertEqual("google/cloud/asset/v1p2beta1", gapics[2].proto_path)
215-
self.assertEqual("google/cloud/asset/v1p5beta1", gapics[3].proto_path)
216-
self.assertEqual("google/cloud/asset/v1p7beta1", gapics[4].proto_path)
217-
218166
@parameterized.expand(
219167
[
220168
("BUILD_no_additional_protos.bazel", " "),
@@ -481,6 +429,7 @@ def __get_a_gen_config(
481429
return GenerationConfig(
482430
gapic_generator_version="",
483431
googleapis_commitish="",
432+
libraries_bom_version="",
484433
owlbot_cli_image="",
485434
synthtool_commitish="",
486435
template_excludes=[

library_generation/test/utils/generation_config_comparator_unit_tests.py

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def setUp(self) -> None:
3939
self.baseline_config = GenerationConfig(
4040
gapic_generator_version="",
4141
googleapis_commitish="",
42+
libraries_bom_version="",
4243
owlbot_cli_image="",
4344
synthtool_commitish="",
4445
template_excludes=[],
@@ -49,6 +50,7 @@ def setUp(self) -> None:
4950
self.current_config = GenerationConfig(
5051
gapic_generator_version="",
5152
googleapis_commitish="",
53+
libraries_bom_version="",
5254
owlbot_cli_image="",
5355
synthtool_commitish="",
5456
template_excludes=[],
@@ -91,6 +93,20 @@ def test_compare_config_generator_update(self):
9193
self.assertEqual("gapic_generator_version", config_change.changed_param)
9294
self.assertEqual("1.2.4", config_change.current_value)
9395

96+
def test_compare_config_libraries_bom_update(self):
97+
self.baseline_config.libraris_bom_version = "26.36.0"
98+
self.current_config.libraris_bom_version = "26.37.0"
99+
result = compare_config(
100+
baseline_config=self.baseline_config,
101+
current_config=self.current_config,
102+
)
103+
self.assertTrue(
104+
len(result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE]) == 1
105+
)
106+
config_change = result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE][0]
107+
self.assertEqual("libraris_bom_version", config_change.changed_param)
108+
self.assertEqual("26.37.0", config_change.current_value)
109+
94110
def test_compare_config_owlbot_cli_update(self):
95111
self.baseline_config.owlbot_cli_image = "image_version_123"
96112
self.current_config.owlbot_cli_image = "image_version_456"

0 commit comments

Comments
 (0)