name: Build & test

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  CARGO_TERM_COLOR: always
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    strategy:
      matrix:
        rust:
          - stable
          # - beta
          - nightly
        features:
          - serde
          - base64
          - simd_backend
          - default
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
        exclude:
          - rust: stable
            features: simd_backend
          - rust: beta
            features: simd_backend
          - os: windows-latest
            features: simd_backend
    runs-on: ${{ matrix.os }}
    env:
      FEATURES: ${{ matrix.rust != 'nightly' && matrix.features || format('{0},nightly', matrix.features) }}
    steps:
      - uses: actions/checkout@v4
      - name: Setup ${{ matrix.rust }} Rust toolchain with caching
        uses: brndnmtthws/rust-action@v1
        with:
          toolchain: ${{ matrix.rust }}
          cargo-packages: |
            cargo-nextest
            cargo-tarpaulin
      - run: cargo build --features ${{ env.FEATURES }}
      - run: cargo nextest run --features ${{ env.FEATURES }}
        env:
          RUST_BACKTRACE: 1
      - run: cargo fmt --all -- --check
        if: ${{ matrix.rust == 'nightly' && matrix.os == 'ubuntu-latest' }}
      - run: cargo clippy --features ${{ env.FEATURES }} -- -D warnings
