name: Release
on:
push:
tags:
- "v*.*"
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
verify-version:
name: Verify tag matches version
runs-on: ubuntu-26.04
outputs:
crate-release: ${{ steps.check.outputs.crate-release }}
steps:
- uses: actions/checkout@v4
- name: Check tag against Cargo.toml version
id: check
run: |
tag="${GITHUB_REF_NAME#v}"
manifest="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "refquiem") | .version')"
echo "tag version: $tag"
echo "manifest version: $manifest"
if [ "$tag" = "$manifest" ]; then
echo "crate-release=true" >> "$GITHUB_OUTPUT"
elif [ "${tag%%.*}" != "${manifest%%.*}" ]; then
echo "tag $tag is not a crate release tag for version $manifest, skipping" >> "$GITHUB_STEP_SUMMARY"
echo "crate-release=false" >> "$GITHUB_OUTPUT"
else
echo "::error::tag $tag does not match Cargo.toml version $manifest"
exit 1
fi
ci:
name: CI
needs: verify-version
if: needs.verify-version.outputs.crate-release == 'true'
uses: ./.github/workflows/ci.yml
secrets: inherit
publish:
name: Publish to crates.io
needs: ci
runs-on: ubuntu-26.04
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Check whether the version is published
id: published
run: |
version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "refquiem") | .version')"
if curl -sf https://index.crates.io/re/fq/refquiem | jq -e --arg v "$version" 'select(.vers == $v)' > /dev/null; then
echo "refquiem $version is already on crates.io" >> "$GITHUB_STEP_SUMMARY"
echo "skip=true" >> "$GITHUB_OUTPUT"
fi
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec if: steps.published.outputs.skip != 'true'
- name: Authenticate to crates.io
id: auth
if: steps.published.outputs.skip != 'true'
uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 - name: Publish the crate
if: steps.published.outputs.skip != 'true'
run: cargo publish --locked -p refquiem
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
create-release:
name: Create the GitHub release
needs: ci
runs-on: ubuntu-26.04
permissions:
contents: write
steps:
- name: Create or reuse the release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \
--verify-tag --generate-notes --title "$GITHUB_REF_NAME" \
|| gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null
binaries:
name: Build ${{ matrix.target }}
needs: create-release
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-26.04
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec with:
targets: ${{ matrix.target }}
- name: Build the binary
run: cargo build --release --locked --bin cargo-refquiem --target ${{ matrix.target }}
- name: Package and upload the binary
shell: bash
env:
GH_TOKEN: ${{ github.token }}
TARGET: ${{ matrix.target }}
run: |
set -euo pipefail
bin=cargo-refquiem
[ "$RUNNER_OS" = Windows ] && bin=cargo-refquiem.exe
asset="cargo-refquiem-$TARGET.tar.gz"
tar -czf "$asset" -C "target/$TARGET/release" "$bin"
gh release upload "$GITHUB_REF_NAME" "$asset" --repo "$GITHUB_REPOSITORY" --clobber