name: CI

on:
  pull_request:
  push:
    branches:
      - master

env:
  RUSTFLAGS: "-Dwarnings"
  RUSTDOCFLAGS: "-Dwarnings"

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - 1.65.0 # MSRV
          - stable
        target:
          - thumbv7em-none-eabi
          - wasm32-unknown-unknown
    steps:
      - uses: actions/checkout@v4
      - uses: RustCrypto/actions/cargo-cache@master
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          targets: ${{ matrix.target }}
      - run: cargo build --no-default-features --target ${{ matrix.target }}

  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - 1.65.0 # MSRV
          - stable
    steps:
      - uses: actions/checkout@v4
      - uses: RustCrypto/actions/cargo-cache@master
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
      - uses: RustCrypto/actions/cargo-hack-install@master
      - run: cargo hack test --release --feature-powerset --exclude-features nightly,getrandom,serde
      - run: cargo test --release --features getrandom
      - run: cargo test --release --features serde

  doc:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: RustCrypto/actions/cargo-cache@master
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
      - run: cargo doc --all-features

  minimal-versions:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: RustCrypto/actions/cargo-cache@master
      - uses: dtolnay/rust-toolchain@nightly
      - run: cargo update -Z minimal-versions
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test --release --features getrandom,serde,pkcs5

  nightly:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: RustCrypto/actions/cargo-cache@master
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: nightly-2023-10-01
      - run: cargo test --release --features nightly
      - run: cargo build --benches
