-
Notifications
You must be signed in to change notification settings - Fork 0
396 lines (369 loc) · 17.2 KB
/
Copy pathci.yml
File metadata and controls
396 lines (369 loc) · 17.2 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
name: CI
on:
issue_comment:
types: [created]
jobs:
validate:
# Run when a maintainer comments /test on a PR (manual trigger for external contributors).
# Dependabot PRs: comment /test to run CI, or add a separate ci-dependabot workflow.
if: |
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(github.event.comment.body, '/test') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
statuses: write
services:
postgres:
image: postgres:18.3
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
# Host port 5632: Metaboost test stack (dev Docker uses 5532; default Postgres is often 5432).
ports:
- 5632:5432
options: >-
--health-cmd "pg_isready -U postgres" --health-interval 10s
--health-timeout 5s --health-retries 5
valkey:
image: valkey/valkey:7-alpine
# Host port 6579: Metaboost test Valkey (dev Docker uses 6479; default Redis/Valkey is often 6379).
ports:
- 6579:6379
options: >-
--health-cmd "valkey-cli ping" --health-interval 10s --health-timeout
5s --health-retries 5
env:
DB_HOST: localhost
DB_PORT: 5632
DB_APP_NAME: metaboost_app_test
DB_APP_MIGRATOR_USER: metaboost_app_migrator
DB_APP_MIGRATOR_PASSWORD: test
DB_APP_READ_USER: metaboost_app_read
DB_APP_READ_PASSWORD: test
DB_APP_READ_WRITE_USER: metaboost_app_read_write
DB_APP_READ_WRITE_PASSWORD: test
DB_MANAGEMENT_NAME: metaboost_management_test
DB_MANAGEMENT_MIGRATOR_USER: metaboost_management_migrator
DB_MANAGEMENT_MIGRATOR_PASSWORD: test
DB_MANAGEMENT_READ_USER: metaboost_management_read
DB_MANAGEMENT_READ_PASSWORD: test
DB_MANAGEMENT_READ_WRITE_USER: metaboost_management_read_write
DB_MANAGEMENT_READ_WRITE_PASSWORD: test
KEYVALDB_HOST: localhost
KEYVALDB_PORT: 6579
KEYVALDB_PASSWORD: "test"
API_PORT: "3999"
BRAND_NAME: metaboost-api-test
AUTH_JWT_SECRET: "ci-test-jwt-secret-min-32-chars-long-for-validation"
steps:
- name: Add reaction to comment
if: github.event_name == 'issue_comment'
uses: actions/github-script@v9
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket'
});
- name: Get PR details
id: pr-comment
uses: actions/github-script@v9
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
core.setOutput('head_ref', pr.data.head.ref);
core.setOutput('head_sha', pr.data.head.sha);
core.setOutput('pr_number', context.issue.number);
- uses: actions/checkout@v7
with:
ref: ${{ steps.pr-comment.outputs.head_sha }}
- name: Validate linear migration files
id: db-verify
run: bash scripts/database/validate-linear-migrations.sh
- name: Verify linear baseline 0003
id: db-baseline-0003
run: bash scripts/database/verify-linear-baseline.sh
- name: Validate db init sync
id: db-init-sync
run: make check_k8s_postgres_init_sync
- name: Verify bootstrap init contract in ephemeral Postgres
id: db-bootstrap-contract
run: bash scripts/database/ci-verify-bootstrap-contract.sh
- name: Enforce no runtime CREATE EXTENSION
id: db-runtime-extension-guard
run: bash scripts/database/check-no-runtime-create-extension.sh
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
cache: "npm"
- name: Pin npm version
run: npm install -g npm@11.13.0
- name: Install dependencies
id: install
run: |
set -euo pipefail
for attempt in 1 2 3 4 5; do
if npm ci; then
break
fi
echo "npm ci failed (attempt $attempt/5); retrying in 15s..." >&2
sleep 15
if [[ "$attempt" -eq 5 ]]; then
exit 1
fi
done
- name: Build packages
id: build-packages
run: npm run build:packages
- name: Lint
id: lint
run: npm run lint
- name: Build apps
id: build-apps
run: npm run build:apps
- name: i18n validate
id: i18n-validate
run: npm run i18n:validate
- name: Type-check
id: type-check
run: npm run type-check
- name: Create test database and run init
id: db-init
env:
PGPASSWORD: postgres
PGHOST: localhost
PGPORT: "5632"
PGUSER: postgres
run: |
psql -c "DROP DATABASE IF EXISTS metaboost_app_test;"
psql -c "CREATE DATABASE metaboost_app_test;"
psql -d postgres -c "
DO \$\$
BEGIN
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'metaboost_app_migrator') THEN
CREATE USER metaboost_app_migrator WITH PASSWORD 'test';
ELSE
ALTER USER metaboost_app_migrator WITH PASSWORD 'test';
END IF;
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'metaboost_management_migrator') THEN
CREATE USER metaboost_management_migrator WITH PASSWORD 'test';
ELSE
ALTER USER metaboost_management_migrator WITH PASSWORD 'test';
END IF;
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'metaboost_app_read') THEN
CREATE USER metaboost_app_read WITH PASSWORD 'test';
END IF;
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'metaboost_app_read_write') THEN
CREATE USER metaboost_app_read_write WITH PASSWORD 'test';
END IF;
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'metaboost_management_read') THEN
CREATE USER metaboost_management_read WITH PASSWORD 'test';
END IF;
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'metaboost_management_read_write') THEN
CREATE USER metaboost_management_read_write WITH PASSWORD 'test';
END IF;
END \$\$;
"
psql -d metaboost_app_test -c "ALTER DATABASE metaboost_app_test OWNER TO metaboost_app_migrator;"
psql -d metaboost_app_test -c "GRANT CONNECT ON DATABASE metaboost_app_test TO metaboost_app_migrator, metaboost_app_read, metaboost_app_read_write;"
psql -d metaboost_app_test -c "GRANT USAGE, CREATE ON SCHEMA public TO metaboost_app_migrator;"
DB_HOST=localhost DB_PORT=5632 DB_APP_NAME=metaboost_app_test DB_APP_MIGRATOR_USER=metaboost_app_migrator DB_APP_MIGRATOR_PASSWORD=test \
bash scripts/database/run-linear-migrations.sh --database app
psql -d metaboost_app_test -c "
GRANT CONNECT ON DATABASE metaboost_app_test TO metaboost_app_read, metaboost_app_read_write;
GRANT USAGE ON SCHEMA public TO metaboost_app_read, metaboost_app_read_write;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO metaboost_app_read;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO metaboost_app_read;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO metaboost_app_read_write;
GRANT SELECT, USAGE, UPDATE ON ALL SEQUENCES IN SCHEMA public TO metaboost_app_read_write;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO metaboost_app_read;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON SEQUENCES TO metaboost_app_read;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO metaboost_app_read_write;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, USAGE, UPDATE ON SEQUENCES TO metaboost_app_read_write;
"
psql -c "DROP DATABASE IF EXISTS metaboost_management_test;"
psql -c "CREATE DATABASE metaboost_management_test;"
psql -d metaboost_management_test -c "ALTER DATABASE metaboost_management_test OWNER TO metaboost_management_migrator;"
psql -d metaboost_management_test -c "GRANT CONNECT ON DATABASE metaboost_management_test TO metaboost_management_migrator, metaboost_management_read, metaboost_management_read_write;"
psql -d metaboost_management_test -c "GRANT USAGE, CREATE ON SCHEMA public TO metaboost_management_migrator;"
DB_HOST=localhost DB_PORT=5632 DB_MANAGEMENT_NAME=metaboost_management_test DB_MANAGEMENT_MIGRATOR_USER=metaboost_management_migrator DB_MANAGEMENT_MIGRATOR_PASSWORD=test \
bash scripts/database/run-linear-migrations.sh --database management
psql -d metaboost_management_test -c "
GRANT CONNECT ON DATABASE metaboost_management_test TO metaboost_management_read, metaboost_management_read_write;
GRANT USAGE ON SCHEMA public TO metaboost_management_read, metaboost_management_read_write;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO metaboost_management_read;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO metaboost_management_read;
GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON ALL TABLES IN SCHEMA public TO metaboost_management_read_write;
GRANT SELECT, USAGE, UPDATE ON ALL SEQUENCES IN SCHEMA public TO metaboost_management_read_write;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO metaboost_management_read;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON SEQUENCES TO metaboost_management_read;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON TABLES TO metaboost_management_read_write;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, USAGE, UPDATE ON SEQUENCES TO metaboost_management_read_write;
"
- name: Test (skipped in CI; run locally)
id: test
if: always()
run: |
echo "::warning::Tests are intentionally skipped in GitHub Actions for this workflow."
echo "::warning::Run tests locally before merge: make E2E_API_GATE_MODE=on e2e_test (or make E2E_API_GATE_MODE=on e2e_test_report for reports)"
- name: Report success
if: success()
uses: actions/github-script@v9
env:
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{
github.run_id }}
PR_NUMBER: ${{ steps.pr-comment.outputs.pr_number }}
with:
script: |
const body = [
'## ✅ CI Passed',
'',
'All checks completed successfully.',
'',
'| Check | Status |',
'|-------|--------|',
'| Linear migration files valid | ✅ |',
'| Linear baseline 0003 (vs generator) | ✅ |',
'| DB init sync valid | ✅ |',
'| Bootstrap init contract verified | ✅ |',
'| Runtime CREATE EXTENSION guard | ✅ |',
'| Dependencies installed | ✅ |',
'| Build packages | ✅ |',
'| Lint | ✅ |',
'| Build apps | ✅ |',
'| i18n validate | ✅ |',
'| Type-check | ✅ |',
'| Test | ⏭️ Skipped in CI (run locally) |',
'',
'> Reminder: run `make E2E_API_GATE_MODE=on e2e_test` locally before merging (or `make E2E_API_GATE_MODE=on e2e_test_report` for reports).',
'',
`[View full run](${process.env.RUN_URL})`
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(process.env.PR_NUMBER),
body: body
});
- name: Set success commit status
if: success()
uses: actions/github-script@v9
env:
HEAD_SHA: ${{ steps.pr-comment.outputs.head_sha }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{
github.run_id }}
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: process.env.HEAD_SHA,
state: 'success',
context: 'validate',
description: 'All checks passed',
target_url: process.env.RUN_URL
});
- name: Report failure
if: failure()
uses: actions/github-script@v9
env:
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{
github.run_id }}
PR_NUMBER: ${{ steps.pr-comment.outputs.pr_number }}
DB_VERIFY: ${{ steps.db-verify.outcome }}
DB_BASELINE_0003: ${{ steps.db-baseline-0003.outcome }}
DB_INIT_SYNC: ${{ steps.db-init-sync.outcome }}
DB_BOOTSTRAP_CONTRACT: ${{ steps.db-bootstrap-contract.outcome }}
DB_RUNTIME_EXTENSION_GUARD: ${{ steps.db-runtime-extension-guard.outcome }}
INSTALL: ${{ steps.install.outcome }}
BUILD_PACKAGES: ${{ steps.build-packages.outcome }}
LINT: ${{ steps.lint.outcome }}
BUILD_APPS: ${{ steps.build-apps.outcome }}
I18N_VALIDATE: ${{ steps.i18n-validate.outcome }}
TYPE_CHECK: ${{ steps.type-check.outcome }}
with:
script: |
const status = (outcome) => {
if (outcome === 'success') return '✅';
if (outcome === 'failure') return '❌';
return '⏭️';
};
const baselineFix =
process.env.DB_BASELINE_0003 === 'failure'
? [
'',
'**Linear baseline 0003a/0003b:** Regenerate from the repo root, then commit:',
'```',
'make db_regen_linear_baseline',
'make db_verify_linear_baseline',
'```',
'Or: `bash scripts/database/generate-linear-baseline.sh` then verify as above.',
''
].join('\n')
: '';
const body = [
'## ❌ CI Failed',
'',
'One or more checks failed. Please review and fix the issues.',
'',
'| Check | Status |',
'|-------|--------|',
`| Linear migration files valid | ${status(process.env.DB_VERIFY)} |`,
`| Linear baseline 0003 (vs generator) | ${status(process.env.DB_BASELINE_0003)} |`,
`| DB init sync valid | ${status(process.env.DB_INIT_SYNC)} |`,
`| Bootstrap init contract verified | ${status(process.env.DB_BOOTSTRAP_CONTRACT)} |`,
`| Runtime CREATE EXTENSION guard | ${status(process.env.DB_RUNTIME_EXTENSION_GUARD)} |`,
`| Dependencies installed | ${status(process.env.INSTALL)} |`,
`| Build packages | ${status(process.env.BUILD_PACKAGES)} |`,
`| Lint | ${status(process.env.LINT)} |`,
`| Build apps | ${status(process.env.BUILD_APPS)} |`,
`| i18n validate | ${status(process.env.I18N_VALIDATE)} |`,
`| Type-check | ${status(process.env.TYPE_CHECK)} |`,
'| Test | ⏭️ Skipped in CI (run locally) |',
'',
'Legend: ✅ Passed | ❌ Failed | ⏭️ Skipped',
'',
baselineFix,
'> Reminder: run `make E2E_API_GATE_MODE=on e2e_test` locally before merging (or `make E2E_API_GATE_MODE=on e2e_test_report` for reports).',
'',
`[View full run for details](${process.env.RUN_URL})`
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(process.env.PR_NUMBER),
body: body
});
- name: Set failure commit status
if: failure()
uses: actions/github-script@v9
env:
HEAD_SHA: ${{ steps.pr-comment.outputs.head_sha }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{
github.run_id }}
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: process.env.HEAD_SHA,
state: 'failure',
context: 'validate',
description: 'One or more checks failed',
target_url: process.env.RUN_URL
});