name: CI

on:
  push:
  pull_request:
  schedule: [cron: "40 1 * * *"]

env:
  RUST_BACKTRACE: 1

jobs:
  test:
    name: Test Rust ${{ matrix.rust }} on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { rust: nightly, os: ubuntu-latest }
          - { rust: nightly, os: macos-latest }
          - { rust: nightly, os: windows-latest }
          - { rust: stable, os: ubuntu-latest }
          - { rust: stable, os: macos-latest }
          - { rust: stable, os: windows-latest }
          - { rust: 1.45.0, os: ubuntu-latest }
          - { rust: 1.45.0, os: macos-latest }
          - { rust: 1.45.0, os: windows-latest }
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true
      - uses: Swatinem/rust-cache@v1
      - name: Check Cargo availability
        run: cargo --version
      - run: cargo test --verbose --all

  clippy:
    name: Lint with clippy
    runs-on: ubuntu-latest
    env:
      RUSTFLAGS: -Dwarnings
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          components: clippy
      - uses: Swatinem/rust-cache@v1
      - name: Run clippy
        uses: actions-rs/clippy-check@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

  rustfmt:
    name: Verify code formatting
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          components: rustfmt
      - uses: Swatinem/rust-cache@v1
      - name: Run fmt --all -- --check
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check
