name: CI

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

jobs:
  backend:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: pgvector/pgvector:pg16
        env:
          POSTGRES_DB: scilit_test
          POSTGRES_USER: scilit
          POSTGRES_PASSWORD: test
        ports: ["5432:5432"]
        options: >-
          --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: "3.12" }
      - name: Install dependencies
        run: |
          cd backend
          pip install -e ".[dev]"
      - name: Lint (Ruff)
        run: |
          cd backend
          pip install ruff
          ruff check app/ tests/
          ruff format --check app/ tests/
      - name: Unit Tests
        run: |
          cd backend
          pytest tests/ -v --tb=short --color=yes --cov=app --cov-report=term-missing
        env:
          DATABASE_URL: postgresql+asyncpg://scilit:test@localhost:5432/scilit_test
          JWT_SECRET: ci-test-secret

  frontend:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: "20" }
      - name: Install
        run: cd frontend && npm ci
      - name: Type Check
        run: cd frontend && npx vue-tsc --noEmit
      - name: Build
        run: cd frontend && npm run build
