simstring_rust 0.1.0

A native Rust implementation of the SimString algorithm
Documentation
name: Rust CI/CD

on:
  push:
    branches: ["main"]
    tags:
      - "v*"
  pull_request:
    branches: ["main"]

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  test:
    name: Test on ${{ matrix.os }} / ${{ matrix.rust }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        rust: [stable]
        include:
          - os: ubuntu-latest
            rust: stable
            target: x86_64-unknown-linux-gnu
          - os: ubuntu-latest
            rust: stable
            target: aarch64-unknown-linux-gnu
          - os: windows-latest
            rust: stable
            target: x86_64-pc-windows-msvc
          - os: macos-latest
            rust: stable
            target: x86_64-apple-darwin
          - os: macos-latest
            rust: stable
            target: aarch64-apple-darwin

    steps:
      - uses: actions/checkout@v3

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust }}
          target: ${{ matrix.target }}
          components: rustfmt, clippy

      - name: Install cross
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: cargo install cross

      - name: Set up cargo cache
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-${{ matrix.target }}-cargo-

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Run clippy
        if: matrix.target != 'aarch64-unknown-linux-gnu'
        run: cargo clippy --target ${{ matrix.target }} -- -D warnings

      - name: Run clippy (cross)
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: cross clippy --target ${{ matrix.target }} -- -D warnings

      - name: Run tests
        if: matrix.target != 'aarch64-unknown-linux-gnu'
        run: cargo test --target ${{ matrix.target }} --verbose

      - name: Run tests (cross)
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: cross test --target ${{ matrix.target }} --verbose

      - name: Build
        if: matrix.target != 'aarch64-unknown-linux-gnu'
        run: cargo build --target ${{ matrix.target }} --verbose

      - name: Build (cross)
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: cross build --target ${{ matrix.target }} --verbose

      # Documentation check
      - name: Check documentation
        run: cargo doc --no-deps --document-private-items

  # Publish to crates.io on new tags
  publish:
    name: Publish to crates.io
    needs: test
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Verify tag version matches Cargo.toml version
        run: |
          CARGO_VERSION=$(grep '^version =' Cargo.toml | cut -d '"' -f2)
          TAG_VERSION=${GITHUB_REF#refs/tags/v}
          echo "CARGO_VERSION: $CARGO_VERSION"
          echo "TAG_VERSION: $TAG_VERSION"
          if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
            echo "Error: Git tag $TAG_VERSION doesn't match Cargo.toml version $CARGO_VERSION"
            exit 1
          fi

      - name: Check package
        run: cargo package

      - name: Publish to crates.io
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}