name: CI
on: [push, pull_request]

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  rust:
    name: Test
    strategy:
      matrix:
        rust:
          - stable
          - '1.70'
        include:
          - rust: stable
            extra_components: rustfmt
    runs-on: ubuntu-20.04
    steps:
    - name: Checkout
      uses: actions/checkout@v4
    - name: Cache
      uses: actions/cache@v2
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.lock') }}
    - name: Install Rust
      uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        toolchain: ${{ matrix.rust }}
        components: ${{ matrix.extra_components }}
    - name: Test with all features
      run: cargo test --all-features --all-targets
    - name: Compile with no features
      run: cargo check --no-default-features
    - name: Check fuzz tests compile (but don't actually fuzz)
      run: cd fuzz && cargo check && cargo test
    - name: Check main crate formatting
      if: matrix.rust == 'stable'
      run: cargo fmt -- --check
    - name: Check fuzz crate formatting
      if: matrix.rust == 'stable'
      run: cd fuzz && cargo fmt -- --check
  license:
    name: Check copyright/license headers
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - run: find . -name target -prune -o -type f -print0 | xargs -0 .github/workflows/check-license.py
