name: Publish to crates.io
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (do not actually publish)'
required: false
default: 'false'
type: boolean
permissions:
contents: write
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- name: Verify version matches tag
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
run: |
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) doesn't match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
echo "Version verified: $TAG_VERSION"
- name: Run tests
run: cargo test --all-features
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Check formatting
run: cargo fmt --all -- --check
- name: Dry run publish
if: inputs.dry_run == 'true'
run: cargo publish --dry-run
- name: Publish to crates.io
if: inputs.dry_run != 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
- name: Create GitHub Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && inputs.dry_run != 'true'
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: |
CHANGELOG.md
LICENSE-MIT
LICENSE-APACHE