diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a24c445..acad56e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,8 +16,9 @@ on: push: branches: [main] -permissions: - contents: write +# Granted on the job below, not here: a workflow-level grant would also reach +# any job added later, and only the release job pushes. +permissions: {} concurrency: group: release @@ -28,6 +29,8 @@ jobs: # Belt and braces: never react to our own release commit. if: ${{ !startsWith(github.event.head_commit.message, 'chore(release):') }} runs-on: ubuntu-latest + permissions: + contents: write steps: # A token for the `scattercode-release` GitHub App, which is the only # actor allowed to bypass main's ruleset. GITHUB_TOKEN cannot be given @@ -45,6 +48,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 @@ -109,6 +116,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 @@ -169,6 +180,6 @@ jobs: # and no changelog commit, so re-running the job is a clean redo. # A retry would have to move an annotated tag, which is a worse # thing to get wrong than a re-run is to perform. - 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