name: Rust

on:
  push:
    branches:
      - '*'
  pull_request:
    types: [opened, synchronize, reopened]
    branches:
      - main

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-Dwarnings"

jobs:

  msrv:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        features:
          - "ext,http,ws,mio,openssl"
          - "ext,http,ws,mio,ktls"
          - "ext,http,ws,mio,rustls-webpki"
          - "ext,http,ws,mio,rustls-native"
    steps:
      - uses: actions/checkout@v4
      - uses: taiki-e/install-action@cargo-hack
      - run: cargo hack check --rust-version --workspace --all-targets --features=${{ matrix.features }} --ignore-private

  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        features:
          - "ext,http,ws,mio,openssl"
          - "ext,http,ws,mio,ktls"
          - "ext,http,ws,mio,rustls-webpki"
          - "ext,http,ws,mio,rustls-native"
    steps:
      - uses: actions/checkout@v2
      - uses: actions/cache@v3
        id: cache-dependencies
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - uses: actions-rs/cargo@v1
        with:
          command: test
          args: --features=${{ matrix.features }}

  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          components: rustfmt
      - uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

  clippy:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        features:
          - "ext,http,ws,mio,openssl"
          - "ext,http,ws,mio,ktls"
          - "ext,http,ws,mio,rustls-webpki"
          - "ext,http,ws,mio,rustls-native"
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          components: clippy
      - uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: --no-deps --all-targets --features=${{ matrix.features }} -- -D warnings
