Skip to content

Commit a202a6c

Browse files
Refactor Github Action per b/485167538 (#829)
Co-authored-by: Ben Knutson <benknutson@google.com>
1 parent 671a8f2 commit a202a6c

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838

3939
- name: Configure git
4040
run: |
41-
git config user.name "${{ github.actor }}"
42-
git config user.email "${{ github.actor }}@users.noreply.github.com"
41+
git config user.name "${GITHUB_ACTOR}"
42+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
4343
4444
- name: Bump version
4545
id: bump
@@ -77,21 +77,22 @@ jobs:
7777
id: create_pr
7878
env:
7979
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
80+
STEPS_BUMP_OUTPUTS_NEW_VERSION: ${{ steps.bump.outputs.new_version }}
8081
run: |
81-
BRANCH="release/v${{ steps.bump.outputs.new_version }}"
82+
BRANCH="release/v${STEPS_BUMP_OUTPUTS_NEW_VERSION}"
8283
8384
# Delete existing branch if it exists
8485
git push origin --delete "$BRANCH" 2>/dev/null || true
8586
8687
git checkout -b "$BRANCH"
8788
git add pyproject.toml uv.lock
88-
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }}"
89+
git commit -m "chore: bump version to ${STEPS_BUMP_OUTPUTS_NEW_VERSION}"
8990
git push -u origin "$BRANCH"
9091
9192
# Create PR using PAT (author is the PAT owner, CLA will pass)
9293
PR_URL=$(gh pr create \
93-
--title "chore: release v${{ steps.bump.outputs.new_version }}" \
94-
--body "## Release v${{ steps.bump.outputs.new_version }}
94+
--title "chore: release v${STEPS_BUMP_OUTPUTS_NEW_VERSION}" \
95+
--body "## Release v${STEPS_BUMP_OUTPUTS_NEW_VERSION}
9596
9697
This PR was automatically created by the release workflow.
9798
@@ -108,24 +109,27 @@ jobs:
108109
- name: Approve PR
109110
env:
110111
GH_TOKEN: ${{ secrets.APPROVER_PAT }}
112+
STEPS_CREATE_PR_OUTPUTS_PR_URL: ${{ steps.create_pr.outputs.pr_url }}
111113
run: |
112114
# Approve with second account's PAT (different user than PR author)
113-
gh pr review "${{ steps.create_pr.outputs.pr_url }}" --approve
115+
gh pr review "${STEPS_CREATE_PR_OUTPUTS_PR_URL}" --approve
114116
115117
- name: Wait for all checks to pass
116118
env:
117119
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
120+
STEPS_CREATE_PR_OUTPUTS_PR_URL: ${{ steps.create_pr.outputs.pr_url }}
118121
run: |
119122
echo "Waiting for all status checks to complete..."
120123
sleep 10
121-
gh pr checks "${{ steps.create_pr.outputs.pr_url }}" --watch --fail-fast
124+
gh pr checks "${STEPS_CREATE_PR_OUTPUTS_PR_URL}" --watch --fail-fast
122125
123126
- name: Enable auto-merge
124127
env:
125128
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
129+
STEPS_CREATE_PR_OUTPUTS_PR_URL: ${{ steps.create_pr.outputs.pr_url }}
126130
run: |
127131
# Use PAT for auto-merge so the merge event triggers the publish workflow
128-
gh pr merge "${{ steps.create_pr.outputs.pr_url }}" --auto --squash
132+
gh pr merge "${STEPS_CREATE_PR_OUTPUTS_PR_URL}" --auto --squash
129133
130134
# Job 2: Publish release (triggered when release PR is merged)
131135
publish:
@@ -150,10 +154,12 @@ jobs:
150154
id: version
151155
run: |
152156
# Extract version from branch name (release/v1.2.3 -> 1.2.3)
153-
VERSION="${{ github.event.pull_request.head.ref }}"
157+
VERSION="${GITHUB_EVENT_PULL_REQUEST_HEAD_REF}"
154158
VERSION="${VERSION#release/v}"
155159
echo "version=$VERSION" >> $GITHUB_OUTPUT
156160
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
161+
env:
162+
GITHUB_EVENT_PULL_REQUEST_HEAD_REF: ${{ github.event.pull_request.head.ref }}
157163

158164
- name: Build package
159165
run: uv build
@@ -165,13 +171,15 @@ jobs:
165171

166172
- name: Configure git
167173
run: |
168-
git config user.name "${{ github.actor }}"
169-
git config user.email "${{ github.actor }}@users.noreply.github.com"
174+
git config user.name "${GITHUB_ACTOR}"
175+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
170176
171177
- name: Create and push tag
172178
run: |
173-
git tag ${{ steps.version.outputs.tag }}
174-
git push origin ${{ steps.version.outputs.tag }}
179+
git tag ${STEPS_VERSION_OUTPUTS_TAG}
180+
git push origin ${STEPS_VERSION_OUTPUTS_TAG}
181+
env:
182+
STEPS_VERSION_OUTPUTS_TAG: ${{ steps.version.outputs.tag }}
175183

176184
- name: Create GitHub Release
177185
uses: softprops/action-gh-release@v2

0 commit comments

Comments
 (0)