Skip to content

Commit

Permalink
chore: always generate a repository if not a monorepo (#3131)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
diegomarquezp authored Aug 31, 2024
1 parent 0e784a2 commit 4cc72ad
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
25 changes: 24 additions & 1 deletion library_generation/cli/entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ def generate(
The commit history, if generated, will be available in
repository_path/pr_description.txt.
"""
__generate_repo_and_pr_description_impl(
baseline_generation_config_path, current_generation_config_path, repository_path
)


def __generate_repo_and_pr_description_impl(
baseline_generation_config_path: str,
current_generation_config_path: str,
repository_path: str,
):
"""
Implementation method for generate().
The decoupling of generate and __generate_repo_and_pr_description_impl is
meant to allow testing of this implementation function.
"""

default_generation_config_path = f"{os.getcwd()}/generation_config.yaml"

if (
Expand Down Expand Up @@ -129,10 +145,17 @@ def generate(
baseline_config=from_yaml(baseline_generation_config_path),
current_config=from_yaml(current_generation_config_path),
)
# pass None if this is not a monorepo in order to trigger the full
# generation
target_library_names = (
config_change.get_changed_libraries()
if config_change.current_config.is_monorepo()
else None
)
generate_from_yaml(
config=config_change.current_config,
repository_path=repository_path,
target_library_names=config_change.get_changed_libraries(),
target_library_names=target_library_names,
)
generate_pr_descriptions(
config_change=config_change,
Expand Down
Empty file modified library_generation/generate_pr_description.py
100644 → 100755
Empty file.
62 changes: 61 additions & 1 deletion library_generation/test/cli/entry_point_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
# limitations under the License.
import os
import unittest
from unittest.mock import patch, ANY
from click.testing import CliRunner
from library_generation.cli.entry_point import generate, validate_generation_config
from library_generation.cli.entry_point import (
generate,
validate_generation_config,
__generate_repo_and_pr_description_impl as generate_impl,
)
from library_generation.model.generation_config import from_yaml

script_dir = os.path.dirname(os.path.realpath(__file__))
test_resource_dir = os.path.join(script_dir, "..", "resources", "test-config")
Expand Down Expand Up @@ -78,3 +84,57 @@ def test_validate_generation_config_with_duplicate_library_name_raise_file_excep
result.output,
"have the same library name",
)

@patch("library_generation.cli.entry_point.generate_from_yaml")
@patch("library_generation.cli.entry_point.generate_pr_descriptions")
def test_generate_non_monorepo_without_changes_triggers_full_generation(
self,
generate_pr_descriptions,
generate_from_yaml,
):
"""
this tests confirms the behavior of generation of non monorepos
(HW libraries). generate() should call generate_from_yaml()
with target_library_names=None in order to trigger the full generation
"""
config_path = f"{test_resource_dir}/generation_config.yaml"
self.assertFalse(from_yaml(config_path).is_monorepo())
# we call the implementation method directly since click
# does special handling when a method is annotated with @main.command()
generate_impl(
baseline_generation_config_path=config_path,
current_generation_config_path=config_path,
repository_path=".",
)
generate_from_yaml.assert_called_with(
config=ANY, repository_path=ANY, target_library_names=None
)

@patch("library_generation.cli.entry_point.generate_from_yaml")
@patch("library_generation.cli.entry_point.generate_pr_descriptions")
def test_generate_non_monorepo_with_changes_triggers_full_generation(
self,
generate_pr_descriptions,
generate_from_yaml,
):
"""
this tests confirms the behavior of generation of non monorepos
(HW libraries). generate() should call generate_from_yaml()
with target_library_names=None in order to trigger the full generation
"""
baseline_config_path = f"{test_resource_dir}/generation_config.yaml"
current_config_path = (
f"{test_resource_dir}/generation_config_library_modified.yaml"
)
self.assertFalse(from_yaml(current_config_path).is_monorepo())
self.assertFalse(from_yaml(baseline_config_path).is_monorepo())
# we call the implementation method directly since click
# does special handling when a method is annotated with @main.command()
generate_impl(
baseline_generation_config_path=baseline_config_path,
current_generation_config_path=current_config_path,
repository_path=".",
)
generate_from_yaml.assert_called_with(
config=ANY, repository_path=ANY, target_library_names=None
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
gapic_generator_version: 2.34.0
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
libraries_bom_version: 26.37.0
libraries:
- api_shortname: cloudasset
name_pretty: Cloud Asset Inventory
product_documentation: "https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview"
api_description: "provides inventory services based on a time series database."
GAPICs:
- proto_path: google/cloud/asset/v1
- proto_path: google/cloud/asset/v1p1beta1
- proto_path: google/cloud/asset/v1p2beta1
- proto_path: google/cloud/asset/v1p5beta1
- proto_path: google/cloud/asset/v1p7beta1

0 comments on commit 4cc72ad

Please sign in to comment.