2020 pull_request :
2121 types : [closed]
2222
23+ # Read-only by default; jobs that write ask for it themselves, so build jobs
24+ # (which run third-party build code) never get a write or OIDC token.
2325permissions :
24- contents : write
25- pull-requests : write
26- id-token : write
26+ contents : read
2727
2828jobs :
2929 # ── Step 1: Create / update the release PR from changesets ────
3030 bump :
3131 name : Create release PR
3232 if : github.event_name == 'push' || github.event_name == 'workflow_dispatch'
3333 runs-on : ubuntu-latest
34+ permissions :
35+ contents : write
36+ pull-requests : write
3437 concurrency :
3538 group : package-release-${{ inputs.branch || github.ref_name }}
3639 cancel-in-progress : true
9598 --body-file "$RUNNER_TEMP/pr-body.md"
9699 fi
97100
101+ # Pending changesets can disappear after the release PR was opened (e.g.
102+ # reverted); merging that stale PR would still publish.
103+ - name : Close stale release PR
104+ if : steps.changesets.outputs.title == ''
105+ env :
106+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
107+ run : |
108+ branch="release/changesets-${BASE_BRANCH//\//-}"
109+ existing=$(gh pr list --state open --head "$branch" --base "$BASE_BRANCH" --json number --jq '.[0].number // empty')
110+ if [ -n "$existing" ]; then
111+ gh pr comment "$existing" --body "Closing: no pending changesets left to release."
112+ gh pr close "$existing" --delete-branch
113+ fi
114+
98115 # ── Step 2: Publish on merge ──────────────────────────────────
99116 detect :
100117 name : Detect packages
@@ -109,6 +126,9 @@ jobs:
109126 && github.event.pull_request.head.repo.full_name == github.repository
110127 && github.event.pull_request.user.login == 'github-actions[bot]'
111128 runs-on : ubuntu-latest
129+ permissions :
130+ contents : read
131+ pull-requests : read
112132 outputs :
113133 rtc : ${{ steps.detect.outputs.rtc }}
114134 api : ${{ steps.detect.outputs.api }}
@@ -159,6 +179,8 @@ jobs:
159179 needs : detect
160180 if : needs.detect.outputs.tags != ''
161181 runs-on : ubuntu-latest
182+ permissions :
183+ contents : write
162184 steps :
163185 - uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
164186 with :
0 commit comments