on:
  pull_request:
    branches:
      - main
  push:
  workflow_dispatch:

name: CI

env:
  CARGO_TERM_COLOR: always

jobs:
  check:
    name: cargo check
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        toolchain: ["1.60.0", stable, nightly]
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@v1
        with:
          toolchain: ${{ matrix.toolchain }}
      - uses: Swatinem/rust-cache@v2
      - run: cargo check

  rustfmt:
    name: rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@v1
        with:
          toolchain: nightly
          components: rustfmt
      - uses: Swatinem/rust-cache@v2
      - run: cargo fmt --all -- --check

  clippy:
    name: clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@v1
        with:
          toolchain: stable
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo clippy -- -A clippy::new-ret-no-self -D warnings
