name: Build and Lint
on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:

jobs:
  check:
    name: cargo-check
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust: [stable, beta, nightly]
        runtimes: ["tokio_runtime", "async_runtime", "async_runtime,tokio"]
    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}}
        run: cargo check --all-targets --no-default-features --features ${{matrix.runtimes}}

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

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

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

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

      - name: cargo-doc
        run: cargo doc --no-deps

  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
