regexsolver 1.0.0

High-performance Rust library for building, combining, and analyzing regular expressions and finite automata
Documentation
name: Publish to crates.io

on:
  push:
    tags:
      - "v*"

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always
  RUSTDOCFLAGS: -D warnings

jobs:
  publish:
    runs-on: ubuntu-latest
    # Gate publishing behind a protected GitHub environment so the crates.io
    # token is only exposed to reviewed, tag-triggered runs. Configure required
    # reviewers on this environment in the repository settings.
    environment: crates-io
    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
      - uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # master
        with:
          toolchain: stable
          components: rustfmt, clippy

      # Never publish a crate whose version disagrees with the pushed tag.
      - name: Verify tag matches Cargo.toml version
        run: |
          crate_version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
          tag_version="${GITHUB_REF_NAME#v}"
          if [ "$crate_version" != "$tag_version" ]; then
            echo "::error::Tag ${GITHUB_REF_NAME} (${tag_version}) does not match Cargo.toml version ${crate_version}"
            exit 1
          fi

      - name: Format
        run: cargo fmt --all -- --check
      - name: Lint
        run: |
          cargo clippy --locked --all-targets -- -D warnings
          cargo clippy --locked --no-default-features --all-targets -- -D warnings
      - name: Test
        run: |
          cargo test --locked
          cargo test --locked --no-default-features
      - name: Docs
        run: cargo doc --locked --no-deps

      # Also verify the declared MSRV before publishing, like CI does.
      - name: Read MSRV from Cargo.toml
        id: msrv
        run: echo "msrv=$(grep -m1 '^rust-version' Cargo.toml | cut -d'"' -f2)" >> "$GITHUB_OUTPUT"
      - uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # master
        with:
          toolchain: ${{ steps.msrv.outputs.msrv }}
      - name: Check on MSRV
        run: |
          cargo +${{ steps.msrv.outputs.msrv }} check --locked --all-features
          cargo +${{ steps.msrv.outputs.msrv }} check --locked --no-default-features

      - name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_API_TOKEN }}
        run: cargo +stable publish --locked