From 723cbcd9ed0d47ecb7bd109ebc2e35407a77a54e Mon Sep 17 00:00:00 2001 From: Mike Eltsufin Date: Wed, 22 Apr 2026 23:17:22 -0400 Subject: [PATCH] impl: fix spanner fallback and add test for split_release_note --- .../split_release_note.py | 31 ++++++++++--------- .github/release-note-generation/unit_test.py | 31 +++++++++++++++++-- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/.github/release-note-generation/split_release_note.py b/.github/release-note-generation/split_release_note.py index c304aae89d2f..3870af2130cb 100644 --- a/.github/release-note-generation/split_release_note.py +++ b/.github/release-note-generation/split_release_note.py @@ -69,6 +69,7 @@ def detect_modules(root_directory: Path): tree = ET.parse(module_pom_xml) root = tree.getroot() version = root.find('mvn:version', POM_NAMESPACES).text + api_name = None if owlbot_yaml_path.exists(): # If OwlBot configuration file exists (most cases), it's the better # source to get the OwlBot-generated pull request title prefix than @@ -78,21 +79,21 @@ def detect_modules(root_directory: Path): match = re.search(r'api-name: (.+)', owlbot_yaml_content) if match: api_name = match.group(1) - modules.append(LibraryModule(module_path, api_name, - version, - changelog)) + + if not api_name: + # Fallback to repo-metadata.json (e.g. for vertexai or Spanner transitional state) + if repo_metadata_path.exists(): + with open(repo_metadata_path, 'r') as file: + repo_metadata = json.load(file) + api_name = repo_metadata.get('api_shortname') + + if api_name: + modules.append(LibraryModule(module_path, api_name, + version, + changelog)) else: - # vertexai (handwritten) does not have OwlBot yaml file - with open(repo_metadata_path, 'r') as file: - repo_metadata = json.load(file) - api_name = repo_metadata['api_shortname'] - if api_name: - modules.append(LibraryModule(repo_metadata_path.parent, api_name, - version, - changelog)) - else: - raise Exception(f'repo_metadata_path {repo_metadata_path} does' - f' not have api_shortname field') + raise Exception(f'Could not determine api-name for {repo_metadata_path}') + return modules @@ -133,7 +134,7 @@ def group_changes_by_api(main_changes: [str]): elif section == BUG_FIXES_SECTION: api_to_changelog[api_name].bug_fixes.append(note) elif section == DEPENDENCIES_SECTION: - api_to_changelog[api_name].dependencies.append(note) + api_to_changelog[api_name].dependency_upgrades.append(note) return api_to_changelog diff --git a/.github/release-note-generation/unit_test.py b/.github/release-note-generation/unit_test.py index 9cb83b6253ab..852459333947 100644 --- a/.github/release-note-generation/unit_test.py +++ b/.github/release-note-generation/unit_test.py @@ -1,9 +1,11 @@ import unittest +import tempfile +import json +from pathlib import Path # Unit tests for split_release_note.py -from split_release_note import LibraryModule, create_changelog_entry, group_changes_by_api, ChangesOnApi -from pathlib import Path +from split_release_note import LibraryModule, create_changelog_entry, group_changes_by_api, ChangesOnApi, detect_modules dummy_module = LibraryModule( Path('release-note-generation/test/java-analyics-admin'), @@ -81,6 +83,31 @@ def test_group_changes_by_api(self): ['No change']), ['No change']) + def test_detect_modules_fallback(self): + with tempfile.TemporaryDirectory() as tmpdirname: + tmp_path = Path(tmpdirname) + module_path = tmp_path / "java-spanner" + module_path.mkdir() + + # Create minimal pom.xml + pom_path = module_path / "pom.xml" + with open(pom_path, "w") as f: + f.write('1.0.0') + + # Create .repo-metadata.json with api_shortname + metadata_path = module_path / ".repo-metadata.json" + with open(metadata_path, "w") as f: + json.dump({"api_shortname": "spanner"}, f) + + # Create CHANGELOG.md + changelog_path = module_path / "CHANGELOG.md" + changelog_path.touch() + + modules = detect_modules(tmp_path) + self.assertEqual(len(modules), 1) + self.assertEqual(modules[0].api_name, "spanner") + self.assertEqual(modules[0].version, "1.0.0") + if __name__ == "__main__": unittest.main()