on:
  push:
    branches: [ master ]
  pull_request:
  merge_group:

name: Lints compliance check

env:
  CLIPPY_PARAMS: -W clippy::all -W clippy::pedantic -W clippy::nursery -W clippy::cargo

jobs:
  clippy:
    strategy:
      matrix:
        toolchain: [ stable, nightly ]
        include:
          # Nightly is only for reference and allowed to fail
          - toolchain: nightly
            experimental: true
    runs-on: ubuntu-latest
    continue-on-error: ${{ matrix.experimental || false }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}
          components: clippy
      - name: Run clippy (no features)
        run: cargo clippy --all --no-default-features -- -D warnings
      - name: Run clippy (all features)
        run: cargo clippy --all --all-features -- -D warnings
  
  # Additonal clippy checks for riscv-rt
  clippy-riscv-rt:
    strategy:
      matrix:
        toolchain: [ stable, nightly ]
    runs-on: ubuntu-latest
    continue-on-error: ${{ matrix.experimental || false }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}
          components: clippy
      - name: Run clippy (s-mode)
        run: cargo clippy --package riscv-rt --all --features=s-mode -- -D warnings
      - name: Run clippy (single-hart)
        run: cargo clippy --package riscv-rt --all --features=single-hart -- -D warnings

   # Job to check that all the lint checks succeeded
  clippy-check:
    needs:
    - clippy
    - clippy-riscv-rt
    runs-on: ubuntu-latest
    if: always()
    steps:
      - run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'