# GENERATED: this file is generated by https://github.com/facet-rs/facet-dev

name: Tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  merge_group:

jobs:
  test:
    runs-on: depot-ubuntu-24.04-32

    container:
      image: ghcr.io/facet-rs/facet-ci:latest-amd64
    steps:
      - uses: actions/checkout@v5

      - uses: Swatinem/rust-cache@v2

      - name: ✨ Run tests
        shell: bash
        run: |
          set -euo pipefail

          echo "::group::All tests except doc-tests"
          cargo nextest run --all-features
          echo "::endgroup::"

          echo "::group::Doc tests"
          output=$(cargo test --doc --all-features 2>&1) || exit_code=$?
          if [ "${exit_code:-0}" -ne 0 ]; then
            if [ $exit_code -eq 101 ] && echo "$output" | grep -q "no library targets found in package"; then
              echo "No library targets found, skipping doc tests"
            else
              echo "$output"
              exit $exit_code
            fi
          fi
          echo "::endgroup::"

  msrv:
    runs-on: depot-ubuntu-24.04-32

    container:
      image: ghcr.io/facet-rs/facet-ci:latest-amd64
    steps:
      - uses: actions/checkout@v5

      - uses: Swatinem/rust-cache@v2

      - uses: taiki-e/install-action@cargo-hack

      - name: ✨ Check MSRV
        shell: bash
        run: |
          set -euo pipefail

          cargo hack check --each-feature --locked \
            --rust-version --workspace \
            --keep-going --exclude-no-default-features

  minimal-versions:
    runs-on: depot-ubuntu-24.04-32

    container:
      image: ghcr.io/facet-rs/facet-ci:latest-amd64
    steps:
      - uses: actions/checkout@v5

      - uses: Swatinem/rust-cache@v2

      - name: ✨ Check minimal versions
        shell: bash
        run: |
          set -euo pipefail

          # Install nightly for minimal-versions feature
          rustup toolchain install nightly

          # Generate lockfile with minimal versions
          cargo +nightly generate-lockfile -Z minimal-versions

          # Check with stable using minimal versions
          cargo check --workspace --all-features --locked --keep-going

  docs:
    runs-on: depot-ubuntu-24.04-32

    container:
      image: ghcr.io/facet-rs/facet-ci:latest-amd64
    steps:
      - uses: actions/checkout@v5

      - uses: Swatinem/rust-cache@v2

      - name: ✨ Check documentation
        shell: bash
        env:
          RUSTDOCFLAGS: -D warnings
        run: |
          set -euo pipefail

          cargo doc --workspace --all-features --no-deps --document-private-items --keep-going

  lockfile:
    runs-on: depot-ubuntu-24.04-4

    container:
      image: ghcr.io/facet-rs/facet-ci:latest-amd64
    steps:
      - uses: actions/checkout@v5

      - uses: Swatinem/rust-cache@v2

      - name: ✨ Check lockfile is updated
        shell: bash
        run: |
          cargo update --workspace --locked

  clippy:
    runs-on: depot-ubuntu-24.04-16

    container:
      image: ghcr.io/facet-rs/facet-ci:latest-amd64
    permissions:
      security-events: write # to upload sarif results
    steps:
      - uses: actions/checkout@v5

      - uses: Swatinem/rust-cache@v2

      - name: Install SARIF tools
        shell: bash
        run: |
          cargo install clippy-sarif --locked
          cargo install sarif-fmt --locked

      - name: ✨ Run clippy with SARIF output
        shell: bash
        run: |
          cargo clippy --workspace --all-features --all-targets --message-format=json | clippy-sarif | tee clippy-results.sarif | sarif-fmt
        continue-on-error: true

      - name: Upload SARIF results
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: clippy-results.sarif
          wait-for-processing: true

      - name: Report status
        shell: bash
        run: |
          cargo clippy --workspace --all-features --all-targets --keep-going -- -D warnings --allow deprecated
