name: Publish to crates.io
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Verify version matches tag
run: |
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
echo "Version verified: $CARGO_VERSION"
- name: Run tests
run: cargo test --all-features
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}