name: CI

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

jobs:
  build:
    runs-on: docker-x64
    container:
      image: python:3.11-slim
    steps:
      - uses: actions/checkout@v4

      - name: Install system deps
        run: |
          apt-get update
          apt-get install -y --no-install-recommends gcc libpq-dev curl git ca-certificates
          rm -rf /var/lib/apt/lists/*

      - name: Install uv
        run: |
          curl -LsSf https://astral.sh/uv/install.sh | sh
          echo "$HOME/.local/bin" >> $GITHUB_PATH

      - name: Setup Python
        run: |
          uv python install 3.11
          uv venv --python 3.11 .venv

      - name: Install dependencies
        run: |
          uv pip install --python .venv/bin/python -r requirements.txt
          uv pip install --python .venv/bin/python -e ".[dev]"

      - name: Lint (ruff)
        run: source .venv/bin/activate && ruff check . --exit-non-zero-on-fix

      - name: Format check (ruff)
        run: source .venv/bin/activate && ruff format --check .

      - name: Type check (mypy)
        run: source .venv/bin/activate && mypy app/ --ignore-missing-imports || true
        continue-on-error: true

      - name: Test (pytest)
        run: source .venv/bin/activate && pytest tests/ -x -q --tb=short -m "not integration"