name: CI

on:
  push:
  pull_request:
  schedule: [cron: "40 1 * * *"]

env:
  RUSTFLAGS: -Dwarnings

jobs:
  test:
    name: Rust ${{matrix.rust}}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        rust: [nightly, beta, stable, 1.36.0]
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{matrix.rust}}
      - run: cargo build
      - run: cargo test
      - run: cargo test --release
      - run: cargo build --no-default-features
      - run: cargo test --tests --no-default-features
      - run: cargo test --tests --no-default-features --release
      - run: cargo bench --no-run
        if: matrix.rust == 'nightly'

  miri:
    name: Miri
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@miri
      - run: cargo miri test
        env:
          MIRIFLAGS: -Zmiri-strict-provenance

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    if: github.event_name != 'pull_request'
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@clippy
      - run: cargo clippy --tests --benches -- -Dclippy::all -Dclippy::pedantic

  fuzz:
    name: Fuzz
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@nightly
      - uses: dtolnay/install@cargo-fuzz
      - run: cargo fuzz build -O

  outdated:
    name: Outdated
    runs-on: ubuntu-latest
    if: github.event_name != 'pull_request'
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/install@cargo-outdated
      - run: cargo outdated --workspace --exit-code 1
      - run: cargo outdated --manifest-path fuzz/Cargo.toml --exit-code 1
