on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

name: Continuous integration

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0

jobs:
  tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
          - rust: 1.64.0  # MSRV
          - rust: stable
            features: unstable quickcheck rayon
            test_all: --all
          - rust: beta
            test_all: --all
          - rust: nightly
            features: unstable quickcheck rayon
            test_all: --all
            bench: true

    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
      - name: Build
        run: |
          cargo build --verbose --no-default-features
          cargo build --verbose --features "${{ matrix.features }}"
      - name: Tests
        run: |
          cargo test --verbose --no-default-features
          cargo test ${{ matrix.test_all }} --verbose --features "${{ matrix.features }}"
      - name: Build benchmarks
        if: ${{ matrix.bench }}
        run: |
          cargo bench --verbose --no-run
          cargo bench --verbose --no-run --all-features

  rustfmt:
    runs-on: ubuntu-latest
    continue-on-error: true
    strategy:
      matrix:
        include:
          - rust: stable
            rustfmt: rustfmt

    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          components: ${{ matrix.rustfmt }}
          override: true
      - name: Rustfmt
        if: matrix.rustfmt
        run: cargo fmt -- --check

  miri:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@nightly
        with:
          components: miri
      - run: cargo miri test
