diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml index 6c85f82..684eaf6 100644 --- a/.github/workflows/release-pr.yml +++ b/.github/workflows/release-pr.yml @@ -21,9 +21,7 @@ on: type: string permissions: - contents: write - pull-requests: write - id-token: write + contents: read concurrency: group: release-pr @@ -45,10 +43,6 @@ jobs: github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'chore(release): prepare') runs-on: ubuntu-latest - # Nothing in this job writes. The workflow-level block is what the job - # below needs; narrowing here keeps the read-only half read-only. - permissions: - contents: read outputs: release: ${{ steps.version.outputs.release }} tag: ${{ steps.version.outputs.tag }} @@ -200,7 +194,9 @@ jobs: echo "branch=release/$tag" } >>"$GITHUB_OUTPUT" - release-pr: + # Stamps, formats and tests under the read-only token, so git-cliff, pre-commit, + # prettier and the tests never run beside the write token `release-pr` needs. + prepare: needs: resolve if: needs.resolve.outputs.release == 'true' runs-on: ubuntu-latest @@ -208,6 +204,7 @@ jobs: - uses: actions/checkout@v7 with: fetch-depth: 0 + persist-credentials: false # Temporary; see the note in the step above and tracking issue #87. Pinned # only because 2.14.x drops commits that touch .git-blame-ignore-revs @@ -267,6 +264,26 @@ jobs: - name: Run tests run: make test + - uses: actions/upload-artifact@v7 + with: + name: release-files + path: | + CHANGELOG.md + README.md + if-no-files-found: error + + release-pr: + needs: [resolve, prepare] + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v7 + - uses: actions/download-artifact@v8 + with: + name: release-files + # The body is a Markdown file rather than an inline block, and the reason # is that the two rules were in direct conflict. Inline, yamllint's # 100-column limit forces every paragraph to be wrapped -- and GitHub diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 276e311..34f3436 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -16,21 +16,22 @@ on: type: string permissions: - contents: write - id-token: write + contents: read concurrency: group: release-publish cancel-in-progress: false +env: + DIST_DIR: dist + jobs: - release-publish: + # Builds under the read-only token. Only `sign` sees the release key, and only + # `release-publish` can write, running nothing but gh. + build: runs-on: ubuntu-latest - # Gated on the protected `release` environment: minting a signed tag - # and publishing artifacts both pause for maintainer approval. - environment: release - env: - DIST_DIR: dist + outputs: + tag: ${{ steps.release-tag.outputs.tag }} steps: # Checked out before the tag is parsed so that the shared, unit-tested # parser can be used. A tag push already lands on the tag; a manual @@ -39,6 +40,7 @@ jobs: - uses: actions/checkout@v7 with: fetch-depth: 0 + persist-credentials: false - name: Resolve release tag id: release-tag @@ -66,6 +68,38 @@ jobs: RELEASE_TAG: ${{ steps.release-tag.outputs.tag }} run: git checkout --detach "refs/tags/$RELEASE_TAG" + - name: Build release artifacts + env: + RELEASE_TAG: ${{ steps.release-tag.outputs.tag }} + run: scripts/release/build-artifacts.sh "$RELEASE_TAG" "$DIST_DIR" + + - uses: actions/upload-artifact@v7 + with: + name: dist + path: ${{ env.DIST_DIR }}/ + if-no-files-found: error + + sign: + needs: build + runs-on: ubuntu-latest + # Gated on the protected `release` environment, which holds the release key. + # Publishing waits on this approval too, since it needs the signed artifacts. + environment: release + permissions: + contents: read + id-token: write + steps: + # sign-artifacts.sh comes from the tag, like every file this run builds from. + - uses: actions/checkout@v7 + with: + ref: refs/tags/${{ needs.build.outputs.tag }} + persist-credentials: false + + - uses: actions/download-artifact@v8 + with: + name: dist + path: ${{ env.DIST_DIR }} + - name: Install cosign uses: sigstore/cosign-installer@v3 @@ -75,21 +109,34 @@ jobs: gpg_private_key: ${{ secrets.RELEASE_GPG_PRIVATE_KEY }} passphrase: ${{ secrets.RELEASE_GPG_PASSPHRASE }} - - name: Build release artifacts - env: - RELEASE_TAG: ${{ steps.release-tag.outputs.tag }} - run: scripts/release/build-artifacts.sh "$RELEASE_TAG" "$DIST_DIR" - - name: Sign artifacts env: - RELEASE_TAG: ${{ steps.release-tag.outputs.tag }} + RELEASE_TAG: ${{ needs.build.outputs.tag }} GPG_PASSPHRASE: ${{ secrets.RELEASE_GPG_PASSPHRASE }} run: scripts/release/sign-artifacts.sh "$DIST_DIR" "$RELEASE_TAG" + - uses: actions/upload-artifact@v7 + with: + name: signed + path: ${{ env.DIST_DIR }}/ + if-no-files-found: error + + release-publish: + needs: [build, sign] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@v8 + with: + name: signed + path: ${{ env.DIST_DIR }} + - name: Publish GitHub release assets env: GH_TOKEN: ${{ github.token }} - RELEASE_TAG: ${{ steps.release-tag.outputs.tag }} + GH_REPO: ${{ github.repository }} + RELEASE_TAG: ${{ needs.build.outputs.tag }} run: | set -euo pipefail if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then diff --git a/scripts/release/approve.sh b/scripts/release/approve.sh index 39d5634..530b3b9 100755 --- a/scripts/release/approve.sh +++ b/scripts/release/approve.sh @@ -26,12 +26,12 @@ # confirmation. That is the run left behind when the wait above timed out or # Release Tag was approved on GitHub, and the run a manual dispatch creates. # -# The publish job also holds the release key, and a run's name is set by the -# run's own workflow file, read from whichever ref the run started on. So a -# publish run is approved only when it started from a file already on main or -# in the tag: the dispatch on main that Release Tag makes or a maintainer -# repeats by hand, or a push of the tag itself. The run that follows a Release -# Tag approval must be that dispatch. +# Release Publish's signing job also holds the release key, and a run's name +# is set by the run's own workflow file, read from whichever ref the run +# started on. So a publish run is approved only when it started from a file +# already on main or in the tag: the dispatch on main that Release Tag makes +# or a maintainer repeats by hand, or a push of the tag itself. The run that +# follows a Release Tag approval must be that dispatch. # # The branch name is parsed through parse-version.sh for the same reason the # workflows do it: it decides what gets tagged, so a `case` glob that also