name: CI

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

jobs:
  test:
    runs-on: ubuntu-latest

    services:
      postgres:
        image: pgvector/pgvector:pg16
        env:
          POSTGRES_USER: cogos
          POSTGRES_PASSWORD: cogos_dev
          POSTGRES_DB: cogos_test
        ports:
          - 5432:5432
        options: >-
          --health-cmd "pg_isready -U cogos -d cogos_test"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    env:
      TEST_DATABASE_URL: postgresql://cogos:cogos_dev@localhost:5432/cogos_test

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python 3.12
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install dependencies
        run: pip install -e ".[dev]"

      - name: Typecheck
        run: pyright

      - name: Run tests
        run: pytest tests/ -q
