name: CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  check:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: pgvector/pgvector:pg16
        ports: ["5432:5432"]
        env:
          POSTGRES_PASSWORD: postgres
        options: >-
          --health-cmd "pg_isready -U postgres"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    env:
      DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/postgres?schema=public"
      LLM_PROVIDER: "ollama"
      EMBEDDER_PROVIDER: "ollama"
      EMBEDDING_DIM: "1024"
      OLLAMA_URL: "http://localhost:11434"
      OLLAMA_LLM_MODEL: "llama3.1"
      OLLAMA_EMBEDDING_MODEL: "bge-m3"
    steps:
      - uses: actions/checkout@v6

      - uses: actions/setup-node@v6
        with:
          node-version: 20
          cache: npm

      - run: npm ci
      - run: npx prisma generate
      - run: psql "$DATABASE_URL" -c "CREATE EXTENSION IF NOT EXISTS vector;"
      - run: npx prisma db push --accept-data-loss
      - run: npm run typecheck
      - run: npm run lint
      - run: npm run test
      - run: npm run build
