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-latest
steps:
- name: Checkout
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09
- name: Check tag against Cargo.toml version
run: |
tag="${GITHUB_REF_NAME#v}"
manifest="$(grep -m1 '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/')"
echo "tag version: $tag"
echo "manifest version: $manifest"
if [ "$tag" != "$manifest" ]; then
echo "::error::tag $tag does not match Cargo.toml version $manifest"
exit 1
fi
ci:
name: CI
needs: verify-version
uses: ./.github/workflows/ci.yml
secrets: inherit
publish:
name: Publish to crates.io
needs: ci
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 with:
toolchain: stable
- name: Authenticate to crates.io
id: auth
uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18
- name: Publish crate
run: cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
create-release:
name: Create the GitHub release
needs: ci
runs-on: ubuntu-latest
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-latest
- 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:
- name: Checkout
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Build the binary
run: cargo build --release --locked --bin cargo-dejadoc --target ${{ matrix.target }}
- name: Package and upload the binary
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
bin=cargo-dejadoc
[ "$RUNNER_OS" = "Windows" ] && bin=cargo-dejadoc.exe
asset="cargo-dejadoc-${{ matrix.target }}.tar.gz"
tar -czf "$asset" -C "target/${{ matrix.target }}/release" "$bin"
gh release upload "$GITHUB_REF_NAME" "$asset" --repo "$GITHUB_REPOSITORY" --clobber