name: CI
on:
    push:
        branches:
            - main
            - ci
    pull_request:

jobs:
    rustfmt:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Nightly Rust
              uses: dtolnay/rust-toolchain@master
              with:
                  toolchain: nightly
                  components: rustfmt

            - name: Rustfmt
              run: cargo +nightly fmt -- --check

    clippy:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Stable Rust
              uses: dtolnay/rust-toolchain@master
              with:
                  toolchain: stable
                  components: clippy

            - name: Clippy
              run: cargo clippy --all-targets --all-features -- -D warnings

    rustdoc:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Stable Rust
              uses: dtolnay/rust-toolchain@master
              with:
                  toolchain: stable

            - name: Rustdoc
              run: cargo rustdoc --all-features -- -D warnings

    test:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Stable Rust
              uses: dtolnay/rust-toolchain@master
              with:
                  toolchain: stable

            - name: Test default features
              run: cargo test --all-targets

            - name: Test forwarded-header feature
              run: cargo test --all-targets --features forwarded-header

            - name: Test docs
              run: cargo test --doc

    typos:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Check typos
              uses: crate-ci/typos@master
              with:
                  files: .

    cargo_sort:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Stable Rust
              uses: dtolnay/rust-toolchain@master
              with:
                  toolchain: stable

            - name: Install cargo-sort
              run: cargo install --locked cargo-sort

            - name: Check `Cargo.toml` sort
              run: cargo sort -c

    machete:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Stable Rust
              uses: dtolnay/rust-toolchain@master
              with:
                  toolchain: stable

            - name: Install `cargo-machete`
              run: cargo install --locked cargo-machete

            - name: Check unused Cargo dependencies
              run: cargo machete
