name: Publish to crates.io
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: read
jobs:
publish:
name: Test & publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo build
uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --features sqlx_postgres,sqlx_sqlite --no-fail-fast
- name: Verify tag matches Cargo.toml version
if: startsWith(github.ref, 'refs/tags/v')
run: |
CARGO_VERSION="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
TAG_VERSION="${GITHUB_REF_NAME#v}"
echo "Cargo.toml version: $CARGO_VERSION"
echo "Git tag version: $TAG_VERSION"
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "::error::Tag '$TAG_VERSION' does not match Cargo.toml version '$CARGO_VERSION'"
exit 1
fi
- name: Package (dry-run check)
run: cargo publish --dry-run
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.RUST_TOKEN }}
run: cargo publish