on: [push, pull_request]

name: Continuous integration

jobs:
  ci:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - stable
          - beta
          - nightly
          - 1.45.0  # MSRV

    steps:
      - run: sudo apt-get update
      - run: sudo apt install -y valgrind

      - uses: actions/checkout@v2

      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true

      - run: cargo bench

      - if: ${{ matrix.rust == 'nightly' }}
        working-directory: ./macro
        run: cargo bench

  lint:
    strategy:
      matrix:
        rust:
          - stable
          - nightly

    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
          components: rustfmt, clippy

      - run: cargo fmt --all -- --check
      - run: cargo clippy --all -- -D warnings

      - if: ${{ matrix.rust == 'nightly' }}
        working-directory: ./macro
        run: cargo fmt --all -- --check

      - if: ${{ matrix.rust == 'nightly' }}
        working-directory: ./macro
        run: cargo clippy --all -- -D warnings
