name: build

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main
  schedule:
    - cron: "12 3 * * *"

jobs:
  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: rustup component add rustfmt
      - run: cargo fmt -- --check

  clippy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: rustup default 1.82.0 && rustup component add clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo clippy --all-targets -- -D warnings -D clippy::all
      - run: cargo clippy --all-targets --features native-tls -- -D warnings -D clippy::all
      - run: cargo clippy --all-targets --features rustls-ring-platform-verifier -- -D warnings -D clippy::all
      - run: cargo clippy --all-targets --features rustls-ring-native -- -D warnings -D clippy::all
      - run: cargo clippy --all-targets --features rustls-ring-webpki -- -D warnings -D clippy::all
      - run: cargo clippy --all-targets --features rustls-aws-lc-platform-verifier -- -D warnings -D clippy::all
      - run: cargo clippy --all-targets --features rustls-aws-lc-native -- -D warnings -D clippy::all
      - run: cargo clippy --all-targets --features rustls-aws-lc-webpki -- -D warnings -D clippy::all
      - run: cargo clippy --all-targets --features flate2 -- -D warnings -D clippy::all
      - run: cargo clippy --all-targets --all-features -- -D warnings -D clippy::all

  test:
    strategy:
      matrix:
        os: [ ubuntu-latest, macos-latest, windows-latest ]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - run: rustup update
      - uses: Swatinem/rust-cache@v2
      - run: cargo test
      - run: cargo test --features native-tls
      - run: cargo test --features rustls-ring-platform-verifier
      - run: cargo test --features rustls-ring-native
      - run: cargo test --features rustls-ring-webpki
      - run: cargo test --features rustls-aws-lc-platform-verifier
        if: ${{ matrix.os != 'windows-latest' }}
      - run: cargo test --features rustls-aws-lc-native
        if: ${{ matrix.os != 'windows-latest' }}
      - run: cargo test --features rustls-aws-lc-webpki
        if: ${{ matrix.os != 'windows-latest' }}
      - run: cargo test --features flate2
      - run: cargo test --all-features
        if: ${{ matrix.os != 'windows-latest' }}

  test_msv:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - run: rustup toolchain install nightly && rustup default 1.74.0
      - uses: Swatinem/rust-cache@v2
      - run: cargo +nightly update -Z direct-minimal-versions
      - run: cargo test
      - run: cargo test --features native-tls
      - run: cargo test --features rustls-ring-platform-verifier
      - run: cargo test --features rustls-ring-native
      - run: cargo test --features rustls-ring-webpki
      - run: cargo test --features rustls-aws-lc-platform-verifier
      - run: cargo test --features rustls-aws-lc-native
      - run: cargo test --features rustls-aws-lc-webpki
      - run: cargo test --features flate2
      - run: cargo test --all-features

  rustdoc:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: rustup override set 1.82.0
      - uses: Swatinem/rust-cache@v2
      - run: cargo doc --all-features --no-deps
        env:
          RUSTDOCFLAGS: -D warnings

  deny:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: taiki-e/install-action@v2
        with: { tool: cargo-deny }
      - run: cargo deny check

  semver_checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@v2
        with: { tool: cargo-semver-checks }
      - run: cargo semver-checks check-release

  typos:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: taiki-e/install-action@v2
        with: { tool: typos-cli }
      - run: typos

  codecov:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@v2
        with: { tool: cargo-llvm-cov }
      - run: cargo llvm-cov --codecov --output-path codecov.json
      - uses: codecov/codecov-action@v5
        with:
          files: codecov.json
          flags: rust
          fail_ci_if_error: true
          token: ${{ secrets.CODECOV_TOKEN }}

  codspeed:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
      - uses: taiki-e/install-action@v2
        with: { tool: cargo-codspeed }
      - run: cargo codspeed build
      - uses: CodSpeedHQ/action@v3
        with:
          run: cargo codspeed run
          token: ${{ secrets.CODSPEED_TOKEN }}
