name: CI

on:
  push:
    branches:
      - main
  pull_request:
    paths:
      - ".github/workflows/tests.yml"
      - "Makefile"
      - "pyproject.toml"
      - "uv.lock"
      - "src/**"
      - "tests/**"
      - "examples/**"

env:
  UV_FROZEN: "1"

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Set up uv (3.13)
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true
          python-version: "3.13"
      - name: Install dependencies
        run: make sync
      - name: Run lint
        run: make lint

  typecheck:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Set up uv (3.13)
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true
          python-version: "3.13"
      - name: Install dependencies
        run: make sync
      - name: Run mypy
        run: make mypy

  tests:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up uv (Python 3.13)
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true
          python-version: "3.13"

      - name: Install dependencies
        run: make sync

      - name: Run tests with coverage
        if: github.event_name != 'pull_request' || (github.event.pull_request.user.login != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork)
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: make coverage

      - name: Run unit tests for PRs without secrets
        if: github.event_name == 'pull_request' && (github.event.pull_request.user.login == 'dependabot[bot]' || github.event.pull_request.head.repo.fork)
        run: uv run pytest tests/test_*_modules

  tests_py312:
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up uv (Python 3.12)
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true
          python-version: "3.12"

      - name: Install dependencies
        run: make sync

      - name: Run tests with coverage (3.12)
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: make coverage
