Skip to content

Commit 0896b47

Browse files
authored
chore(release): fix promote_rc arguments and align comments (#3898)
chore(release): fix promote_rc arguments and align comments `promote_rc.py` was calling `Git.fetch` with `refspec` keyword argument which was not supported by `Git.fetch` signature, leading to fatal errors. The release promotion comment format was different from the release candidate creation comment format, leading to inconsistency. - Added `refspec` argument support to `Git.fetch` in `git.py`. - Added `sys.argv` printing at startup in `release.py` for debugging. - Updated `promote_rc.py` comment body to match `create_rc.py` style and added necessary helper variables. - Updated `git_test.py` to test `Git.fetch` with `refspec`. - Updated `promote_rc_test.py` to match the new comment format.
1 parent 5fe64d8 commit 0896b47

5 files changed

Lines changed: 84 additions & 15 deletions

File tree

tests/tools/private/release/git_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,43 @@ def test_checkout_track_remote_existing_branch(
4444
mock_reset_hard.assert_called_once_with("origin/my-branch")
4545

4646

47+
class GitFetchTest(unittest.TestCase):
48+
def setUp(self):
49+
self.git = Git(".")
50+
self.patcher = patch.object(self.git, "_run_git")
51+
self.mock_run_git = self.patcher.start()
52+
self.addCleanup(self.patcher.stop)
53+
54+
def test_fetch_default(self):
55+
self.git.fetch()
56+
self.mock_run_git.assert_called_once_with(
57+
"fetch", "origin", capture_output=False
58+
)
59+
60+
def test_fetch_custom_remote(self):
61+
self.git.fetch("upstream")
62+
self.mock_run_git.assert_called_once_with(
63+
"fetch", "upstream", capture_output=False
64+
)
65+
66+
def test_fetch_with_refspec(self):
67+
self.git.fetch("origin", refspec="my-branch")
68+
self.mock_run_git.assert_called_once_with(
69+
"fetch", "origin", "my-branch", capture_output=False
70+
)
71+
72+
def test_fetch_with_tags_and_force(self):
73+
self.git.fetch("origin", tags=True, force=True)
74+
self.mock_run_git.assert_called_once_with(
75+
"fetch", "origin", "--tags", "--force", capture_output=False
76+
)
77+
78+
def test_fetch_all_options(self):
79+
self.git.fetch("origin", refspec="my-branch", tags=True, force=True)
80+
self.mock_run_git.assert_called_once_with(
81+
"fetch", "origin", "my-branch", "--tags", "--force", capture_output=False
82+
)
83+
84+
4785
if __name__ == "__main__":
4886
unittest.main()

tests/tools/private/release/promote_rc_test.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ def test_promote_rc_success(self):
5050
123, expected_updated_body
5151
)
5252
expected_comment = (
53-
"Version 2.0.0 has been tagged.\n\n"
54-
"- **Release Page**: https://github.com/bazel-contrib/rules_python/releases/tag/2.0.0\n"
55-
'- **BCR PR Search**: [is:pr ("bazel-contrib/rules_python" in:title) ("@2.0.0" in:title)](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr%20%28%22bazel-contrib/rules_python%22%20in%3Atitle%29%20%28%22%402.0.0%22%20in%3Atitle%29)'
53+
"**New Release Tagged!** 🐍🌿\n\n"
54+
"Version **2.0.0** has been successfully generated and tagged on branch [`release/2.0`](https://github.com/bazel-contrib/rules_python/tree/release/2.0).\n\n"
55+
"- [Github Release 2.0.0](https://github.com/bazel-contrib/rules_python/releases/tag/2.0.0)\n"
56+
"- [BCR Entry 2.0.0](https://registry.bazel.build/modules/rules_python/2.0.0)\n"
57+
"- [BCR PRs](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr%20%28%22bazel-contrib/rules_python%22%20in%3Atitle%29%20%28%22%402.0.0%22%20in%3Atitle%29)\n"
58+
"- [Release workflow status](https://github.com/bazel-contrib/rules_python/actions/workflows/release_promote_rc.yaml)"
5659
)
5760
self.mock_gh.post_issue_comment.assert_called_once_with(123, expected_comment)
5861

@@ -95,9 +98,12 @@ def test_promote_rc_resolve_issue_success(self):
9598
123, expected_updated_body
9699
)
97100
expected_comment = (
98-
"Version 2.0.0 has been tagged.\n\n"
99-
"- **Release Page**: https://github.com/bazel-contrib/rules_python/releases/tag/2.0.0\n"
100-
'- **BCR PR Search**: [is:pr ("bazel-contrib/rules_python" in:title) ("@2.0.0" in:title)](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr%20%28%22bazel-contrib/rules_python%22%20in%3Atitle%29%20%28%22%402.0.0%22%20in%3Atitle%29)'
101+
"**New Release Tagged!** 🐍🌿\n\n"
102+
"Version **2.0.0** has been successfully generated and tagged on branch [`release/2.0`](https://github.com/bazel-contrib/rules_python/tree/release/2.0).\n\n"
103+
"- [Github Release 2.0.0](https://github.com/bazel-contrib/rules_python/releases/tag/2.0.0)\n"
104+
"- [BCR Entry 2.0.0](https://registry.bazel.build/modules/rules_python/2.0.0)\n"
105+
"- [BCR PRs](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr%20%28%22bazel-contrib/rules_python%22%20in%3Atitle%29%20%28%22%402.0.0%22%20in%3Atitle%29)\n"
106+
"- [Release workflow status](https://github.com/bazel-contrib/rules_python/actions/workflows/release_promote_rc.yaml)"
101107
)
102108
self.mock_gh.post_issue_comment.assert_called_once_with(123, expected_comment)
103109

@@ -142,9 +148,12 @@ def test_promote_rc_resolves_version_from_issue(self):
142148
123, expected_updated_body
143149
)
144150
expected_comment = (
145-
"Version 2.0.1 has been tagged.\n\n"
146-
"- **Release Page**: https://github.com/bazel-contrib/rules_python/releases/tag/2.0.1\n"
147-
'- **BCR PR Search**: [is:pr ("bazel-contrib/rules_python" in:title) ("@2.0.1" in:title)](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr%20%28%22bazel-contrib/rules_python%22%20in%3Atitle%29%20%28%22%402.0.1%22%20in%3Atitle%29)'
151+
"**New Release Tagged!** 🐍🌿\n\n"
152+
"Version **2.0.1** has been successfully generated and tagged on branch [`release/2.0`](https://github.com/bazel-contrib/rules_python/tree/release/2.0).\n\n"
153+
"- [Github Release 2.0.1](https://github.com/bazel-contrib/rules_python/releases/tag/2.0.1)\n"
154+
"- [BCR Entry 2.0.1](https://registry.bazel.build/modules/rules_python/2.0.1)\n"
155+
"- [BCR PRs](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr%20%28%22bazel-contrib/rules_python%22%20in%3Atitle%29%20%28%22%402.0.1%22%20in%3Atitle%29)\n"
156+
"- [Release workflow status](https://github.com/bazel-contrib/rules_python/actions/workflows/release_promote_rc.yaml)"
148157
)
149158
self.mock_gh.post_issue_comment.assert_called_once_with(123, expected_comment)
150159

tools/private/release/git.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,23 @@ def push(
135135
self._run_git(*cmd, capture_output=False)
136136

137137
def fetch(
138-
self, remote: str = "origin", tags: bool = False, force: bool = False
138+
self,
139+
remote: str = "origin",
140+
refspec: str | None = None,
141+
tags: bool = False,
142+
force: bool = False,
139143
) -> None:
140144
"""Fetches updates from a remote repository.
141145
142146
Args:
143147
remote: The remote repository name. Defaults to 'origin'.
148+
refspec: The refspec to fetch.
144149
tags: If True, fetches all tags.
145150
force: If True, force fetches updates.
146151
"""
147152
cmd = ["fetch", remote]
153+
if refspec:
154+
cmd.append(refspec)
148155
if tags:
149156
cmd.append("--tags")
150157
if force:

tools/private/release/promote_rc.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Subcommand to promote a release candidate to final release."""
22

33
import argparse
4+
import os
45
import urllib.parse
56

67
from tools.private.release.gh import GitHub
@@ -161,16 +162,29 @@ def run(self) -> int:
161162

162163
print(f"Posting comment to tracking issue #{issue_num}...")
163164

165+
branch_url = f"{REPO_URL}/tree/{branch_name}"
164166
release_url = f"{REPO_URL}/releases/tag/{version}"
167+
bcr_entry_url = f"https://registry.bazel.build/modules/rules_python/{version}"
165168
bcr_query = (
166169
f'is:pr ("bazel-contrib/rules_python" in:title) ("@{version}" in:title)'
167170
)
168171
bcr_search_url = f"https://github.com/bazelbuild/bazel-central-registry/pulls?q={urllib.parse.quote(bcr_query)}"
169-
comment_body = (
170-
f"Version {version} has been tagged.\n\n"
171-
f"- **Release Page**: {release_url}\n"
172-
f"- **BCR PR Search**: [{bcr_query}]({bcr_search_url})"
173-
)
172+
173+
if run_id := os.environ.get("GITHUB_RUN_ID"):
174+
release_workflow_url = f"{REPO_URL}/actions/runs/{run_id}"
175+
else:
176+
release_workflow_url = (
177+
f"{REPO_URL}/actions/workflows/release_promote_rc.yaml"
178+
)
179+
180+
comment_body = f"""**New Release Tagged!** 🐍🌿
181+
182+
Version **{version}** has been successfully generated and tagged on branch [`{branch_name}`]({branch_url}).
183+
184+
- [Github Release {version}]({release_url})
185+
- [BCR Entry {version}]({bcr_entry_url})
186+
- [BCR PRs]({bcr_search_url})
187+
- [Release workflow status]({release_workflow_url})"""
174188
self.gh.post_issue_comment(issue_num, comment_body)
175189

176190
return 0

tools/private/release/release.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def create_parser():
4646

4747

4848
def main():
49+
print(f"sys.argv: {sys.argv}")
4950
if "BUILD_WORKSPACE_DIRECTORY" in os.environ:
5051
os.chdir(os.environ["BUILD_WORKSPACE_DIRECTORY"])
5152

0 commit comments

Comments
 (0)