Skip to content

Commit dcbdf1b

Browse files
authored
chore(release): make promote_rc workflow call publish_release workflow to finish publishing (#3900)
Why: The tagging done by promote_rc doesn't trigger the on-tag trigger of the publish workflow (due to GITHUB_TOKEN restriction). How: - Modified promote_rc.py to output the promoted version to GITHUB_OUTPUT. - Modified release_promote_rc.yaml to capture this version and chain the release_publish workflow. - Added unit tests for GITHUB_OUTPUT writing in promote_rc_test.py.
1 parent 5650cc8 commit dcbdf1b

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

.github/workflows/release_promote_rc.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ permissions:
2525
jobs:
2626
promote:
2727
runs-on: ubuntu-latest
28+
outputs:
29+
version: ${{ steps.promote.outputs.version }}
2830
steps:
2931
- name: Checkout repository
3032
uses: actions/checkout@v7
@@ -42,6 +44,7 @@ jobs:
4244
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
4345
4446
- name: Run Promote RC
47+
id: promote
4548
env:
4649
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4750
VERSION: ${{ inputs.version }}
@@ -58,3 +61,11 @@ jobs:
5861
ARGS+=("--no-dry-run")
5962
6063
bazel run //tools/private/release -- promote-rc "${ARGS[@]}"
64+
65+
publish:
66+
needs: promote
67+
uses: ./.github/workflows/release_publish.yaml
68+
with:
69+
tag_name: ${{ needs.promote.outputs.version }}
70+
publish_to_pypi: true
71+
secrets: inherit

tests/tools/private/release/promote_rc_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import argparse
2+
import os
3+
import tempfile
24
import unittest
5+
from pathlib import Path
36
from unittest.mock import call, patch
47

58
from tests.tools.private.release.release_test_helper import _mock_git_and_gh
@@ -10,6 +13,8 @@
1013
class CmdPromoteRcTest(unittest.TestCase):
1114
def setUp(self):
1215
_mock_git_and_gh(self)
16+
self.test_dir = tempfile.TemporaryDirectory()
17+
self.addCleanup(self.test_dir.cleanup)
1318

1419
def test_promote_rc_success(self):
1520
# Arrange
@@ -59,6 +64,28 @@ def test_promote_rc_success(self):
5964
)
6065
self.mock_gh.post_issue_comment.assert_called_once_with(123, expected_comment)
6166

67+
def test_promote_rc_writes_github_output(self):
68+
# Arrange
69+
github_output_path = os.path.join(self.test_dir.name, "github_output")
70+
args = argparse.Namespace(
71+
version="2.0.0", issue=123, dry_run=False, remote="my-remote"
72+
)
73+
self.mock_git.get_remote_tags.return_value = ["2.0.0-rc0", "2.0.0-rc1"]
74+
self.mock_git.get_commit_sha.return_value = "abcdef123456"
75+
self.mock_git.tag_exists.return_value = False
76+
initial_body = "- [ ] Tag Final"
77+
self.mock_gh.get_issue_body.return_value = initial_body
78+
79+
# Act
80+
with patch.dict("os.environ", {"GITHUB_OUTPUT": github_output_path}):
81+
result = PromoteRc(args, self.mock_git, self.mock_gh).run()
82+
83+
# Assert
84+
self.assertEqual(result, 0)
85+
self.assertTrue(os.path.exists(github_output_path))
86+
content = Path(github_output_path).read_text(encoding="utf-8")
87+
self.assertEqual(content, "version=2.0.0\n")
88+
6289
def test_promote_rc_resolve_issue_success(self):
6390
# Arrange
6491
args = argparse.Namespace(

tools/private/release/promote_rc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ def run(self) -> int:
157157
self.git.tag(version, commit_sha)
158158
self.git.push(args.remote, version)
159159

160+
if github_output := os.environ.get("GITHUB_OUTPUT"):
161+
with open(github_output, "a", encoding="utf-8") as f:
162+
f.write(f"version={version}\n")
163+
160164
print(f"Updating tracking issue #{issue_num} checklist...")
161165
self.gh.update_issue_body(issue_num, updated_body)
162166

0 commit comments

Comments
 (0)