on: [push, pull_request]

name: Build and Lint

jobs:
  check:
    name: cargo-check
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust: [stable, beta, nightly]
        runtimes: ["tokio_runtime", "async_runtime", "async_runtime,tokio"]
        channels: [async_channel, futures_channel] # futures_channel is default
    steps:
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust }}

      - name: check
        run: cargo check --all-targets

      - name: check ${{matrix.runtimes}},${{matrix.channels}}
        run: cargo check --all-targets --no-default-features --features ${{matrix.runtimes}},${{matrix.channels}}

  fmtclippy:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust: [stable, beta]
        runtimes: ["tokio_runtime", "async_runtime", "async_runtime,tokio"]
        channels: [async_channel, futures_channel] # futures_channel is default
    steps:
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy, rustfmt
      - uses: Swatinem/rust-cache@v2

      - name: clippy
        run: cargo clippy --workspace --all-targets -- -D warnings

      - name: clippy ${{matrix.runtimes}},${{matrix.channels}}
        run: cargo clippy --workspace --no-default-features --features ${{matrix.runtimes}},${{matrix.channels}}

      - name: cargo-clippy
        run: cargo clippy --workspace --all-targets -- -D warnings

      - name: cargo-fmt
        run: cargo fmt --all --check

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