name: Release
on:
push:
tags:
- "v*"
jobs:
publish-crate:
name: Publish (crates.io)
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Verify tag matches Cargo.toml version
working-directory: .
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME#v}"
VER=$(grep -m1 '^version' Cargo.toml | sed -E 's/^version\s*=\s*"([^"]+)".*/\1/')
if [ "$TAG" != "$VER" ]; then
echo "::error::Git tag v$TAG must match Cargo.toml version $VER"
exit 1
fi
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish --locked