Repository navigation
173 lines (165 loc) · 6.39 KB
/
Copy pathci.yml
File metadata and controls
173 lines (165 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: ci
on:
push:
branches: [main, v2, "platform/**"]
pull_request:
jobs:
backend:
runs-on: ubuntu-latest
services:
postgres:
image: pgvector/pgvector:pg16
env:
# Disposable test database: trust auth, so no credentials live in this workflow.
POSTGRES_HOST_AUTH_METHOD: trust
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready -U postgres" --health-interval 5s --health-timeout 5s --health-retries 20
# A separate server plays the customer's database: the SSRF guard (rightly) refuses
# connections to the platform's own database endpoint.
customer:
image: postgres:16
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports: ["5433:5432"]
options: >-
--health-cmd "pg_isready -U postgres" --health-interval 5s --health-timeout 5s --health-retries 20
env:
TEST_DATABASE_URL: postgresql+psycopg://rag@localhost:5432/rag_test
TEST_CUSTOMER_PG_ADMIN_URL: postgresql://postgres@localhost:5433/postgres
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v4
- name: "Prepare databases (the app role must not be a superuser: superusers bypass RLS)"
run: |
psql -h localhost -U postgres -c "CREATE ROLE rag LOGIN NOSUPERUSER NOBYPASSRLS NOCREATEROLE"
for db in rag_test rag_drift; do
psql -h localhost -U postgres -c "CREATE DATABASE $db OWNER rag"
psql -h localhost -U postgres -d "$db" -c "CREATE EXTENSION IF NOT EXISTS vector"
done
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install
run: pip install -e ".[dev]"
- name: Lint
run: ruff check app tests
- name: Tests (PostgreSQL 16 + pgvector service)
run: pytest -q
- name: Migration drift check
env:
DATABASE_URL: postgresql+psycopg://rag@localhost:5432/rag_drift
run: |
alembic upgrade head
alembic check
- name: Dependency audit
run: pip install pip-audit && pip-audit --progress-spinner off || true
frontend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: frontend/package-lock.json
- run: npm ci
- run: npx tsc --noEmit
- run: npm run build
- run: npm audit --omit=dev --audit-level=high || true
# Browser end-to-end tests (frontend/e2e) against the real backend + built frontend.
# See docs/TESTING.md. Chat answers are extractive here: no model provider keys.
e2e:
runs-on: ubuntu-latest
timeout-minutes: 30
services:
postgres:
image: pgvector/pgvector:pg16
env:
# Disposable test database: trust auth, so no credentials live in this workflow.
POSTGRES_HOST_AUTH_METHOD: trust
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready -U postgres" --health-interval 5s --health-timeout 5s --health-retries 20
env:
DATABASE_URL: postgresql+psycopg://rag@localhost:5432/rag
# The suite signs in once per browser context and registers a few accounts.
REGISTER_RATE_LIMIT_PER_HOUR: "1000"
LOGIN_RATE_LIMIT_PER_MINUTE: "1000"
E2E_BASE_URL: http://localhost:3000
# The console email backend prints invitation links here; the tests read them.
E2E_BACKEND_LOG: ${{ github.workspace }}/e2e-logs/backend.log
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: backend/pyproject.toml
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: "Prepare databases (the app role must not be a superuser: superusers bypass RLS)"
run: |
psql -h localhost -U postgres -c "CREATE ROLE rag LOGIN NOSUPERUSER NOBYPASSRLS NOCREATEROLE"
for db in rag; do
psql -h localhost -U postgres -c "CREATE DATABASE $db OWNER rag"
psql -h localhost -U postgres -d "$db" -c "CREATE EXTENSION IF NOT EXISTS vector"
done
- name: Install backend
working-directory: backend
run: pip install -e ".[dev]"
- name: Start backend (PostgreSQL service via DATABASE_URL)
working-directory: backend
run: |
mkdir -p "$(dirname "$E2E_BACKEND_LOG")"
nohup python scripts/dev.py > "$E2E_BACKEND_LOG" 2>&1 &
- name: Wait for the API
run: |
for i in $(seq 1 90); do
if curl -fsS http://127.0.0.1:8000/api/v1/health > /dev/null; then echo "backend up"; exit 0; fi
sleep 2
done
echo "backend did not become healthy"; cat "$E2E_BACKEND_LOG"; exit 1
- name: Install frontend dependencies
working-directory: frontend
run: npm ci
- name: Build frontend
working-directory: frontend
run: npm run build
- name: Start frontend (standalone server)
working-directory: frontend
run: |
cp -r .next/static .next/standalone/.next/static
cp -r public .next/standalone/public
# HOSTNAME is preset on runners; the standalone server binds to it.
PORT=3000 HOSTNAME=0.0.0.0 nohup node .next/standalone/server.js > "$GITHUB_WORKSPACE/e2e-logs/frontend.log" 2>&1 &
for i in $(seq 1 60); do
if curl -fsS http://localhost:3000/login > /dev/null; then echo "frontend up"; exit 0; fi
sleep 2
done
echo "frontend did not start"; cat "$GITHUB_WORKSPACE/e2e-logs/frontend.log"; exit 1
- name: Install Playwright Chromium
working-directory: frontend
run: npx playwright install --with-deps chromium
- name: Run end-to-end tests
working-directory: frontend
run: npm run test:e2e
- name: Upload Playwright report and server logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: |
frontend/playwright-report
frontend/test-results
e2e-logs
retention-days: 14