Repository navigation
264 lines (255 loc) · 11.4 KB
/
Copy pathci.yml
File metadata and controls
264 lines (255 loc) · 11.4 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# Blueprint Section 14: verify, local service checks, migrations with
# integration tests, image builds and end-to-end journeys on every pull request
# and push. On main, once the repository is set up for it (see
# docs/operations/deployment.md), the gated deploy job migrates Neon, deploys
# to Vercel and runs the smoke checks. Actions are pinned to commit SHAs.
name: CI
on:
pull_request:
push:
branches: [main]
concurrency:
group: ci-${{ github.ref }}
# Never cancel a run on main: it may be migrating or deploying.
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
verify:
name: Lint, typecheck, test, build
runs-on: ubuntu-latest
# No keys in CI; `next typegen` (typecheck) and `next build` both load env.ts.
env:
SKIP_ENV_VALIDATION: "1"
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm typecheck
- run: pnpm test
- run: pnpm build
- run: pnpm check:route-trace
services:
name: Local service smoke checks
runs-on: ubuntu-latest
# Keyless subset of `pnpm check:services` against the Compose stack (Phase 2).
env:
DIRECT_DATABASE_URL: postgres://foliomind:foliomind@localhost:5433/foliomind
UPSTASH_REDIS_REST_URL: http://localhost:8079
UPSTASH_REDIS_REST_TOKEN: foliomind-local-dev-token
BROWSERLESS_WS_ENDPOINT: ws://localhost:3001
BROWSERLESS_TOKEN: foliomind-local-dev-token
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Start Postgres, Redis, Upstash proxy and Browserless
run: docker compose -f infra/compose.yaml up -d --wait postgres redis upstash-http browserless
- run: pnpm check:services --only=postgres,upstash,browserless
- name: Render both PDF Studio templates in Chromium
run: pnpm --filter @foliomind/pdf test
- name: Service logs
if: failure()
run: docker compose -f infra/compose.yaml logs --tail=100
- name: Stop the stack
if: always()
run: docker compose -f infra/compose.yaml down -v
integration:
name: Migrations and integration tests
runs-on: ubuntu-latest
# Disposable pgvector Postgres plus the Upstash-compatible proxy (Section 14).
env:
DIRECT_DATABASE_URL: postgres://foliomind:foliomind@localhost:5433/foliomind
TEST_DATABASE_URL: postgres://foliomind:foliomind@localhost:5433/foliomind_test
TEST_UPSTASH_REDIS_REST_URL: http://localhost:8079
TEST_UPSTASH_REDIS_REST_TOKEN: foliomind-local-dev-token
DATABASE_RUNTIME_PASSWORD: ci-runtime-password
REQUIRE_TEST_SERVICES: "1"
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Start Postgres, Redis and the Upstash proxy
run: docker compose -f infra/compose.yaml up -d --wait postgres redis upstash-http
- name: Apply the committed migrations to an empty database
run: pnpm db:migrate
- run: pnpm db:roles
- run: pnpm db:seed
- name: Schema and migrations agree
run: |
pnpm db:generate --name drift_check
if [ -n "$(git status --porcelain packages/db/migrations)" ]; then
echo "::error::The Drizzle schema has changes with no migration. Run pnpm db:generate and commit the reviewed SQL."
git status --porcelain packages/db/migrations
exit 1
fi
- name: Domain integration tests (Postgres and Redis)
run: pnpm --filter @foliomind/domain test
- name: Workflow integration tests (ingestion and import on Postgres)
run: pnpm --filter @foliomind/workflows test
- name: Chat integration tests (retrieval, access and quotas on Postgres)
run: pnpm --filter @foliomind/ai test
- name: Rate-limit tests (Upstash proxy)
run: pnpm --filter web exec vitest run lib/rate-limit
- name: Service logs
if: failure()
run: docker compose -f infra/compose.yaml logs --tail=100
- name: Stop the stack
if: always()
run: docker compose -f infra/compose.yaml down -v
docker:
name: Build ${{ matrix.image }} image
runs-on: ubuntu-latest
# A stuck step fails here instead of running to GitHub's 6-hour limit.
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
image: [web, ingestion, generation, migrate]
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
file: infra/docker/Dockerfile.${{ matrix.image }}
push: false
load: ${{ matrix.image == 'ingestion' }}
tags: foliomind-${{ matrix.image }}:ci
cache-from: type=gha,scope=${{ matrix.image }}
cache-to: type=gha,mode=max,scope=${{ matrix.image }}
# The bundle must start in the production image and stop cleanly on
# SIGTERM. Placeholder values only: the worker boots, then retries Inngest.
- name: Worker A boots from its image and stops on SIGTERM
if: matrix.image == 'ingestion'
run: |
docker run -d --name worker-a \
-e APP_ENV=production \
-e DIRECT_DATABASE_URL=postgres://ci:ci@db.invalid/ci \
-e UPSTASH_REDIS_REST_URL=https://redis.invalid \
-e UPSTASH_REDIS_REST_TOKEN=ci \
-e BROWSERLESS_WS_ENDPOINT=wss://browserless.invalid \
-e BROWSERLESS_TOKEN=ci \
-e INNGEST_EVENT_KEY=ci \
-e INNGEST_SIGNING_KEY=signkey-prod-ci \
-e UPLOADTHING_TOKEN=ci \
-e JINA_API_KEY=ci \
-e STRIPE_SECRET_KEY=sk_test_ci \
-e STRIPE_PRO_MONTHLY_PRICE_ID=price_ci \
foliomind-ingestion:ci
timeout 60 sh -c 'until docker logs worker-a 2>&1 | grep -q "\"worker booted\""; do sleep 1; done' \
|| { docker logs worker-a; exit 1; }
docker stop --time 10 worker-a
docker logs worker-a
test "$(docker inspect worker-a --format '{{.State.ExitCode}}')" = "0"
e2e:
name: End-to-end journeys
runs-on: ubuntu-latest
timeout-minutes: 40
# The production build against the Compose stack. Sessions are minted
# locally (apps/web/e2e/auth.ts), so no Auth0 tenant is involved; journeys
# that need provider keys or a connected worker skip with a reason.
env:
CI: "true"
DIRECT_DATABASE_URL: postgres://foliomind:foliomind@localhost:5433/foliomind
DATABASE_URL: postgres://foliomind_app:foliomind_app@localhost:5433/foliomind
UPSTASH_REDIS_REST_URL: http://localhost:8079
UPSTASH_REDIS_REST_TOKEN: foliomind-local-dev-token
RATE_LIMIT_IP_SECRET: ci-e2e-rate-limit-secret-0123456789
INNGEST_DEV: "1"
INNGEST_BASE_URL: http://localhost:8288
NEXT_TELEMETRY_DISABLED: "1"
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Start Postgres, Redis, the Upstash proxy and the Inngest Dev Server
run: docker compose -f infra/compose.yaml up -d --wait postgres redis upstash-http inngest
- name: Migrate, create the runtime role and seed
run: pnpm db:setup
# The catalog journeys expect the sample publisher and books (local databases only).
- name: Seed the development sample catalog
run: pnpm db:seed:dev
- name: Build the web app
run: pnpm --filter web build
- name: Install Chromium
run: pnpm --filter web exec playwright install --with-deps chromium
- name: Run the journeys
run: pnpm e2e
- name: Upload the Playwright report
if: failure()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: playwright-report
path: |
apps/web/playwright-report
apps/web/test-results
retention-days: 7
- name: Service logs
if: failure()
run: docker compose -f infra/compose.yaml logs --tail=100
- name: Stop the stack
if: always()
run: docker compose -f infra/compose.yaml down -v
deploy:
name: Migrate, deploy and smoke-test production
# Off until the repository variable CI_DEPLOY is "true" and the secrets in
# docs/operations/deployment.md exist. Every gate above must pass first.
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && vars.CI_DEPLOY == 'true'
needs: [verify, services, integration, docker, e2e]
runs-on: ubuntu-latest
timeout-minutes: 30
environment:
name: production
url: ${{ vars.PRODUCTION_URL }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
# Section 3: migrations run once, here, with the migration role; never
# from app replicas. Expand/migrate/contract keeps the old code working.
- name: Apply migrations to Neon
env:
DIRECT_DATABASE_URL: ${{ secrets.NEON_DIRECT_DATABASE_URL }}
run: pnpm db:migrate
- name: Build for Vercel production
run: |
pnpm dlx vercel@65.9.0 pull --yes --environment=production --token="$VERCEL_TOKEN"
pnpm dlx vercel@65.9.0 build --prod --token="$VERCEL_TOKEN"
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
- name: Deploy the prebuilt output
id: deploy
run: |
url=$(pnpm dlx vercel@65.9.0 deploy --prebuilt --prod --token="$VERCEL_TOKEN")
echo "url=$url" >> "$GITHUB_OUTPUT"
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
- name: Register the new Inngest functions
run: curl -fsS -X PUT "${{ vars.PRODUCTION_URL }}/api/inngest"
- name: Smoke checks
run: pnpm smoke -- "${{ vars.PRODUCTION_URL }}"