Skip to content

Commit 6e68d4f

Browse files
ci(release): gate release jobs to tag refs and isolate actions:write
Gate release.yaml build/publish/release jobs behind startsWith(github.ref, 'refs/tags/') so a workflow_dispatch from a branch cannot bypass the tag-only release flow. tagpr dispatches with --ref <tag>, so the intended path is unaffected. Move the release dispatch out of the tagpr job into a dependent dispatch-release job that alone holds actions: write, keeping tagpr on its documented least-privilege scopes (contents/pull-requests/issues). Co-authored-by: Codesmith <[email protected]>
1 parent 3c674d4 commit 6e68d4f

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎.github/workflows/release.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
jobs:
1212
build-native-packages:
1313
name: ${{ matrix.name }}
14+
# Only release from tag refs. The push trigger is tag-only, and tagpr.yaml
15+
# dispatches with --ref <tag>, so a manual branch dispatch must not publish.
16+
if: startsWith(github.ref, 'refs/tags/')
1417
runs-on: ${{ matrix.os }}
1518
timeout-minutes: 30
1619
strategy:
@@ -74,6 +77,7 @@ jobs:
7477
npm:
7578
needs:
7679
- build-native-packages
80+
if: startsWith(github.ref, 'refs/tags/')
7781
runs-on: ubuntu-24.04-arm
7882
timeout-minutes: 10
7983
permissions:
@@ -109,6 +113,7 @@ jobs:
109113
release:
110114
needs:
111115
- npm
116+
if: startsWith(github.ref, 'refs/tags/')
112117
runs-on: blacksmith-32vcpu-ubuntu-2404-arm
113118
permissions:
114119
contents: write

‎.github/workflows/tagpr.yaml‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ jobs:
1111
tagpr:
1212
runs-on: ubuntu-latest
1313
timeout-minutes: 15
14+
# tagpr's documented least-privilege scopes; the release dispatch that needs
15+
# `actions: write` is isolated in the dependent dispatch-release job below.
1416
permissions:
1517
contents: write
1618
pull-requests: write
1719
issues: read
18-
actions: write
20+
outputs:
21+
tag: ${{ steps.tagpr.outputs.tag }}
1922
steps:
2023
# persist-credentials stays on (default) so tagpr can push the release PR and tag
2124
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
@@ -27,11 +30,21 @@ jobs:
2730
uses: Songmu/tagpr@e84001bd5dac8defa0c75b3913937d284a3b3660 # v1.20.0
2831
env:
2932
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30-
# Tags pushed with GITHUB_TOKEN do not trigger `on: push: tags` workflows,
31-
# so dispatch release.yaml explicitly (workflow_dispatch is exempt from that rule)
33+
34+
# Tags pushed with GITHUB_TOKEN do not trigger `on: push: tags` workflows,
35+
# so dispatch release.yaml explicitly (workflow_dispatch is exempt from that rule).
36+
# Isolated in its own job so only it needs `actions: write`.
37+
dispatch-release:
38+
needs: tagpr
39+
if: needs.tagpr.outputs.tag != ''
40+
runs-on: ubuntu-latest
41+
timeout-minutes: 5
42+
permissions:
43+
actions: write
44+
steps:
3245
- name: Trigger release workflow
33-
if: steps.tagpr.outputs.tag != ''
34-
run: gh workflow run release.yaml --ref "$TAG"
46+
run: gh workflow run release.yaml --ref "$TAG" --repo "$REPO"
3547
env:
3648
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
TAG: ${{ steps.tagpr.outputs.tag }}
49+
TAG: ${{ needs.tagpr.outputs.tag }}
50+
REPO: ${{ github.repository }}

0 commit comments

Comments
 (0)