permissions:
  contents: read

# Spend CI time only on latest ref: https://github.com/jonhoo/rust-ci-conf/pull/5
concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

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

name: check
jobs:
  fmt:
    runs-on: ubuntu-latest
    name: nightly / fmt
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: Install nightly
        uses: dtolnay/rust-toolchain@nightly
        with:
          components: rustfmt
      - name: cargo fmt --check
        run: cargo fmt --check

  clippy:
    runs-on: ubuntu-latest
    name: ${{ matrix.toolchain }} / clippy
    permissions:
      contents: read
      checks: write
    strategy:
      fail-fast: false
      matrix:
        toolchain: [stable]
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: Install ${{ matrix.toolchain }}
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}
          components: clippy
      - name: cargo clippy
        run: cargo clippy --all-features -- -D warnings
  doc:
    runs-on: ubuntu-latest
    name: nightly / doc
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: Install nightly
        uses: dtolnay/rust-toolchain@nightly
      - name: cargo doc
        run: cargo doc --no-deps --all-features
        env:
          RUSTDOCFLAGS: --cfg docsrs

  deny:
    runs-on: ubuntu-latest
    name: ubuntu / cargo-deny
    strategy:
      matrix:
        checks:
          - advisories
          - bans licenses sources
    continue-on-error: ${{ matrix.checks == 'advisories'}}
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: cargo-deny
        uses: EmbarkStudios/cargo-deny-action@v2
        with:
          command: check ${{ matrix.checks }}

  hack:
    runs-on: ubuntu-latest
    name: ubuntu / stable / features
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: Install stable
        uses: dtolnay/rust-toolchain@stable
      - name: cargo install cargo-hack
        uses: taiki-e/install-action@cargo-hack
      # intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4
      - name: cargo hack
        run: cargo hack --feature-powerset check

  msrv:
    runs-on: ubuntu-latest
    # we use a matrix here just because env can't be used in job names
    # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
    strategy:
      matrix:
        msrv: ["1.84"]
    name: ubuntu / ${{ matrix.msrv }}
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: Install ${{ matrix.msrv }}
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.msrv }}
      - name: cargo +${{ matrix.msrv }} check
        run: cargo check
