Skip to content

Commit 63a7e2c

Browse files
bdracoclaude
andauthored
ci(release): use release-bot GitHub App token for PSR (#228)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 45d3694 commit 63a7e2c

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ jobs:
130130
- commitlint
131131

132132
runs-on: ubuntu-latest
133-
environment: release
133+
# Only enter the protected 'release' environment when actually releasing
134+
# from main; PR dry-runs would otherwise be blocked by the env's
135+
# main-only branch policy.
136+
environment: ${{ github.ref_name == 'main' && 'release' || '' }}
134137
concurrency: release
135138
permissions:
136139
id-token: write
@@ -143,22 +146,36 @@ jobs:
143146
- uses: actions/checkout@v6
144147
with:
145148
fetch-depth: 0
146-
ref: ${{ github.head_ref || github.ref_name }}
149+
ref: ${{ github.ref }}
150+
151+
- name: Create local branch name
152+
run: git switch -C ${{ github.head_ref || github.ref_name }}
147153

148154
# Do a dry run of PSR
149155
- name: Test release
150156
uses: python-semantic-release/python-semantic-release@v10.5.3
151157
if: github.ref_name != 'main'
152158
with:
153-
root_options: --noop
159+
no_operation_mode: true
160+
161+
# Mint a short-lived installation token for the release-bot GitHub
162+
# App, which is in the main ruleset's bypass_actors list so PSR's
163+
# version-bump commit/tag push isn't blocked by required checks.
164+
- name: Generate release App token
165+
if: github.ref_name == 'main'
166+
id: app-token
167+
uses: actions/create-github-app-token@v2
168+
with:
169+
app-id: ${{ secrets.RELEASE_APP_ID }}
170+
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
154171

155172
# On main branch: actual PSR + upload to PyPI & GitHub
156173
- name: Release
157174
uses: python-semantic-release/python-semantic-release@v10.5.3
158175
id: release
159176
if: github.ref_name == 'main'
160177
with:
161-
github_token: ${{ secrets.GITHUB_TOKEN }}
178+
github_token: ${{ steps.app-token.outputs.token }}
162179

163180
- name: Publish package distributions to PyPI
164181
uses: pypa/gh-action-pypi-publish@release/v1
@@ -168,7 +185,7 @@ jobs:
168185
uses: python-semantic-release/upload-to-gh-release@main
169186
if: steps.release.outputs.released == 'true'
170187
with:
171-
github_token: ${{ secrets.GITHUB_TOKEN }}
188+
github_token: ${{ steps.app-token.outputs.token }}
172189

173190
build_wheels:
174191
needs: [release]

0 commit comments

Comments
 (0)