name: Lint

on:
  push:
    branches:
      - master

  pull_request:

env:
  CARGO_INCREMENTAL: 0
  RUST_BACKTRACE: short

jobs:
  static-analysis:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Set up Rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          components: rustfmt, clippy

      - name: Cache dependencies
        uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641

      - name: Run `cargo fmt`
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

      - name: Run `cargo clippy`
        uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: -- -D warnings
