name: CI

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

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13"]
        django-version: ["4.2", "5.0", "5.1", "5.2", "6.0"]
        exclude:
          - python-version: "3.10"
            django-version: "5.1"
          - python-version: "3.10"
            django-version: "5.2"
          - python-version: "3.10"
            django-version: "6.0"
          - python-version: "3.11"
            django-version: "6.0"
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          pip install -e ".[dev]"
          pip install "django~=${{ matrix.django-version }}.0"
      - name: Run tests with coverage
        run: pytest --cov=query_doctor --cov-report=xml --cov-report=term-missing
      - name: Upload coverage
        if: matrix.python-version == '3.12' && matrix.django-version == '5.2'
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml
          fail_ci_if_error: false

  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - name: Install dependencies
        run: pip install ruff
      - name: Check linting
        run: ruff check src/ tests/
      - name: Check formatting
        run: ruff format src/ tests/ --check

  typecheck:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - name: Install dependencies
        run: pip install -e ".[dev]"
      - name: Run mypy
        run: mypy src/query_doctor/
