Skip to content

Commit 4cc72ad

Browse files
chore: always generate a repository if not a monorepo (#3131)
Context in [this doc](https://docs.google.com/document/d/1wrpyBtphdenM3BNelcnpBKGADYrGJUo686HXvSA0h-0/edit?pli=1&tab=t.luhbzlh25mfs#bookmark=id.ruacqw13dxd2) This PR makes the generation workflow to always get triggered when the target repository is not a monorepo (i.e. handwritten libraries). This will still respect other changes between baseline and current configurations when it comes to PR description generation, but if no config changes are detected then no PR description will be created, assuming that the PR description of the original PR that will trigger the generation will be informative enough.
1 parent 0e784a2 commit 4cc72ad

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

library_generation/cli/entry_point.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ def generate(
8888
The commit history, if generated, will be available in
8989
repository_path/pr_description.txt.
9090
"""
91+
__generate_repo_and_pr_description_impl(
92+
baseline_generation_config_path, current_generation_config_path, repository_path
93+
)
94+
95+
96+
def __generate_repo_and_pr_description_impl(
97+
baseline_generation_config_path: str,
98+
current_generation_config_path: str,
99+
repository_path: str,
100+
):
101+
"""
102+
Implementation method for generate().
103+
The decoupling of generate and __generate_repo_and_pr_description_impl is
104+
meant to allow testing of this implementation function.
105+
"""
106+
91107
default_generation_config_path = f"{os.getcwd()}/generation_config.yaml"
92108

93109
if (
@@ -129,10 +145,17 @@ def generate(
129145
baseline_config=from_yaml(baseline_generation_config_path),
130146
current_config=from_yaml(current_generation_config_path),
131147
)
148+
# pass None if this is not a monorepo in order to trigger the full
149+
# generation
150+
target_library_names = (
151+
config_change.get_changed_libraries()
152+
if config_change.current_config.is_monorepo()
153+
else None
154+
)
132155
generate_from_yaml(
133156
config=config_change.current_config,
134157
repository_path=repository_path,
135-
target_library_names=config_change.get_changed_libraries(),
158+
target_library_names=target_library_names,
136159
)
137160
generate_pr_descriptions(
138161
config_change=config_change,

library_generation/generate_pr_description.py

100644100755
File mode changed.

library_generation/test/cli/entry_point_unit_tests.py

+61-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
# limitations under the License.
1414
import os
1515
import unittest
16+
from unittest.mock import patch, ANY
1617
from click.testing import CliRunner
17-
from library_generation.cli.entry_point import generate, validate_generation_config
18+
from library_generation.cli.entry_point import (
19+
generate,
20+
validate_generation_config,
21+
__generate_repo_and_pr_description_impl as generate_impl,
22+
)
23+
from library_generation.model.generation_config import from_yaml
1824

1925
script_dir = os.path.dirname(os.path.realpath(__file__))
2026
test_resource_dir = os.path.join(script_dir, "..", "resources", "test-config")
@@ -78,3 +84,57 @@ def test_validate_generation_config_with_duplicate_library_name_raise_file_excep
7884
result.output,
7985
"have the same library name",
8086
)
87+
88+
@patch("library_generation.cli.entry_point.generate_from_yaml")
89+
@patch("library_generation.cli.entry_point.generate_pr_descriptions")
90+
def test_generate_non_monorepo_without_changes_triggers_full_generation(
91+
self,
92+
generate_pr_descriptions,
93+
generate_from_yaml,
94+
):
95+
"""
96+
this tests confirms the behavior of generation of non monorepos
97+
(HW libraries). generate() should call generate_from_yaml()
98+
with target_library_names=None in order to trigger the full generation
99+
"""
100+
config_path = f"{test_resource_dir}/generation_config.yaml"
101+
self.assertFalse(from_yaml(config_path).is_monorepo())
102+
# we call the implementation method directly since click
103+
# does special handling when a method is annotated with @main.command()
104+
generate_impl(
105+
baseline_generation_config_path=config_path,
106+
current_generation_config_path=config_path,
107+
repository_path=".",
108+
)
109+
generate_from_yaml.assert_called_with(
110+
config=ANY, repository_path=ANY, target_library_names=None
111+
)
112+
113+
@patch("library_generation.cli.entry_point.generate_from_yaml")
114+
@patch("library_generation.cli.entry_point.generate_pr_descriptions")
115+
def test_generate_non_monorepo_with_changes_triggers_full_generation(
116+
self,
117+
generate_pr_descriptions,
118+
generate_from_yaml,
119+
):
120+
"""
121+
this tests confirms the behavior of generation of non monorepos
122+
(HW libraries). generate() should call generate_from_yaml()
123+
with target_library_names=None in order to trigger the full generation
124+
"""
125+
baseline_config_path = f"{test_resource_dir}/generation_config.yaml"
126+
current_config_path = (
127+
f"{test_resource_dir}/generation_config_library_modified.yaml"
128+
)
129+
self.assertFalse(from_yaml(current_config_path).is_monorepo())
130+
self.assertFalse(from_yaml(baseline_config_path).is_monorepo())
131+
# we call the implementation method directly since click
132+
# does special handling when a method is annotated with @main.command()
133+
generate_impl(
134+
baseline_generation_config_path=baseline_config_path,
135+
current_generation_config_path=current_config_path,
136+
repository_path=".",
137+
)
138+
generate_from_yaml.assert_called_with(
139+
config=ANY, repository_path=ANY, target_library_names=None
140+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
gapic_generator_version: 2.34.0
2+
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
3+
libraries_bom_version: 26.37.0
4+
libraries:
5+
- api_shortname: cloudasset
6+
name_pretty: Cloud Asset Inventory
7+
product_documentation: "https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview"
8+
api_description: "provides inventory services based on a time series database."
9+
GAPICs:
10+
- proto_path: google/cloud/asset/v1
11+
- proto_path: google/cloud/asset/v1p1beta1
12+
- proto_path: google/cloud/asset/v1p2beta1
13+
- proto_path: google/cloud/asset/v1p5beta1
14+
- proto_path: google/cloud/asset/v1p7beta1

0 commit comments

Comments
 (0)