Skip to content

Commit dbdeba6

Browse files
cloudwebrtcclaude
andcommitted
ci: least-privilege job permissions; close stale release PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b186e64 commit dbdeba6

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

‎.github/workflows/package-release.yml‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ on:
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.
2325
permissions:
24-
contents: write
25-
pull-requests: write
26-
id-token: write
26+
contents: read
2727

2828
jobs:
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
@@ -95,6 +98,20 @@ jobs:
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

Comments
 (0)