Skip to content

Commit b70a57e

Browse files
committed
chore: update docs changelog in release init
1 parent 7d41c7f commit b70a57e

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

.generator/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,12 @@ def _update_changelog_for_library(
13731373
)
13741374
_write_text_file(changelog_dest, updated_content)
13751375

1376+
docs_relative_path = f"packages/{library_id}/docs/CHANGELOG.md"
1377+
docs_changelog_src = f"{repo}/{docs_relative_path}"
1378+
if os.path.lexists(docs_changelog_src):
1379+
docs_changelog_dst = f"{output}/{docs_relative_path}"
1380+
_write_text_file(docs_changelog_dst, updated_content)
1381+
13761382

13771383
def _is_mono_repo(repo: str) -> bool:
13781384
"""Determines if a library is generated or handwritten.
@@ -1424,7 +1430,6 @@ def handle_release_init(
14241430
)
14251431

14261432
if is_mono_repo:
1427-
14281433
# only a mono repo has a global changelog
14291434
_update_global_changelog(
14301435
f"{repo}/CHANGELOG.md",

.generator/test_cli.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def test_handle_configure_no_new_library(mocker):
312312
with pytest.raises(ValueError, match="Configuring a new library failed."):
313313
handle_configure()
314314

315+
315316
def test_create_new_changelog_for_library(mocker):
316317
"""Tests that the changelog files are created correctly."""
317318
library_id = "google-cloud-language"
@@ -325,7 +326,9 @@ def test_create_new_changelog_for_library(mocker):
325326
docs_changelog_path = f"{output}/packages/{library_id}/docs/CHANGELOG.md"
326327

327328
# Check that makedirs was called for both parent directories
328-
mock_makedirs.assert_any_call(os.path.dirname(package_changelog_path), exist_ok=True)
329+
mock_makedirs.assert_any_call(
330+
os.path.dirname(package_changelog_path), exist_ok=True
331+
)
329332
mock_makedirs.assert_any_call(os.path.dirname(docs_changelog_path), exist_ok=True)
330333
assert mock_makedirs.call_count == 2
331334

@@ -1141,29 +1144,34 @@ def test_get_previous_version_failure(mock_state_file):
11411144
_get_previous_version("google-cloud-does-not-exist", LIBRARIAN_DIR)
11421145

11431146

1144-
def test_update_changelog_for_library_success(mocker):
1145-
m = mock_open()
1146-
1147+
def test_update_changelog_for_library_writes_both_changelogs(mocker):
1148+
"""Tests that _update_changelog_for_library writes to both changelogs."""
11471149
mock_content = """# Changelog
11481150
11491151
[PyPI History][1]
11501152
11511153
[1]: https://pypi.org/project/google-cloud-language/#history
1152-
1153-
## [2.17.2](https://github.com/googleapis/google-cloud-python/compare/google-cloud-language-v2.17.1...google-cloud-language-v2.17.2) (2025-06-11)
1154-
11551154
"""
1156-
with unittest.mock.patch("cli.open", m):
1157-
mocker.patch("cli._read_text_file", return_value=mock_content)
1158-
_update_changelog_for_library(
1159-
"repo",
1160-
"output",
1161-
_MOCK_LIBRARY_CHANGES,
1162-
"1.2.3",
1163-
"1.2.2",
1164-
"google-cloud-language",
1165-
"CHANGELOG.md",
1166-
)
1155+
mock_read = mocker.patch("cli._read_text_file", return_value=mock_content)
1156+
mock_write = mocker.patch("cli._write_text_file")
1157+
mock_path_exists = mocker.patch("cli.os.path.lexists", return_value=True)
1158+
_update_changelog_for_library(
1159+
"repo",
1160+
"output",
1161+
_MOCK_LIBRARY_CHANGES,
1162+
"1.2.3",
1163+
"1.2.2",
1164+
"google-cloud-language",
1165+
"packages/google-cloud-language/CHANGELOG.md",
1166+
)
1167+
1168+
assert mock_write.call_count == 2
1169+
mock_write.assert_any_call(
1170+
"output/packages/google-cloud-language/CHANGELOG.md", mocker.ANY
1171+
)
1172+
mock_write.assert_any_call(
1173+
"output/packages/google-cloud-language/docs/CHANGELOG.md", mocker.ANY
1174+
)
11671175

11681176

11691177
def test_process_changelog_success():

0 commit comments

Comments
 (0)