Skip to content

Commit 8396c28

Browse files
authored
Fix release tool links and improve workflow robustness (bazel-contrib#3888)
Fixes release tool bugs and improves workflow robustness. - Fix BCR entry link in create-rc to use RC version instead of final version. - Format BCR entry link as 'BCR Entry <version>'. - Fix release workflow status link to use release_create_rc.yaml. - Use GITHUB_RUN_ID to link directly to the workflow run if available. - Link the branch name in the create-rc comment. - Add a always-running job to release_create_release_branch.yaml to suppress 'no jobs ran' errors. - Remove obsolete rocket assertions in create_rc tests.
1 parent 7968ac9 commit 8396c28

3 files changed

Lines changed: 64 additions & 13 deletions

File tree

.github/workflows/release_create_release_branch.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ jobs:
3535
create-release-branch --issue ${{ github.event.issue.number }} --remote origin
3636
env:
3737
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
39+
# A no-op job that always runs to prevent "no jobs ran" failures
40+
# when the main job is skipped.
41+
suppress-no-jobs-ran-error:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Echo Success
45+
run: echo "Success"
46+

tests/tools/private/release/create_rc_test.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,56 @@ def test_create_rc_success_first_rc(self):
5656
"**New Release Candidate Tagged!** 🐍🌿",
5757
comment_call_args[1],
5858
)
59+
self.assertIn(
60+
"tagged on branch [`release/2.0`](https://github.com/bazel-contrib/rules_python/tree/release/2.0)",
61+
comment_call_args[1],
62+
)
5963
self.assertIn(
6064
"- [Github Release 2.0.0-rc0](https://github.com/bazel-contrib/rules_python/releases/tag/2.0.0-rc0)",
6165
comment_call_args[1],
6266
)
6367
self.assertIn(
64-
"- BCR Entry: [rules_python@2.0.0](https://registry.bazel.build/modules/rules_python/2.0.0)",
68+
"- [BCR Entry 2.0.0-rc0](https://registry.bazel.build/modules/rules_python/2.0.0-rc0)",
6569
comment_call_args[1],
6670
)
6771
self.assertIn(
68-
"- [BCR PRs](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr+rules_python+2.0.0)",
72+
"- [BCR PRs](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr+rules_python+2.0.0-rc0)",
6973
comment_call_args[1],
7074
)
7175
self.assertIn(
72-
"- [Release workflow status](https://github.com/bazel-contrib/rules_python/actions/workflows/release_publish.yaml)",
76+
"- [Release workflow status](https://github.com/bazel-contrib/rules_python/actions/workflows/release_create_rc.yaml)",
77+
comment_call_args[1],
78+
)
79+
80+
def test_create_rc_success_with_run_id(self):
81+
# Arrange
82+
args = MagicMock(issue=123, remote="my-remote")
83+
self.mock_gh.get_issue_title.return_value = "Release 2.0.0"
84+
self.mock_gh.get_issue_body.return_value = """
85+
## Checklist
86+
- [x] Prepare Release | status=done pr=#122 commit=abcdef12
87+
- [x] Create Release branch | status=done branch=release/2.0 commit=abcdef12
88+
- [ ] Tag RC0 | status=pending
89+
"""
90+
self.mock_git.get_remote_tags.return_value = []
91+
self.mock_git.get_commit_sha.return_value = "1234567890"
92+
93+
# Act
94+
with patch.dict(os.environ, {"GITHUB_RUN_ID": "987654321"}):
95+
result = CreateRc(args, self.mock_git, self.mock_gh).run()
96+
97+
# Assert
98+
self.assertEqual(result, 0)
99+
self.mock_gh.post_issue_comment.assert_called_once()
100+
comment_call_args = self.mock_gh.post_issue_comment.call_args[0]
101+
self.assertIn(
102+
"- [Release workflow status](https://github.com/bazel-contrib/rules_python/actions/runs/987654321)",
103+
comment_call_args[1],
104+
)
105+
self.assertIn(
106+
"tagged on branch [`release/2.0`](https://github.com/bazel-contrib/rules_python/tree/release/2.0)",
73107
comment_call_args[1],
74108
)
75-
self.assertNotIn("🚀", comment_call_args[1])
76109

77110
def test_create_rc_success_next_rc(self):
78111
# Arrange
@@ -113,23 +146,26 @@ def test_create_rc_success_next_rc(self):
113146
"**New Release Candidate Tagged!** 🐍🌿",
114147
comment_call_args[1],
115148
)
149+
self.assertIn(
150+
"tagged on branch [`release/2.0`](https://github.com/bazel-contrib/rules_python/tree/release/2.0)",
151+
comment_call_args[1],
152+
)
116153
self.assertIn(
117154
"- [Github Release 2.0.0-rc1](https://github.com/bazel-contrib/rules_python/releases/tag/2.0.0-rc1)",
118155
comment_call_args[1],
119156
)
120157
self.assertIn(
121-
"- BCR Entry: [rules_python@2.0.0](https://registry.bazel.build/modules/rules_python/2.0.0)",
158+
"- [BCR Entry 2.0.0-rc1](https://registry.bazel.build/modules/rules_python/2.0.0-rc1)",
122159
comment_call_args[1],
123160
)
124161
self.assertIn(
125-
"- [BCR PRs](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr+rules_python+2.0.0)",
162+
"- [BCR PRs](https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr+rules_python+2.0.0-rc1)",
126163
comment_call_args[1],
127164
)
128165
self.assertIn(
129-
"- [Release workflow status](https://github.com/bazel-contrib/rules_python/actions/workflows/release_publish.yaml)",
166+
"- [Release workflow status](https://github.com/bazel-contrib/rules_python/actions/workflows/release_create_rc.yaml)",
130167
comment_call_args[1],
131168
)
132-
self.assertNotIn("🚀", comment_call_args[1])
133169

134170
def test_create_rc_gating_on_backports(self):
135171
# Arrange

tools/private/release/create_rc.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,21 @@ def run(self) -> int:
114114
self.gh.update_issue_body(args.issue, updated_body)
115115

116116
tag_url = f"{REPO_URL}/releases/tag/{next_rc}"
117-
bcr_entry_url = f"https://registry.bazel.build/modules/rules_python/{version}"
118-
bcr_search_url = f"https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr+rules_python+{version}"
119-
release_workflow_url = f"{REPO_URL}/actions/workflows/release_publish.yaml"
117+
bcr_entry_url = f"https://registry.bazel.build/modules/rules_python/{next_rc}"
118+
bcr_search_url = f"https://github.com/bazelbuild/bazel-central-registry/pulls?q=is%3Apr+rules_python+{next_rc}"
119+
if run_id := os.environ.get("GITHUB_RUN_ID"):
120+
release_workflow_url = f"{REPO_URL}/actions/runs/{run_id}"
121+
else:
122+
release_workflow_url = (
123+
f"{REPO_URL}/actions/workflows/release_create_rc.yaml"
124+
)
125+
branch_url = f"{REPO_URL}/tree/{branch_name}"
120126
comment_body = f"""**New Release Candidate Tagged!** 🐍🌿
121127
122-
Release Candidate **{next_rc}** has been successfully generated and tagged on branch `{branch_name}`.
128+
Release Candidate **{next_rc}** has been successfully generated and tagged on branch [`{branch_name}`]({branch_url}).
123129
124130
- [Github Release {next_rc}]({tag_url})
125-
- BCR Entry: [rules_python@{version}]({bcr_entry_url})
131+
- [BCR Entry {next_rc}]({bcr_entry_url})
126132
- [BCR PRs]({bcr_search_url})
127133
- [Release workflow status]({release_workflow_url})"""
128134
self.gh.post_issue_comment(args.issue, comment_body)

0 commit comments

Comments
 (0)