name: Stable lints

# We only run these lints on trial-merges of PRs to reduce noise.
on: pull_request

jobs:
  clippy:
    name: Clippy (MSRV)
    timeout-minutes: 30
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run Clippy
        uses: auguwu/clippy-action@1.3.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          working-directory: ${{ inputs.target }}
          deny: warnings

  clippy-nostd:
    name: Clippy (MSRV) no_std for ${{ matrix.target }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - wasm32-wasip1
    steps:
      - uses: actions/checkout@v4
        with:
          path: crate_root
      # We use a synthetic crate to ensure no dev-dependencies are enabled, which can
      # be incompatible with some of these targets.
      - name: Create synthetic crate for testing
        run: cargo init --edition 2021 --lib ci-build
      - name: Copy Rust version into synthetic crate
        run: cp crate_root/rust-toolchain.toml ci-build/
      - name: Copy patch directives into synthetic crate
        run: |
          echo "[patch.crates-io]" >> ./ci-build/Cargo.toml
          cat ./crate_root/Cargo.toml | sed "0,/.\+\(patch.crates.\+\)/d" >> ./ci-build/Cargo.toml
      - name: Add no_std pragma to lib.rs
        run: |
          echo "#![no_std]" > ./ci-build/src/lib.rs
      - name: Add dependencies of the synthetic crate (e.g. sapling-crypto)
        working-directory: ./ci-build
        run: cargo add --no-default-features --path ../crate_root
      - name: Add lazy_static with the spin_no_std feature
        working-directory: ./ci-build
        run: cargo add lazy_static --no-default-features --features "spin_no_std"
      - name: Add typenum with no default features
        working-directory: ./ci-build
        run: cargo add typenum --no-default-features
      - name: Show Cargo.toml for the synthetic crate
        working-directory: ./ci-build
        run: cat Cargo.toml
      - name: Copy pinned dependencies into synthetic crate
        run: cp crate_root/Cargo.lock ci-build/
      - name: Add target
        working-directory: ./ci-build
        run: rustup target add ${{ matrix.target }}
      - name: Clippy no_std for target
        working-directory: ./ci-build
        run: cargo clippy --verbose --target ${{ matrix.target }}
