Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ on:
type: string

permissions:
contents: write
pull-requests: write
id-token: write
contents: read

concurrency:
group: release-pr
Expand All @@ -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 }}
Expand Down Expand Up @@ -200,14 +194,17 @@ 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
steps:
- 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
Expand Down Expand Up @@ -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
Expand Down
77 changes: 62 additions & 15 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,6 +40,7 @@ jobs:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false

- name: Resolve release tag
id: release-tag
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions scripts/release/approve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading