name: tests

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

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  core:
    name: core (${{ matrix.os }}, py${{ matrix.python-version }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
        python-version: ["3.11", "3.12", "3.13"]

    steps:
      - uses: actions/checkout@v4

      - name: Install uv
        uses: astral-sh/setup-uv@v3
        with:
          enable-cache: true
          cache-dependency-glob: "uv.lock"

      - name: Set up Python
        run: uv python install ${{ matrix.python-version }}

      - name: Sync core dependencies
        run: uv sync --frozen --all-extras

      - name: Install Tesseract (Ubuntu)
        if: matrix.os == 'ubuntu-latest'
        run: sudo apt-get update && sudo apt-get install -y tesseract-ocr

      - name: Install Tesseract (macOS)
        if: matrix.os == 'macos-latest'
        run: brew install tesseract

      - name: Run ruff
        run: uv run ruff check src/ tests/

      - name: Check formatting
        run: uv run ruff format --check src/ tests/

      - name: Run mypy
        run: uv run mypy src/ocr_pipeline

      - name: Run pytest
        run: uv run pytest tests/ -q --maxfail=1

  doctor-smoke:
    name: doctor CLI smoke test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v3
      - run: uv sync --frozen
      - name: Install Tesseract
        run: sudo apt-get update && sudo apt-get install -y tesseract-ocr
      - name: Run doctor
        run: uv run ocr-pipeline doctor
