Skip to content

Commit 0747902

Browse files
authored
chore: update release-init to release-stage (#14856)
This PR updates `release-init` to `release-stage`. Fixes googleapis/librarian#2786 🦕
1 parent 735dcad commit 0747902

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

.generator/cli.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
BUILD_REQUEST_FILE = "build-request.json"
4747
GENERATE_REQUEST_FILE = "generate-request.json"
4848
CONFIGURE_REQUEST_FILE = "configure-request.json"
49-
RELEASE_INIT_REQUEST_FILE = "release-init-request.json"
49+
RELEASE_STAGE_REQUEST_FILE = "release-stage-request.json"
5050
STATE_YAML_FILE = "state.yaml"
5151

5252
INPUT_DIR = "input"
@@ -1433,38 +1433,38 @@ def _is_mono_repo(repo: str) -> bool:
14331433
return Path(f"{repo}/packages").exists()
14341434

14351435

1436-
def handle_release_init(
1436+
def handle_release_stage(
14371437
librarian: str = LIBRARIAN_DIR, repo: str = REPO_DIR, output: str = OUTPUT_DIR
14381438
):
14391439
"""The main coordinator for the release preparation process.
14401440
14411441
This function prepares for the release of client libraries by reading a
1442-
`librarian/release-init-request.json` file. The primary responsibility is
1442+
`librarian/release-stage-request.json` file. The primary responsibility is
14431443
to update all required files with the new version and commit information
14441444
for libraries that have the `release_triggered` field set to `True`.
14451445
14461446
See https://github.com/googleapis/librarian/blob/main/doc/container-contract.md#generate-container-command
14471447
14481448
Args:
14491449
librarian(str): Path to the directory in the container which contains
1450-
the `release-init-request.json` file.
1450+
the `release-stage-request.json` file.
14511451
repo(str): This directory will contain all directories that make up a
14521452
library, the .librarian folder, and any global file declared in
14531453
the config.yaml.
14541454
output(str): Path to the directory in the container where modified
14551455
code should be placed.
14561456
14571457
Raises:
1458-
ValueError: if the version in `release-init-request.json` is
1458+
ValueError: if the version in `release-stage-request.json` is
14591459
the same as the version in state.yaml or if the
1460-
`release-init-request.json` file in the given
1460+
`release-stage-request.json` file in the given
14611461
librarian directory cannot be read.
14621462
"""
14631463
try:
14641464
is_mono_repo = _is_mono_repo(repo)
14651465

1466-
# Read a release-init-request.json file
1467-
request_data = _read_json_file(f"{librarian}/{RELEASE_INIT_REQUEST_FILE}")
1466+
# Read a release-stage-request.json file
1467+
request_data = _read_json_file(f"{librarian}/{RELEASE_STAGE_REQUEST_FILE}")
14681468
libraries_to_prep_for_release = _get_libraries_to_prepare_for_release(
14691469
request_data
14701470
)
@@ -1488,7 +1488,7 @@ def handle_release_init(
14881488
previous_version = _get_previous_version(library_id, librarian)
14891489
if previous_version == version:
14901490
raise ValueError(
1491-
f"The version in {RELEASE_INIT_REQUEST_FILE} is the same as the version in {STATE_YAML_FILE}\n"
1491+
f"The version in {RELEASE_STAGE_REQUEST_FILE} is the same as the version in {STATE_YAML_FILE}\n"
14921492
f"{library_id} version: {previous_version}\n"
14931493
)
14941494

@@ -1506,9 +1506,9 @@ def handle_release_init(
15061506
)
15071507

15081508
except Exception as e:
1509-
raise ValueError(f"Release init failed: {e}") from e
1509+
raise ValueError(f"Release stage failed: {e}") from e
15101510

1511-
logger.info("'release-init' command executed.")
1511+
logger.info("'release-stage' command executed.")
15121512

15131513

15141514
if __name__ == "__main__": # pragma: NO COVER
@@ -1522,14 +1522,14 @@ def handle_release_init(
15221522
"configure": handle_configure,
15231523
"generate": handle_generate,
15241524
"build": handle_build,
1525-
"release-init": handle_release_init,
1525+
"release-stage": handle_release_stage,
15261526
}
15271527

15281528
for command_name, help_text in [
15291529
("configure", "Onboard a new library or an api path to Librarian workflow."),
15301530
("generate", "generate a python client for an API."),
15311531
("build", "Run unit tests via nox for the generated library."),
1532-
("release-init", "Prepare to release a given set of libraries"),
1532+
("release-stage", "Prepare to release a given set of libraries"),
15331533
]:
15341534
parser_cmd = subparsers.add_parser(command_name, help=help_text)
15351535
parser_cmd.set_defaults(func=handler_map[command_name])
@@ -1588,7 +1588,7 @@ def handle_release_init(
15881588
)
15891589
elif args.command == "build":
15901590
args.func(librarian=args.librarian, repo=args.repo)
1591-
elif args.command == "release-init":
1591+
elif args.command == "release-stage":
15921592
args.func(librarian=args.librarian, repo=args.repo, output=args.output)
15931593
else:
15941594
args.func()

.generator/test_cli.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
GENERATE_REQUEST_FILE,
3030
BUILD_REQUEST_FILE,
3131
CONFIGURE_REQUEST_FILE,
32-
RELEASE_INIT_REQUEST_FILE,
32+
RELEASE_STAGE_REQUEST_FILE,
3333
SOURCE_DIR,
3434
STATE_YAML_FILE,
3535
LIBRARIAN_DIR,
@@ -75,7 +75,7 @@
7575
handle_build,
7676
handle_configure,
7777
handle_generate,
78-
handle_release_init,
78+
handle_release_stage,
7979
)
8080

8181

@@ -235,10 +235,10 @@ def mock_generate_request_data_for_nox():
235235

236236

237237
@pytest.fixture
238-
def mock_release_init_request_file(tmp_path, monkeypatch):
238+
def mock_release_stage_request_file(tmp_path, monkeypatch):
239239
"""Creates the mock request file at the correct path inside a temp dir."""
240240
# Create the path as expected by the script: .librarian/release-request.json
241-
request_path = f"{LIBRARIAN_DIR}/{RELEASE_INIT_REQUEST_FILE}"
241+
request_path = f"{LIBRARIAN_DIR}/{RELEASE_STAGE_REQUEST_FILE}"
242242
request_dir = tmp_path / os.path.dirname(request_path)
243243
request_dir.mkdir()
244244
request_file = request_dir / os.path.basename(request_path)
@@ -876,34 +876,34 @@ def test_clean_up_files_after_post_processing_success(mocker, is_mono_repo):
876876
_clean_up_files_after_post_processing("output", "library_id", is_mono_repo)
877877

878878

879-
def test_get_libraries_to_prepare_for_release(mock_release_init_request_file):
879+
def test_get_libraries_to_prepare_for_release(mock_release_stage_request_file):
880880
"""
881881
Tests that only libraries with the `release_triggered` field set to `True` are
882882
returned.
883883
"""
884-
request_data = _read_json_file(f"{LIBRARIAN_DIR}/{RELEASE_INIT_REQUEST_FILE}")
884+
request_data = _read_json_file(f"{LIBRARIAN_DIR}/{RELEASE_STAGE_REQUEST_FILE}")
885885
libraries_to_prep_for_release = _get_libraries_to_prepare_for_release(request_data)
886886
assert len(libraries_to_prep_for_release) == 1
887887
assert "google-cloud-language" in libraries_to_prep_for_release[0]["id"]
888888
assert libraries_to_prep_for_release[0]["release_triggered"]
889889

890890

891-
def test_handle_release_init_success(mocker, mock_release_init_request_file):
891+
def test_handle_release_stage_success(mocker, mock_release_stage_request_file):
892892
"""
893-
Simply tests that `handle_release_init` runs without errors.
893+
Simply tests that `handle_release_stage` runs without errors.
894894
"""
895895
mocker.patch("cli._update_global_changelog", return_value=None)
896896
mocker.patch("cli._update_version_for_library", return_value=None)
897897
mocker.patch("cli._get_previous_version", return_value=None)
898898
mocker.patch("cli._update_changelog_for_library", return_value=None)
899-
handle_release_init()
899+
handle_release_stage()
900900

901901

902-
def test_handle_release_init_is_generated_success(
903-
mocker, mock_release_init_request_file
902+
def test_handle_release_stage_is_generated_success(
903+
mocker, mock_release_stage_request_file
904904
):
905905
"""
906-
Tests that `handle_release_init` calls `_update_global_changelog` when the
906+
Tests that `handle_release_stage` calls `_update_global_changelog` when the
907907
`packages` directory exists.
908908
"""
909909
mocker.patch("pathlib.Path.exists", return_value=True)
@@ -912,23 +912,23 @@ def test_handle_release_init_is_generated_success(
912912
mocker.patch("cli._get_previous_version", return_value="1.2.2")
913913
mocker.patch("cli._update_changelog_for_library")
914914

915-
handle_release_init()
915+
handle_release_stage()
916916

917917
mock_update_global_changelog.assert_called_once()
918918

919919

920-
def test_handle_release_init_fail_value_error_file():
920+
def test_handle_release_stage_fail_value_error_file():
921921
"""
922-
Tests that handle_release_init fails to read `librarian/release-init-request.json`.
922+
Tests that handle_release_stage fails to read `librarian/release-stage-request.json`.
923923
"""
924924
with pytest.raises(ValueError, match="No such file or directory"):
925-
handle_release_init()
925+
handle_release_stage()
926926

927927

928-
def test_handle_release_init_fail_value_error_version(mocker):
928+
def test_handle_release_stage_fail_value_error_version(mocker):
929929
m = mock_open()
930930

931-
mock_release_init_request_content = {
931+
mock_release_stage_request_content = {
932932
"libraries": [
933933
{
934934
"id": "google-cloud-language",
@@ -942,17 +942,17 @@ def test_handle_release_init_fail_value_error_version(mocker):
942942
with unittest.mock.patch("cli.open", m):
943943
mocker.patch(
944944
"cli._get_libraries_to_prepare_for_release",
945-
return_value=mock_release_init_request_content["libraries"],
945+
return_value=mock_release_stage_request_content["libraries"],
946946
)
947947
mocker.patch("cli._get_previous_version", return_value="1.2.2")
948948
mocker.patch("cli._process_changelog", return_value=None)
949949
mocker.patch(
950-
"cli._read_json_file", return_value=mock_release_init_request_content
950+
"cli._read_json_file", return_value=mock_release_stage_request_content
951951
)
952952
with pytest.raises(
953953
ValueError, match="is the same as the version in state.yaml"
954954
):
955-
handle_release_init()
955+
handle_release_stage()
956956

957957

958958
def test_read_valid_text_file(mocker):
@@ -1009,13 +1009,13 @@ def test_write_json_file():
10091009
assert written_content == expected_output
10101010

10111011

1012-
def test_update_global_changelog(mocker, mock_release_init_request_file):
1012+
def test_update_global_changelog(mocker, mock_release_stage_request_file):
10131013
"""Tests that the global changelog is updated
10141014
with the new version for a given library.
10151015
See https://docs.python.org/3/library/unittest.mock.html#mock-open
10161016
"""
10171017
m = mock_open()
1018-
request_data = _read_json_file(f"{LIBRARIAN_DIR}/{RELEASE_INIT_REQUEST_FILE}")
1018+
request_data = _read_json_file(f"{LIBRARIAN_DIR}/{RELEASE_STAGE_REQUEST_FILE}")
10191019
libraries = _get_libraries_to_prepare_for_release(request_data)
10201020

10211021
with unittest.mock.patch("cli.open", m):

0 commit comments

Comments
 (0)