Documentation
name: CI

on:
  pull_request:
  push:
    branches:
      - master

env:
  RUSTFLAGS: "--cfg lettre_ignore_tls_mismatch"
  RUSTDOCFLAGS: "--cfg lettre_ignore_tls_mismatch"
  RUST_BACKTRACE: full

jobs:
  rustfmt:
    name: rustfmt / nightly-2025-03-20
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install rust
        run: |
          rustup default nightly-2025-03-20
          rustup component add rustfmt

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

  clippy:
    name: clippy / stable
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install rust
        run: |
          rustup update --no-self-update stable
          rustup component add clippy

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

  check:
    name: check / stable
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install rust
        run: rustup update --no-self-update stable

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

      - name: Install cargo hack
        run: cargo install cargo-hack --debug

      - name: Check with cargo hack
        run: cargo hack check --feature-powerset --depth 3 --at-least-one-of aws-lc-rs,ring,rustls-no-provider --at-least-one-of rustls-native-certs,webpki-roots

  test:
    name: test / ${{ matrix.name }}
    runs-on: ubuntu-latest

    strategy:
      matrix:
        include:
          - name: stable
            rust: stable
          - name: beta
            rust: beta
          - name: '1.85'
            rust: '1.85'

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install rust
        run: |
          rustup default ${{ matrix.rust }}
          rustup update --no-self-update ${{ matrix.rust }}

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

      - name: Install postfix
        run: |
          DEBIAN_FRONTEND=noninteractive sudo apt-get update
          DEBIAN_FRONTEND=noninteractive sudo apt-get -y install postfix

      - name: Run SMTP server
        run: smtp-sink 2525 1000&

      - name: Install coredns
        run: |
          wget -q https://github.com/coredns/coredns/releases/download/v1.14.2/coredns_1.14.2_linux_amd64.tgz
          tar xzf coredns_1.14.2_linux_amd64.tgz

      - name: Start coredns
        run: |
          sudo ./coredns -conf testdata/coredns.conf &
          sudo systemctl stop systemd-resolved
          echo "nameserver 127.0.0.54" | sudo tee /etc/resolv.conf

      - name: Install dkimverify
        run: sudo apt -y install python3-dkim

      - name: Test with no default features
        run: cargo test --no-default-features

      - name: Test with default features
        run: cargo test

      - name: Test with all features (-native-tls)
        run: cargo test --no-default-features --features async-std1,async-std1-rustls,aws-lc-rs,rustls-native-certs,boring-tls,builder,dkim,file-transport,file-transport-envelope,hostname,mime03,pool,rustls-native-certs,rustls,sendmail-transport,smtp-transport,tokio1,tokio1-boring-tls,tokio1-rustls,tracing

      - name: Test with all features (-boring-tls)
        run: cargo test --no-default-features --features async-std1,async-std1-rustls,aws-lc-rs,rustls-native-certs,builder,dkim,file-transport,file-transport-envelope,hostname,mime03,native-tls,pool,rustls-native-certs,rustls,sendmail-transport,smtp-transport,tokio1,tokio1-native-tls,tokio1-rustls,tracing

#  coverage:
#    name: Coverage
#    runs-on: ubuntu-latest
#    steps:
#      - uses: actions/checkout@v6
#      - uses: actions-rs/toolchain@v1
#        with:
#          toolchain: nightly
#          override: true
#      - run: sudo DEBIAN_FRONTEND=noninteractive apt-get -y install postfix
#      - run: smtp-sink 2525 1000&
#      - uses: actions-rs/cargo@v1
#        with:
#          command: test
#          args: --no-fail-fast
#        env:
#          CARGO_INCREMENTAL: "0"
#          RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
#      - id: coverage
#        uses: actions-rs/grcov@v0.1
#      - name: Coveralls upload
#        uses: coverallsapp/github-action@master
#        with:
#          github-token: ${{ secrets.GITHUB_TOKEN }}
#          path-to-lcov: ${{ steps.coverage.outputs.report }}