name: Release
on:
push:
tags: ["rs-v*"]
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Fmt
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all-targets -- -D warnings
- name: Test
run: cargo test
- name: Verify crate version matches tag
run: |
TAG="${GITHUB_REF_NAME#rs-v}"
CRATE=$(grep -m1 '^version' Cargo.toml | sed -E 's/version *= *"([^"]+)"/\1/')
if [ "$TAG" != "$CRATE" ]; then
echo "Tag $GITHUB_REF_NAME (→ $TAG) does not match Cargo.toml version $CRATE"
exit 1
fi
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
generate_release_notes: true
prerelease: ${{ contains(github.ref_name, '-alpha') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-rc') }}