name: CI

on:
  push:
  pull_request:

concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      CARGO_TERM_COLOR: always
      RUST_BACKTRACE: 1
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Rust cache
        uses: Swatinem/rust-cache@v2

      - name: rustfmt
        run: cargo fmt -p muxer --check

      - name: clippy (default)
        run: cargo clippy -p muxer --all-targets -- -D warnings

      - name: test (default)
        run: cargo test -p muxer --all-targets

      - name: clippy (no default features)
        run: cargo clippy -p muxer --all-targets --no-default-features -- -D warnings

      - name: test (no default features)
        run: cargo test -p muxer --all-targets --no-default-features

      - name: clippy (all features)
        run: cargo clippy -p muxer --all-targets --all-features -- -D warnings

      - name: test (all features)
        run: cargo test -p muxer --all-targets --all-features

      - name: clippy (contextual, no default features)
        run: cargo clippy -p muxer --all-targets --no-default-features --features contextual -- -D warnings

      - name: test (contextual, no default features)
        run: cargo test -p muxer --all-targets --no-default-features --features contextual

      - name: clippy (serde, no default features)
        run: cargo clippy -p muxer --lib --tests --no-default-features --features serde -- -D warnings

      - name: test (serde, no default features)
        run: cargo test -p muxer --lib --tests --no-default-features --features serde

      - name: doctests (default)
        run: cargo test -p muxer --doc

      - name: doctests (all features)
        run: cargo test -p muxer --doc --all-features

      - name: rustdoc (all features)
        env:
          RUSTDOCFLAGS: -D warnings
        run: cargo doc -p muxer --no-deps --all-features
