Skip to content

Commit 3254868

Browse files
authored
chore: update GH action to remove stale entries from .release-please-manifest.json (#14504)
This PR updates the python script used in [configure_release_please.yml](https://github.com/googleapis/google-cloud-python/blob/main/.github/workflows/configure_release_please.yml) to remove stale entries from [.release-please-manifest.json](https://github.com/googleapis/google-cloud-python/blob/main/.release-please-manifest.json). This will fix the issue seen in #14503 where stale entries are deleted from `release-please-config.json` but not `.release-please-manifest.json`
1 parent 2673009 commit 3254868

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

.github/workflows/configure_release_please.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ on:
2020
push:
2121
paths:
2222
- '**/gapic_version.py'
23+
- '**/.OwlBot.yaml'
2324
branches:
2425
- main
2526

scripts/configure_release_please/configure_release_please.py

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_version_for_package(version_path: Path) -> Tuple[int]:
4343

4444
def get_packages_with_owlbot_yaml(packages_dir: Path = PACKAGES_DIR) -> List[Path]:
4545
"""
46-
Walks through all API packages in the specified `packages_dir` path.
46+
Walks through all API packages in the specified `packages_dir` path.
4747
4848
Args:
4949
packages_dir(pathlib.Path): Path to the directory which contains packages.
@@ -62,7 +62,8 @@ def configure_release_please_manifest(
6262
) -> None:
6363
"""
6464
This method updates the `.release-please-manifest.json` file in the directory
65-
`root_dir`.
65+
`root_dir`. It removes entries that are not in `package_dirs` and updates
66+
versions for both existing and new packages.
6667
6768
Args:
6869
package_dirs(List[pathlib.Path]): A list of Paths, one for each package in the
@@ -72,34 +73,50 @@ def configure_release_please_manifest(
7273
Returns:
7374
None
7475
"""
76+
7577
release_please_manifest = root_dir / ".release-please-manifest.json"
78+
7679
with open(release_please_manifest, "r") as f:
7780
manifest_json = json.load(f)
78-
for package_dir in package_dirs:
79-
if f"packages/{package_dir.name}" not in manifest_json:
80-
manifest_json[f"packages/{package_dir.name}"] = "0.0.0"
81-
82-
if not package_supports_gapic_version(package_dir):
83-
continue
84-
gapic_version_file = next(package_dir.rglob("**/gapic_version.py"), None)
85-
if gapic_version_file is None:
86-
raise Exception("Failed to find gapic_version.py")
87-
version = get_version_for_package(gapic_version_file)
88-
# check the version in gapic_version.py and update if newer than the default which is
89-
# 0.0.0 or 0.1.0.
90-
if version != (0, 0, 0) and version != (0, 1, 0):
91-
manifest_json[
92-
f"packages/{package_dir.name}"
93-
] = f"{version[0]}.{version[1]}.{version[2]}"
81+
82+
expected_package_paths = {
83+
f"packages/{package_dir.name}" for package_dir in package_dirs
84+
}
85+
86+
keys_to_remove = []
87+
for key in manifest_json.keys():
88+
if key not in expected_package_paths:
89+
keys_to_remove.append(key)
90+
91+
for key in keys_to_remove:
92+
print(f"Removed stale entry from manifest: {key}")
93+
del manifest_json[key]
94+
95+
for package_dir in package_dirs:
96+
if f"packages/{package_dir.name}" not in manifest_json:
97+
manifest_json[f"packages/{package_dir.name}"] = "0.0.0"
98+
99+
if not package_supports_gapic_version(package_dir):
100+
continue
101+
gapic_version_file = next(package_dir.rglob("**/gapic_version.py"), None)
102+
if gapic_version_file is None:
103+
raise Exception("Failed to find gapic_version.py")
104+
version = get_version_for_package(gapic_version_file)
105+
# check the version in gapic_version.py and update if newer than the default which is
106+
# 0.0.0 or 0.1.0.
107+
if version != (0, 0, 0) and version != (0, 1, 0):
108+
manifest_json[
109+
f"packages/{package_dir.name}"
110+
] = f"{version[0]}.{version[1]}.{version[2]}"
94111

95112
with open(release_please_manifest, "w") as f:
96113
json.dump(manifest_json, f, indent=4, sort_keys=True)
97114
f.write("\n")
98115

99116

100117
def package_supports_gapic_version(package_dir: str) -> bool:
101-
"""Returns True if the given package directory is expected to have gapic_version.py """
102-
118+
"""Returns True if the given package directory is expected to have gapic_version.py"""
119+
103120
for package in PACKAGES_WITHOUT_GAPIC_VERSION:
104121
if package_dir == Path(PACKAGES_DIR / package):
105122
return False
@@ -111,16 +128,16 @@ def configure_release_please_config(
111128
package_dirs: List[Path], root_dir: Path = ROOT_DIR
112129
) -> None:
113130
"""
114-
This method updates the `release-please-config.json` file in the directory
115-
`root_dir`. If `root_dir` is not provided, `google-cloud-python` will be used as the root.
131+
This method updates the `release-please-config.json` file in the directory
132+
`root_dir`. If `root_dir` is not provided, `google-cloud-python` will be used as the root.
116133
117-
Args:
118-
package_dirs(List[pathlib.Path]): A list of Paths, one for each package in
119-
the `packages/` folder whose entry will be updated in the release-please config.
120-
root_dir(pathlib.Path): The directory to update the `release-please-config.json`
134+
Args:
135+
package_dirs(List[pathlib.Path]): A list of Paths, one for each package in
136+
the `packages/` folder whose entry will be updated in the release-please config.
137+
root_dir(pathlib.Path): The directory to update the `release-please-config.json`
121138
122-
Returns:
123-
None
139+
Returns:
140+
None
124141
"""
125142
release_please_config = root_dir / "release-please-config.json"
126143
config_json = {"packages": {}}

0 commit comments

Comments
 (0)