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
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- "src/**"
- "xtask/**"
- ".github/workflows/codeql.yml"
push:
branches: [main]
Expand Down
110 changes: 81 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
name: release

on:
pull_request:
paths:
- ".github/workflows/release.yml"
- "Cargo.toml"
- "Cargo.lock"
- ".cargo/config.toml"
- "README.md"
- "CHANGELOG.md"
- "LICENSE-MIT"
- "migrations/**"
- "src/**"
- "xtask/**"
- "scripts/syft-release.yaml"
push:
tags:
- "v*"
Expand Down Expand Up @@ -28,25 +41,32 @@ defaults:

jobs:
validate-tag:
name: validate tag
name: validate release candidate
runs-on: ubuntu-24.04
timeout-minutes: 5
env:
TAG_REF: ${{ inputs.tag || github.ref_name }}
EVENT_NAME: ${{ github.event_name }}
CANDIDATE_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
outputs:
tag_ref: ${{ steps.validate.outputs.tag_ref }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Build exactly the tagged bytes: without ref, a manual dispatch
# would check out the default branch and label it as the tag.
# Tag dispatches use the tag; PR rehearsals use the immutable head, not its merge ref.
with:
ref: ${{ inputs.tag || github.ref_name }}
ref: ${{ github.event.pull_request.head.sha || inputs.tag || github.ref_name }}
- name: Tag matches Cargo.toml version and changelog section
id: validate
run: |
manifest_version="$(sed -n '/^\[package\]/,/^\[/{s/^version = "\(.*\)"/\1/p;}' Cargo.toml)"
ref="$TAG_REF"
if [ "$EVENT_NAME" = pull_request ]; then
ref="v$manifest_version"
fi
case "$ref" in
v*) tag="${ref#v}" ;;
*) echo "::error::tag must start with 'v' (got '$ref')"; exit 1 ;;
esac
manifest_version="$(sed -n '/^\[package\]/,/^\[/{s/^version = "\(.*\)"/\1/p;}' Cargo.toml)"
if [ "$tag" != "$manifest_version" ]; then
echo "::error::tag v$tag does not match Cargo.toml version $manifest_version"
exit 1
Expand All @@ -60,12 +80,19 @@ jobs:
fi
# Prove the checkout really is the tag before anything builds.
head="$(git rev-parse HEAD)"
tagged="$(git rev-parse "$ref^{commit}")"
if [ "$EVENT_NAME" = pull_request ]; then
tagged="$CANDIDATE_SHA"
else
tagged="$(git rev-parse "$ref^{commit}")"
fi
if [ "$head" != "$tagged" ]; then
echo "::error::HEAD $head is not the tagged commit $tagged"
exit 1
fi
printf 'tag_ref=%s\n' "$ref" >> "$GITHUB_OUTPUT"
- name: Extract release notes
env:
TAG_REF: ${{ steps.validate.outputs.tag_ref }}
run: |
ref="$TAG_REF"
version="${ref#v}"
Expand Down Expand Up @@ -116,11 +143,11 @@ jobs:
os: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
env:
TAG_REF: ${{ inputs.tag || github.ref_name }}
TAG_REF: ${{ needs.validate-tag.outputs.tag_ref }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.tag || github.ref_name }}
ref: ${{ github.event.pull_request.head.sha || inputs.tag || github.ref_name }}
- uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable branch
with:
toolchain: 1.97.0
Expand All @@ -137,7 +164,9 @@ jobs:
# packaging only and must not ship clap_mangen or the hidden __man
# command inside released binaries.
- name: Build release binary
run: cargo build --release --locked --target ${{ matrix.target }}
run: |
cargo install cargo-auditable --version 0.7.7 --locked
cargo auditable build --release --locked --target ${{ matrix.target }}
- name: Generate man pages for the archive
run: cargo run --quiet --locked --features man -- __man man-pages
- name: Smoke test binary
Expand Down Expand Up @@ -187,9 +216,14 @@ jobs:
uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
with:
format: cyclonedx-json
file: "dist/atx-${{ inputs.tag || github.ref_name }}-${{ matrix.target }}.tar.gz"
output-file: "dist/atx-${{ inputs.tag || github.ref_name }}-${{ matrix.target }}.cdx.json"
file: "dist/atx-${{ needs.validate-tag.outputs.tag_ref }}-${{ matrix.target }}.tar.gz"
output-file: "dist/atx-${{ needs.validate-tag.outputs.tag_ref }}-${{ matrix.target }}.cdx.json"
syft-version: v1.42.3
config: scripts/syft-release.yaml
upload-artifact: false
upload-release-assets: false
- name: Validate binary dependency inventory
run: cargo xtask check-sbom "dist/atx-${TAG_REF}-${{ matrix.target }}.cdx.json" "${{ matrix.target }}"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: archive-${{ matrix.target }}
Expand All @@ -199,23 +233,24 @@ jobs:
if-no-files-found: error

finalize:
name: checksums and attestation
needs: archives
name: validate release inventories and checksums
needs: [validate-tag, archives]
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
id-token: write
attestations: write
env:
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && 'true' || 'false' }}
TAG_REF: ${{ needs.validate-tag.outputs.tag_ref }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.head.sha || inputs.tag || github.ref_name }}
- uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c
with:
toolchain: 1.97.0
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: dist
merge-multiple: true
- name: Verify every expected archive and SBOM is present
env:
TAG_REF: ${{ inputs.tag || github.ref_name }}
run: |
ref="$TAG_REF"
for target in aarch64-apple-darwin x86_64-apple-darwin x86_64-unknown-linux-gnu x86_64-unknown-linux-musl aarch64-unknown-linux-gnu aarch64-unknown-linux-musl; do
Expand All @@ -225,6 +260,7 @@ jobs:
test -s "dist/atx-$ref-$target.cdx.json" || {
echo "::error::missing SBOM for $target"; exit 1;
}
cargo xtask check-sbom "dist/atx-$ref-$target.cdx.json" "$target"
done
test -s "dist/RELEASE_NOTES.md" || {
echo "::error::missing extracted release notes"; exit 1;
Expand All @@ -234,6 +270,29 @@ jobs:
run: |
sha256sum -- *.tar.gz *.cdx.json > SHA256SUMS
cat SHA256SUMS
- name: Upload checksum manifest
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: release-checksums
path: dist/SHA256SUMS
if-no-files-found: error

attest:
name: attest release artifacts
needs: finalize
if: github.event_name == 'push'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
id-token: write
attestations: write
env:
DRY_RUN: 'false'
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: dist
merge-multiple: true
- name: Attest archives and SBOMs
if: env.DRY_RUN == 'false'
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
Expand All @@ -251,19 +310,12 @@ jobs:
for f in dist/*.tar.gz dist/*.cdx.json dist/SHA256SUMS; do
gh attestation verify "$f" -R "$GITHUB_REPOSITORY"
done
- name: Upload checksum manifest
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: release-checksums
path: dist/SHA256SUMS
if-no-files-found: error

draft-release:
name: publish draft release
needs: finalize
# The only write-to-GitHub step runs in the protected environment, so
# dry-run dispatches (workflow_dispatch) never touch it at all.
if: github.event_name != 'workflow_dispatch'
needs: attest
# Only tag pushes can enter the protected publishing environment.
if: github.event_name == 'push'
environment: release
runs-on: ubuntu-24.04
timeout-minutes: 10
Expand Down
19 changes: 19 additions & 0 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ a reproducible `.tar.gz` with fixed timestamps and ownership. The workflow adds
a `SHA256SUMS` file and a CycloneDX SBOM for every archive, then creates a draft
GitHub release. Publishing the draft is a manual click.

Release builds use `cargo-auditable` 0.7.7 to embed the Rust dependency graph in
the stripped binary. The existing SBOM action uses pinned Syft 1.42.3 to scan
that archive. `cargo xtask check-sbom FILE TARGET` checks the root package,
locked crate versions, and exact default-feature direct runtime dependencies.
Empty inventories, missing crates, duplicate references, and broken edges fail
before upload and again before checksums are generated.

The inventory covers Rust crates recorded by the build, not bundled C source
or operating-system libraries. It is not a complete native-library inventory.
Scanner timestamps can vary; the checksum manifest covers the exact SBOM files
attached to that run. Temporary extraction-file records are omitted, while
crate locations and the archive hash remain in the document.

PRs that change release inputs run these same six native archive jobs against
the exact PR head. This rehearsal creates workflow artifacts and checksums,
not tags, attestations, releases, or registry uploads. Tag checks remain required
for actual tag builds and manual dispatches. Only a tag push can attest files
or enter the protected draft-release job.

The workflow also signs build attestations for each archive, SBOM, and the
checksum file, so anyone can check that a file came from this repository's
release workflow:
Expand Down
5 changes: 5 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ The required CI package job also tests the bin from a freshly extracted source
archive. Workspace tests alone cannot catch a missing packaged test fixture.
Use a fresh `CARGO_TARGET_DIR` for the extracted crate too. Reusing the workspace
target can run an older test binary even when the archive contains the new code.

`syft-release.yaml` configures the pinned release scanner. It omits temporary
extraction-file metadata, not the Rust dependency inventory, and disables
update checks. Release jobs scan the actual auditable archive and validate its
inventory with `cargo xtask check-sbom FILE TARGET` before upload and finalize.
8 changes: 7 additions & 1 deletion scripts/check-workflow-guards.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ require_literal .github/workflows/ci.yml ' COVERAGE_REGION_FLOOR: 85'

require_pattern .github/workflows/codeql.yml 'ubuntu-[0-9]'
require_pattern .github/workflows/codeql.yml 'macos-[0-9]'
require_literal .github/workflows/codeql.yml ' - "xtask/**"'

require_pattern .github/workflows/mutation.yml 'timeout-minutes:'
require_pattern .github/workflows/mutation.yml 'cargo mutants'
Expand All @@ -58,7 +59,12 @@ fi

require_pattern .github/workflows/release.yml 'DRY_RUN:'
require_pattern .github/workflows/release.yml "if: env\.DRY_RUN == 'false'"
require_pattern .github/workflows/release.yml "if: github\.event_name != 'workflow_dispatch'"
require_pattern .github/workflows/release.yml "if: github\.event_name == 'push'"
require_pattern .github/workflows/release.yml 'cargo install cargo-auditable --version 0\.7\.7 --locked'
require_pattern .github/workflows/release.yml 'cargo auditable build --release --locked --target'
require_pattern .github/workflows/release.yml 'syft-version: v1\.42\.3'
require_pattern .github/workflows/release.yml 'cargo xtask check-sbom'
require_pattern .github/workflows/release.yml 'upload-release-assets: false'
require_pattern .github/workflows/release.yml 'sha256sum .*\.tar\.gz .*\.cdx\.json .*SHA256SUMS'
require_pattern .github/workflows/release.yml 'dist/SHA256SUMS'
require_pattern .github/workflows/release.yml 'gh attestation verify'
Expand Down
5 changes: 5 additions & 0 deletions scripts/syft-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Keep scanner-generated extraction paths out of the released inventory.
check-for-app-update: false
file:
metadata:
selection: none
27 changes: 19 additions & 8 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
//! Repository maintenance tasks. Run with `cargo xtask <task>`.

mod sbom;

use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::ExitCode;

fn main() -> ExitCode {
if std::env::args().nth(1).as_deref() != Some("dist-man") {
eprintln!("usage: cargo xtask dist-man");
return ExitCode::from(2);
}
match dist_man() {
Ok(path) => {
println!("{}", path.display());
let args: Vec<_> = std::env::args_os().skip(1).collect();
let result = match args.as_slice() {
[task] if task == "dist-man" => dist_man().map(|path| path.display().to_string()),
[task, path, target] if task == "check-sbom" => match target.to_str() {
Some(target) => sbom::check(Path::new(path), target)
.map(|count| format!("SBOM: {count} locked runtime components verified")),
None => Err("release target must be UTF-8".into()),
},
_ => {
eprintln!("usage: cargo xtask dist-man | check-sbom FILE TARGET");
return ExitCode::from(2);
}
};
match result {
Ok(message) => {
println!("{message}");
ExitCode::SUCCESS
}
Err(error) => {
eprintln!("xtask dist-man: {error}");
eprintln!("xtask: {error}");
ExitCode::FAILURE
}
}
Expand Down
Loading
Loading