name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
id-token: write
env:
CARGO_TERM_COLOR: always
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-action@stable
- name: Verify version matches tag
run: |
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
- name: Run tests
run: cargo test --verbose
- name: Authenticate with crates.io
uses: rust-lang/crates-io-auth-action@v1
- name: Publish to crates.io
run: cargo publish
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true