on: [push, pull_request]

name: Continuous integration

jobs:
  Nightly:
    name: Nightly - ASan + Bench + Docs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Crate
        uses: actions/checkout@v2
      - name: Install clang for ASan
        run: sudo apt-get install -y clang
      - name: Checkout Toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: nightly
          override: true
          components: rust-src
      - name: Check formatting
        env:
          DO_FMT: true
        run: ./contrib/test.sh
      - name: Running address sanitizer
        env:
          DO_ASAN: true
        run: ./contrib/test.sh
      - name: Running benchmarks
        env:
          DO_BENCH: true
        run: ./contrib/test.sh
      - name: Building docs
        env:
          DO_DOCS: true
        run: ./contrib/test.sh

  Tests:
    name: Tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust: [stable, beta, nightly, 1.41.1]
    steps:
      - name: Checkout Crate
        uses: actions/checkout@v2
      - name: Checkout Toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
      - name: Running cargo
        env:
          DO_FEATURE_MATRIX: true
        run: ./contrib/test.sh

  WASM:
    name: WASM
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust: [stable, beta, nightly] # wasm-pack doesn't support rust 1.41.1
    steps:
      - name: Checkout Crate
        uses: actions/checkout@v2
      - name: Install clang
        run: sudo apt-get install -y clang
      - name: Checkout Toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
          components: rust-src
      - name: Running WASM tests
        env:
          DO_WASM: true
        run: ./contrib/test.sh

  Clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - run: rustup component add clippy
      - uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: --features=rand-std,recovery,lowmemory,global-context --all-targets -- -D warnings
