Repository navigation
ci(release): tag-driven release with attested binaries and crates.io trusted publishing (LAB-5117) #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ci(release): tag-driven release with attested binaries and crates.io trusted publishing (LAB-5117) #4
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1842318
ci(release): tag-driven release with attested binaries and crates.io …
27Bslash6 1d14ecc
ci(release): let a rerun reuse an existing release (LAB-5117)
27Bslash6 1de07cd
ci(release): describe what the main-ancestry check catches (LAB-5117)
27Bslash6 0372149
ci(release): publish a leftover draft release on rerun; note the crat…
27Bslash6 be67294
ci(release): name the hand-published bootstrap version (LAB-5117)
27Bslash6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| name: Release | ||
|
|
||
| # A version tag (v0.1.0, v0.2.0-rc.1) on a commit in main publishes that | ||
| # version: attested binaries on the GitHub Release, then the crate on | ||
| # crates.io. Users verify a binary against this file's path, so renaming it | ||
| # breaks the verify command in the README. | ||
|
|
||
| on: | ||
| push: | ||
| tags: ["v*"] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: release-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| check: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Tag matches the crate version | ||
| run: | | ||
| version=$(cargo metadata --locked --no-deps --format-version 1 | jq -r '.packages[0].version') | ||
| if [ "$GITHUB_REF_NAME" != "v$version" ]; then | ||
| echo "::error::tag $GITHUB_REF_NAME does not match the crate version $version" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Tagged commit is on main | ||
| # Catches a version tag pushed on the wrong commit by mistake. | ||
| run: | | ||
| git merge-base --is-ancestor "$GITHUB_SHA" origin/main \ | ||
| || { echo "::error::$GITHUB_SHA is not on main"; exit 1; } | ||
|
|
||
| - name: Package the crate | ||
| # Builds the packaged crate, so the publish job can skip that build. | ||
| run: cargo package --locked | ||
|
|
||
| build: | ||
| name: build (${{ matrix.target }}) | ||
| needs: check | ||
| runs-on: ${{ matrix.os }} | ||
| timeout-minutes: 30 | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| # musl builds are static, so they run on any Linux distribution. | ||
| - { os: ubuntu-latest, target: x86_64-unknown-linux-musl } | ||
| - { os: ubuntu-24.04-arm, target: aarch64-unknown-linux-musl } | ||
| - { os: macos-latest, target: aarch64-apple-darwin } | ||
| env: | ||
| TARGET: ${{ matrix.target }} | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Install the musl toolchain | ||
| if: runner.os == 'Linux' | ||
| # ring compiles C, which needs musl-gcc. | ||
| run: sudo apt-get update && sudo apt-get install -y --no-install-recommends musl-tools | ||
|
|
||
| - name: Add the target | ||
| run: rustup target add "$TARGET" | ||
|
|
||
| - name: Test the shipped target | ||
| run: cargo test --locked --release --target "$TARGET" | ||
|
|
||
| - name: Build | ||
| run: cargo build --locked --release --target "$TARGET" | ||
|
|
||
| - name: Archive | ||
| run: | | ||
| dir="ck-$GITHUB_REF_NAME-$TARGET" | ||
| mkdir "$dir" | ||
| cp "target/$TARGET/release/ck" LICENSE README.md "$dir/" | ||
| tar -czf "$dir.tar.gz" "$dir" | ||
|
|
||
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: ${{ matrix.target }} | ||
| path: ck-*.tar.gz | ||
| if-no-files-found: error | ||
|
|
||
| release: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| # Signing happens here rather than in the build jobs, so dependency build | ||
| # scripts never run with a token that can sign or publish. | ||
| permissions: | ||
| contents: write # create the release | ||
| id-token: write # sign the attestation | ||
| attestations: write # store the attestation | ||
| steps: | ||
| - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | ||
| with: | ||
| path: dist | ||
| merge-multiple: true | ||
|
|
||
| - name: Unpack the binaries | ||
| # Attesting the binary too lets a user verify ck after unpacking it. | ||
| run: for archive in dist/*.tar.gz; do tar -xzf "$archive" -C dist; done | ||
|
|
||
| - name: Attest the archives and the binaries in them | ||
| uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 | ||
| with: | ||
| subject-path: | | ||
| dist/*.tar.gz | ||
| dist/ck-*/ck | ||
|
|
||
| - name: Create the GitHub Release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| GH_REPO: ${{ github.repository }} | ||
| run: | | ||
| # A rerun, after a failed upload or publish, finds the release | ||
| # already there: replace its archives with this run's attested ones | ||
| # so the publish job still runs. gh creates a release with assets as | ||
| # a draft and publishes it after the uploads, so a run that died | ||
| # mid-upload can leave a draft behind; publish it here. | ||
| if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then | ||
| gh release upload "$GITHUB_REF_NAME" --clobber dist/*.tar.gz | ||
| gh release edit "$GITHUB_REF_NAME" --draft=false | ||
| exit | ||
| fi | ||
|
27Bslash6 marked this conversation as resolved.
|
||
| prerelease=() | ||
| case "$GITHUB_REF_NAME" in *-*) prerelease=(--prerelease) ;; esac | ||
| gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes "${prerelease[@]}" \ | ||
| dist/*.tar.gz | ||
|
|
||
| publish: | ||
| needs: release | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| # crates.io accepts a token minted here only from this workflow in this | ||
| # environment: trusted publishing, so the repo holds no registry secret. | ||
| environment: release | ||
| permissions: | ||
| contents: read | ||
| id-token: write # exchange for a crates.io token | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| # Needs the crate to exist on crates.io with this workflow and the | ||
| # `release` environment registered as its trusted publisher. crates.io | ||
| # attaches a publisher only to an existing crate, so 0.0.0 is published | ||
| # by hand with an API token first. Every tagged version comes after it, | ||
| # because this job cannot publish a version that already exists. | ||
| - uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5 | ||
| id: auth | ||
|
|
||
| - name: Publish to crates.io | ||
| # The check job already built the packaged crate. A version can never | ||
| # be republished, so this runs last, after the GitHub Release exists. | ||
| env: | ||
| CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} | ||
| run: cargo publish --locked --no-verify | ||
|
27Bslash6 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.