Skip to content

Commit aa54771

Browse files
authored
chore(librarian): allow onboarding new packages (#14450)
This PR resolves the following error by ignoring libraries which which do not have entries in `release-please-manifest.json` when onboarding new packages. These are likely libraries that have already onboarded. We will also preserve existing entries in state.yaml for these libraries. ``` (py392) partheniou@partheniou-vm-3:~/git/google-cloud-python/scripts/configure_state_yaml$ python3 configure_state_yaml.py Traceback (most recent call last): File "/usr/local/google/home/partheniou/git/google-cloud-python/scripts/configure_state_yaml/configure_state_yaml.py", line 94, in <module> configure_state_yaml() File "/usr/local/google/home/partheniou/git/google-cloud-python/scripts/configure_state_yaml/configure_state_yaml.py", line 67, in configure_state_yaml "version": release_please_manifest[f"packages/{package_name}"], KeyError: 'packages/google-cloud-dlp' ``` Towards googleapis/librarian#761
1 parent acf0e4f commit aa54771

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

scripts/configure_state_yaml/configure_state_yaml.py

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def configure_state_yaml() -> None:
4444
with open(PACKAGES_TO_ONBOARD_YAML, "r") as packages_to_onboard_yaml_file:
4545
packages_to_onboard = yaml.safe_load(packages_to_onboard_yaml_file)
4646

47-
state_dict[
48-
"image"
49-
] = "us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator:latest"
50-
state_dict["libraries"] = []
47+
state_dict = {}
48+
with open(LIBRARIAN_YAML, "r") as state_yaml_file:
49+
state_dict = yaml.safe_load(state_yaml_file)
50+
5151
for package_name in packages_to_onboard["packages_to_onboard"]:
5252
package_path = Path(PACKAGES_DIR / package_name).resolve()
5353
api_paths = []
@@ -61,30 +61,34 @@ def configure_state_yaml() -> None:
6161
}
6262
]
6363
)
64-
state_dict["libraries"].append(
65-
{
66-
"id": package_name,
67-
"version": release_please_manifest[f"packages/{package_name}"],
68-
"last_generated_commit": "97a83d76a09a7f6dcab43675c87bdfeb5bcf1cb5",
69-
"apis": api_paths,
70-
"source_roots": [f"packages/{package_path.name}"],
71-
"preserve_regex": [
72-
# Use the full path to avoid ambiguity with the root CHANGELOG.md
73-
f"packages/{package_path.name}/CHANGELOG.md",
74-
"docs/CHANGELOG.md",
75-
"docs/README.rst",
76-
"samples/README.txt",
77-
"tar.gz",
78-
"gapic_version.py",
79-
"samples/generated_samples/snippet_metadata_",
80-
"scripts/client-post-processing",
81-
"samples/snippets/README.rst",
82-
"tests/system",
83-
],
84-
"remove_regex": [f"packages/{package_path.name}"],
85-
"tag_format": "{id}-v{version}",
86-
}
87-
)
64+
65+
# Skip libraries which are not present in the release please manifest as
66+
# these are likely libraries that have already onboarded.
67+
if release_please_manifest.get(f"packages/{package_name}", None):
68+
state_dict["libraries"].append(
69+
{
70+
"id": package_name,
71+
"version": release_please_manifest[f"packages/{package_name}"],
72+
"last_generated_commit": "97a83d76a09a7f6dcab43675c87bdfeb5bcf1cb5",
73+
"apis": api_paths,
74+
"source_roots": [f"packages/{package_path.name}"],
75+
"preserve_regex": [
76+
# Use the full path to avoid ambiguity with the root CHANGELOG.md
77+
f"packages/{package_path.name}/CHANGELOG.md",
78+
"docs/CHANGELOG.md",
79+
"docs/README.rst",
80+
"samples/README.txt",
81+
"tar.gz",
82+
"gapic_version.py",
83+
"samples/generated_samples/snippet_metadata_",
84+
"scripts/client-post-processing",
85+
"samples/snippets/README.rst",
86+
"tests/system",
87+
],
88+
"remove_regex": [f"packages/{package_path.name}"],
89+
"tag_format": "{id}-v{version}",
90+
}
91+
)
8892

8993
with open(LIBRARIAN_YAML, "w") as f:
9094
yaml.dump(state_dict, f, sort_keys=False, indent=2)

0 commit comments

Comments
 (0)