name: Lint

on:
  pull_request:
    branches: [master, main]
  push:
    branches: [staging, trying]

concurrency:
  group: lint-${{ github.ref }}
  cancel-in-progress: true

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

    steps:
      - uses: actions/checkout@v2

      - name: OpenSSL Libs
        if: matrix.os == 'ubuntu-latest' && matrix.features == 'all'
        run: |
          sudo apt-get update
          sudo apt-get install libssl-dev

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

      - uses: Swatinem/rust-cache@v1

      - name: Spell Check
        uses: crate-ci/typos@master

      - name: Install Just
        if: ${{ matrix.rust == 'nightly' || matrix.rust == 'stable' }}
        run: cargo install just

      - name: Check Formatting
        if: ${{ matrix.rust == 'nightly' }}
        run: just fmt-check

      - name: Clippy
        if: ${{ matrix.rust == 'stable' }}
        run: just lint

      - name: MSRV Check
        if: ${{ matrix.rust == '1.83.0' }}
        # Note we have to actually _run_ the application to check the MSRV.
        # The standard `cargo check` may successfully build on an earlier
        # Rust, but cargo-oudated by not be able to successfully run in such
        # environments.
        #
        # Note2: we exclude git2-curl because it requires libgit2-sys which
        # must match the same version that our internal cargo transitively
        # requires
        run: cargo run -- outdated -x git2-curl
