name: Continuous integration

on:
  push:
    branches: [master]
  pull_request:

jobs:
  test:
    name: Tests
    runs-on: ubuntu-latest
    steps:
      - uses: styfle/cancel-workflow-action@0.10.0
        with:
          access_token: ${{ github.token }}
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - run: cargo test
      - run: cargo test --all-features

  fuzz-tests:
    name: Fuzz tests
    runs-on: ubuntu-latest
    steps:
      - uses: styfle/cancel-workflow-action@0.10.0
        with:
          access_token: ${{ github.token }}
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: nightly
          override: true
      - run: cargo install cargo-fuzz
      - run: for fuzz_test in `cargo fuzz list`; do cargo fuzz run $fuzz_test -- -max_total_time=60 -detect_leaks=0 -len_control=0 || exit 1; done

  lint:
    name: Rustfmt & Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: styfle/cancel-workflow-action@0.10.0
        with:
          access_token: ${{ github.token }}
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - run: rustup component add rustfmt
      - uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check
      - run: rustup component add clippy
      - uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: -- -D warnings
