name: CI

on:
  pull_request:
  push:
    branches:
      - master

jobs:
  test:
    name: Test with Rust ${{ matrix.rust }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        rust: [1.41.1, stable, beta, nightly]
    steps:
      - uses: actions/checkout@v2
      - uses: hecrj/setup-rust-action@v1
        with:
          rust-version: ${{ matrix.rust }}
      - run: cargo test --verbose --all-features
      - run: cargo test --verbose --no-default-features --features alloc
      - run: cargo test --verbose --no-default-features

  clippy:
    name: Lint with Clippy
    runs-on: ubuntu-latest
    env:
      RUSTFLAGS: -Dwarnings
    steps:
      - uses: actions/checkout@v2
      - uses: hecrj/setup-rust-action@v1
        with:
          components: clippy
      - run: cargo clippy --all-targets --verbose --no-default-features
      - run: cargo clippy --all-targets --verbose --all-features

  test-minimal:
    name: Test minimal dependency version with Rust nightly
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: hecrj/setup-rust-action@v1
        with:
          rust-version: nightly
      - run: cargo test -Zminimal-versions --verbose --all-features

  miri:
    name: Run tests under `miri` to check for UB
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@nightly
        with:
          components: miri
      - run: cargo miri test --all-features
