---
name: Test

on:
  workflow_call:
  pull_request:
    branches:
      - '*'

jobs:
  format:
    name: Format
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: llvm-tools-preview

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

  lint:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable

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

  check:
    name: Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable

      - name: Check
        run: cargo check

  test-linux:
    name: Test (Linux)
    runs-on: ubuntu-latest
    needs:
      - format
      - lint
      - check
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable

      - name: test
        run: cargo test --lib --bins

  test-portable:
    name: Test (Portable)
    strategy:
      matrix:
        os:
          - macOS-latest
          - windows-latest
        rust:
          - stable
    runs-on: ${{ matrix.os }}
    needs:
      - format
      - lint
      - check
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable

      - name: test
        # Keep this list free of MinIO/container-backed tests. Those run in
        # containers.yml on Ubuntu, where Docker and an explicit MinIO endpoint
        # are available. In particular, integration_streams includes a live
        # multipart resume path and is intentionally excluded here.
        run: >-
          cargo test --lib --bins
          --test integration_encryption
          --test integration_json_output
          --test integration_minio_runtime
          --test integration_multipart
          --test integration_s3_actions
          --test integration_stdin
