Skip to content

Commit 710d9de

Browse files
Jacksunweicopybara-github
authored andcommitted
chore(release): Update release process to allow tag to use accurate commit sha in the branch
* use last-release-sha to locate the previous release commit in main for CHANGELOG generating. * release tag can now use the commit sha in release branch Co-authored-by: Wei Sun (Jack) <weisun@google.com> PiperOrigin-RevId: 871909085
1 parent 33f7d11 commit 710d9de

File tree

6 files changed

+50
-18
lines changed

6 files changed

+50
-18
lines changed

.github/release-please-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3+
"last-release-sha": "9f7d5b3f1476234e552b783415527cc4bac55b39",
34
"packages": {
45
".": {
56
"release-type": "python",

.github/workflows/release-cherry-pick.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Cherry-picks a commit from main to the release/candidate branch.
2-
# Use this to include bug fixes in an in-progress release.
1+
# Step 3 (optional): Cherry-picks a commit from main to the release/candidate branch.
2+
# Use between step 1 and step 4 to include bug fixes in an in-progress release.
33
name: "Release: Cherry-pick"
44

55
on:
@@ -42,5 +42,5 @@ jobs:
4242
env:
4343
GH_TOKEN: ${{ github.token }}
4444
run: |
45-
gh workflow run release-please.yml --repo ${{ github.repository }}
45+
gh workflow run release-please.yml --repo ${{ github.repository }} --ref release/candidate
4646
echo "Triggered Release Please workflow"

.github/workflows/release-cut.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Starts the release process by creating a release/candidate branch.
2-
# Triggers release-please to generate a changelog PR.
1+
# Step 1: Starts the release process by creating a release/candidate branch.
2+
# Generates a changelog PR for review (step 2).
33
name: "Release: Cut"
44

55
on:
@@ -42,5 +42,5 @@ jobs:
4242
env:
4343
GH_TOKEN: ${{ github.token }}
4444
run: |
45-
gh workflow run release-please.yml --repo ${{ github.repository }}
45+
gh workflow run release-please.yml --repo ${{ github.repository }} --ref release/candidate
4646
echo "Triggered Release Please workflow"

.github/workflows/release-finalize.yml

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Triggers when release-please PR is merged to release/candidate.
2-
# Creates the final release/v{version} branch and deletes the candidate branch.
1+
# Step 4: Triggers when the changelog PR is merged to release/candidate.
2+
# Records last-release-sha and renames release/candidate to release/v{version}.
33
name: "Release: Finalize"
44

55
on:
@@ -33,6 +33,8 @@ jobs:
3333
if: steps.check.outputs.is_release_pr == 'true'
3434
with:
3535
ref: release/candidate
36+
token: ${{ secrets.RELEASE_PAT }}
37+
fetch-depth: 0
3638

3739
- name: Extract version from manifest
3840
if: steps.check.outputs.is_release_pr == 'true'
@@ -42,18 +44,33 @@ jobs:
4244
echo "version=$VERSION" >> $GITHUB_OUTPUT
4345
echo "Extracted version: $VERSION"
4446
45-
- name: Create release branch
47+
- name: Configure git identity from RELEASE_PAT
48+
if: steps.check.outputs.is_release_pr == 'true'
49+
env:
50+
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
51+
run: |
52+
USER_JSON=$(gh api user)
53+
git config user.name "$(echo "$USER_JSON" | jq -r '.login')"
54+
git config user.email "$(echo "$USER_JSON" | jq -r '.id')+$(echo "$USER_JSON" | jq -r '.login')@users.noreply.github.com"
55+
56+
- name: Record last-release-sha for release-please
4657
if: steps.check.outputs.is_release_pr == 'true'
4758
run: |
48-
git checkout -b "release/v${{ steps.version.outputs.version }}"
49-
git push origin "release/v${{ steps.version.outputs.version }}"
50-
echo "Created branch: release/v${{ steps.version.outputs.version }}"
59+
git fetch origin main
60+
CUT_SHA=$(git merge-base origin/main HEAD)
61+
echo "Release was cut from main at: $CUT_SHA"
62+
jq --arg sha "$CUT_SHA" '. + {"last-release-sha": $sha}' \
63+
.github/release-please-config.json > tmp.json && mv tmp.json .github/release-please-config.json
64+
git add .github/release-please-config.json
65+
git commit -m "chore: update last-release-sha for next release"
66+
git push origin release/candidate
5167
52-
- name: Delete release/candidate branch
68+
- name: Rename release/candidate to release/v{version}
5369
if: steps.check.outputs.is_release_pr == 'true'
5470
run: |
55-
git push origin --delete release/candidate
56-
echo "Deleted branch: release/candidate"
71+
VERSION="v${{ steps.version.outputs.version }}"
72+
git push origin "release/candidate:refs/heads/release/$VERSION" ":release/candidate"
73+
echo "Renamed release/candidate to release/$VERSION"
5774
5875
- name: Update PR label to tagged
5976
if: steps.check.outputs.is_release_pr == 'true'

.github/workflows/release-please.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Runs release-please to create/update a PR with version bump and changelog.
2-
# Triggered by pushes to release/candidate or manually.
2+
# Triggered automatically by step 1 (cut) or step 3 (cherry-pick).
33
name: "Release: Please"
44

55
on:
@@ -18,11 +18,25 @@ jobs:
1818
if: "!startsWith(github.event.head_commit.message, 'chore(release')"
1919
runs-on: ubuntu-latest
2020
steps:
21+
- name: Check if release/candidate still exists
22+
id: check
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
run: |
26+
if gh api repos/${{ github.repository }}/branches/release/candidate --silent 2>/dev/null; then
27+
echo "exists=true" >> $GITHUB_OUTPUT
28+
else
29+
echo "release/candidate branch no longer exists, skipping"
30+
echo "exists=false" >> $GITHUB_OUTPUT
31+
fi
32+
2133
- uses: actions/checkout@v4
34+
if: steps.check.outputs.exists == 'true'
2235
with:
2336
ref: release/candidate
2437

2538
- uses: googleapis/release-please-action@v4
39+
if: steps.check.outputs.exists == 'true'
2640
with:
2741
token: ${{ secrets.RELEASE_PAT }}
2842
config-file: .github/release-please-config.json

.github/workflows/release-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Builds and publishes the package to PyPI from a release branch.
2-
# Creates a merge-back PR to sync release changes to main.
1+
# Step 6: Builds and publishes the package to PyPI from a release/v{version} branch.
2+
# Creates a merge-back PR (step 7) to sync release changes to main.
33
name: "Release: Publish to PyPi"
44

55
on:

0 commit comments

Comments
 (0)