diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b8a4af8..28d6968 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,8 +35,9 @@ on: required: true type: string -permissions: - contents: write +# Granted per job below, not here: a workflow-level grant reaches every job, +# and only the release job pushes. +permissions: {} concurrency: group: release @@ -48,6 +49,8 @@ jobs: # names a tag that already exists, so there is nothing to compute. if: ${{ github.event_name == 'push' && !startsWith(github.event.head_commit.message, 'chore(release):') }} runs-on: ubuntu-latest + permissions: + contents: write outputs: released: ${{ steps.version.outputs.release }} version: ${{ steps.version.outputs.next }} @@ -63,6 +66,10 @@ jobs: with: app-id: ${{ secrets.RELEASE_CLIENT_ID }} private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + # Scoped to what the job uses, even though the installation grants + # no more: a token minted without this inherits whatever the App + # is later given. + permission-contents: write # The committer line needs the App's bot *user* id, which is not any of # the ids the token action returns -- `installation-id` is a different @@ -115,6 +122,10 @@ jobs: env: VERSION: ${{ steps.version.outputs.next }} GH_TOKEN: ${{ github.token }} + # Passed through the environment rather than expanded into the + # script: an expression inside `run:` is pasted into the shell + # before it runs, which is how workflow injection happens. + BRANCH: ${{ github.ref_name }} run: | set -euo pipefail @@ -146,7 +157,7 @@ jobs: # push is atomic and nothing after it has run, a lost race leaves no # tag, no release and no changelog commit, so re-running the job is # a clean redo. - git push --atomic origin "HEAD:${{ github.ref_name }}" "$VERSION" + git push --atomic origin "HEAD:${BRANCH}" "$VERSION" gh release create "$VERSION" --title "$VERSION" --notes-file RELEASE_NOTES.md @@ -191,6 +202,9 @@ jobs: needs: tag if: ${{ !cancelled() && needs.tag.outputs.released == 'true' }} runs-on: ubuntu-latest + # Reads the tag and nothing more. + permissions: + contents: read steps: - uses: actions/checkout@v7 with: