name: Release
on:
push:
tags: ['v*']
permissions:
contents: read
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
validate:
name: Validate protected release tag
runs-on: ubuntu-26.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
fetch-depth: 0
- run: rustup toolchain install stable --profile minimal
- name: Check tag matches Cargo version
shell: bash
run: |
set -euo pipefail
[[ "$GITHUB_REF" == refs/tags/v* ]] || { echo "Run releases on a version tag"; exit 1; }
git merge-base --is-ancestor HEAD origin/main || { echo "Release tag must point to a commit on main"; exit 1; }
version="$(cargo +stable metadata --locked --no-deps --format-version 1 | jq -er '.packages[] | select(.name == "aoc-toolkit") | .version')"
[[ "$GITHUB_REF_NAME" == "v$version" ]] || { echo "Tag does not match Cargo.toml version"; exit 1; }
ci:
needs: validate
uses: ./.github/workflows/ci.yml
permissions:
contents: read
build:
name: Build / ${{ matrix.target }}
needs: ci
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
- os: macos-15-intel
target: x86_64-apple-darwin
- os: macos-15
target: aarch64-apple-darwin
- os: windows-2025
target: x86_64-pc-windows-msvc
env:
TARGET: ${{ matrix.target }}
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- run: rustup toolchain install stable --profile minimal
- run: rustup target add --toolchain stable ${{ matrix.target }}
- run: cargo +stable build --locked --release --bin aoc --target ${{ matrix.target }}
- name: Smoke test and package
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$exe = if ($IsWindows) { 'aoc.exe' } else { 'aoc' }
$binary = Join-Path "target/$env:TARGET/release" $exe
& $binary --version
if ($LASTEXITCODE -ne 0) { throw 'Version smoke test failed' }
& $binary --help
if ($LASTEXITCODE -ne 0) { throw 'Help smoke test failed' }
New-Item -ItemType Directory -Force staging, dist | Out-Null
Copy-Item $binary, README.md, LICENSE -Destination staging
$name = "aoc-toolkit-$env:GITHUB_REF_NAME-$env:TARGET"
if ($IsWindows) {
$archive = "dist/$name.zip"
Compress-Archive -Path staging/* -DestinationPath $archive
} else {
$archive = "dist/$name.tar.gz"
tar -czf $archive -C staging .
if ($LASTEXITCODE -ne 0) { throw 'Archive creation failed' }
}
$hash = (Get-FileHash -Algorithm SHA256 $archive).Hash.ToLowerInvariant()
"$hash $(Split-Path -Leaf $archive)" | Set-Content -Encoding ascii "$archive.sha256"
- uses: actions/upload-artifact@v7
with:
name: ${{ matrix.target }}
path: dist/*
if-no-files-found: error
publish-release:
name: Publish to crates.io and GitHub
needs: build
runs-on: ubuntu-26.04
timeout-minutes: 30
environment: release
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- run: rustup toolchain install stable --profile minimal
- uses: actions/download-artifact@v8
with:
path: ${{ runner.temp }}/release-dist
merge-multiple: true
- name: Verify checksums
shell: bash
run: |
set -euo pipefail
cd "$RUNNER_TEMP/release-dist"
shopt -s nullglob
checksums=(*.sha256)
archives=(*.tar.gz *.zip)
[[ ${#checksums[@]} -eq 5 && ${#archives[@]} -eq 5 ]] || { echo 'Expected five archives and five checksums'; exit 1; }
for checksum in "${checksums[@]}"; do sha256sum --check "$checksum"; done
- name: Create draft and attach assets
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
shell: bash
run: |
set -euo pipefail
# Fail closed if a release already exists; never overwrite published assets.
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
echo "Release already exists; inspect it before retrying."
exit 1
fi
flags=()
if [[ "$GITHUB_REF_NAME" == *-* ]]; then flags+=(--prerelease); fi
gh release create "$GITHUB_REF_NAME" "$RUNNER_TEMP"/release-dist/* --verify-tag --draft --generate-notes --title "$GITHUB_REF_NAME" "${flags[@]}"
gh release view "$GITHUB_REF_NAME" --json isDraft,assets --jq 'if .isDraft and (.assets | length == 10) and all(.assets[]; .state == "uploaded") then true else false end' | grep -Fx true
- name: Authenticate to crates.io (Trusted Publishing)
id: crates-auth
uses: rust-lang/crates-io-auth-action@v1
- name: Publish crate
env:
CARGO_REGISTRY_TOKEN: ${{ steps.crates-auth.outputs.token }}
shell: bash
run: |
set -euo pipefail
[[ -n "$CARGO_REGISTRY_TOKEN" ]] || { echo "Missing crates.io authentication"; exit 1; }
cargo +stable publish --locked
- name: Publish verified GitHub release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
shell: bash
run: |
set -euo pipefail
gh release edit "$GITHUB_REF_NAME" --draft=false