name: CI

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

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

jobs:
  lint:
    name: Lint & Format
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install uv
        run: curl -LsSf https://astral.sh/uv/install.sh | sh

      - name: Install Python 3.14.3
        run: uv python install 3.14.3

      - name: Install dependencies
        run: uv sync --group dev --python 3.14.3

      - name: Run linter
        run: uv run --python 3.14.3 ruff check privacyforms_pdf tests

      - name: Check formatting
        run: uv run --python 3.14.3 ruff format --check privacyforms_pdf tests

  type-check:
    name: Type Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install uv
        run: curl -LsSf https://astral.sh/uv/install.sh | sh

      - name: Install Python 3.14.3
        run: uv python install 3.14.3

      - name: Install dependencies
        run: uv sync --group dev --python 3.14.3

      - name: Run type checker
        run: uv run --python 3.14.3 ty check

  test:
    name: Test (Python ${{ matrix.python-version }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.13", "3.14.3", "3.14t"]

    steps:
      - uses: actions/checkout@v4

      - name: Install uv
        run: curl -LsSf https://astral.sh/uv/install.sh | sh

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

      - name: Install dependencies
        run: uv sync --group dev --python ${{ matrix.python-version }}

      - name: Run tests
        run: uv run --python ${{ matrix.python-version }} pytest -v --cov --cov-report=xml

      - name: Upload coverage to Codecov
        if: matrix.python-version == '3.14.3'
        uses: codecov/codecov-action@v5
        with:
          files: ./coverage.xml
          fail_ci_if_error: false
          verbose: true
