chain-builder 2.1.2

A typed, dialect-aware SQL query builder for Rust (PostgreSQL/MySQL/SQLite).
Documentation
name: Publish to crates.io

# Publishes the crate to crates.io.
#
# Triggers:
#   - Pushing a version tag (e.g. `v1.0.2`) — the tag must match the version in
#     Cargo.toml, otherwise the job fails before publishing.
#   - Manually via the "Run workflow" button (workflow_dispatch).
#
# Auth: uses `RUST_TOKEN` (a crates.io API token) provided as an
# *Organization* secret. The organization secret must grant access to this
# repository (Org Settings → Secrets and variables → Actions → RUST_TOKEN →
# Repository access).

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