-
Notifications
You must be signed in to change notification settings - Fork 59
279 lines (241 loc) · 9 KB
/
Copy pathci.yml
File metadata and controls
279 lines (241 loc) · 9 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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
# Cancel in-progress runs for the same branch/PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
secrets-scan:
name: Secrets Scanning (Gitleaks)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Gitleaks Scan
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
vulnerability-scan:
name: Dependency Vulnerability Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm audit --audit-level=high
license-scan:
name: Dependency License Compliance
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
# Permissive-only allow-list, reconciled with the project's own
# MIT/Apache-2.0 license (issue #107). Fails the build on any
# dependency (direct or transitive) carrying a copyleft or
# unrecognized/unlicensed license.
- name: Check dependency licenses
run: |
npx license-checker --production \
--onlyAllow 'MIT;Apache-2.0;BSD-2-Clause;BSD-3-Clause;ISC;0BSD;CC0-1.0;Unlicense' \
--excludePrivatePackages
commitlint:
name: Commit Message Lint
runs-on: ubuntu-latest
# Only meaningful on PRs — on direct pushes to main we skip this check
# since squash merges are handled by the branch protection rule.
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with:
# Fetch enough history to validate all commits in the PR.
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
# Lint every commit in the PR from the merge base to HEAD.
- name: Lint commit messages
run: |
npx commitlint \
--from ${{ github.event.pull_request.base.sha }} \
--to ${{ github.event.pull_request.head.sha }} \
--verbose
backend:
name: Backend (Nest) – Node ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20, 22]
# Spin up a PostgreSQL service container so Prisma can connect during the
# migrate step (migrate deploy requires a live DB).
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: vortex
POSTGRES_PASSWORD: vortex
POSTGRES_DB: vortex
ports:
- 5432:5432
# Wait until postgres is healthy before the steps run.
options: >-
--health-cmd="pg_isready -U vortex"
--health-interval=10s
--health-timeout=5s
--health-retries=5
env:
DATABASE_URL: postgresql://vortex:vortex@localhost:5432/vortex?schema=public
steps:
- uses: actions/checkout@v4
# ── Node / npm cache (#130) ──────────────────────────────────────────
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Install dependencies
run: npm ci
# ── Env drift check ────────────────────────────────────────────────────
# Fast, early-failing check that env.validation.ts, .env*.example, and
# configuration.ts's process.env reads all agree on the same variable set.
- name: Check env var drift
run: npx tsx scripts/check-env-drift.ts
# ── Prisma ──────────────────────────────────────────────────────────────
- name: Validate Prisma schema
run: npm run db:validate
- name: Generate Prisma client
run: npm run db:generate
# Apply all pending migrations to the CI database so the schema stays in
# sync and any broken migration SQL is caught before merge.
- name: Run database migrations
run: npm run db:migrate:prod
# ── Build & test ────────────────────────────────────────────────────────
- name: Lint
run: npm run lint
- name: Type-check
run: npm run typecheck
- name: Build
run: npm run build
- name: Unit tests
run: npm test
- name: E2E tests
run: npm run test:e2e
# ── Migration rollback verification ────────────────────────────────────────
# For every prisma/migrations/*/down.sql, applies migration.sql then
# down.sql against a fresh Postgres and asserts the schema returns to its
# pre-migration (empty) state. See prisma/migrations/README.md.
migration-rollback:
name: Migration rollback verification
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: vortex
POSTGRES_PASSWORD: vortex
POSTGRES_DB: vortex_rollback_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
PGHOST: localhost
PGPORT: 5432
PGUSER: vortex
PGPASSWORD: vortex
PGDATABASE: vortex_rollback_test
steps:
- uses: actions/checkout@v4
- name: Apply each migration's up then down script and verify schema is restored
run: |
set -euo pipefail
for dir in prisma/migrations/*/; do
name=$(basename "$dir")
up="$dir/migration.sql"
down="$dir/down.sql"
[ -f "$down" ] || continue
echo "::group::$name"
before=$(psql -Atc "select tablename from pg_tables where schemaname='public' order by 1")
psql -v ON_ERROR_STOP=1 -f "$up"
psql -v ON_ERROR_STOP=1 -f "$down"
after=$(psql -Atc "select tablename from pg_tables where schemaname='public' order by 1")
if [ "$before" != "$after" ]; then
echo "Schema after down.sql does not match pre-migration state for $name"
echo "before: $before"
echo "after: $after"
exit 1
fi
echo "::endgroup::"
done
# ── Docker build verification (#131) ──────────────────────────────────────
# Ensures every push that changes application code doesn't silently break
# the Dockerfile. Image publishing to a registry can be wired up separately
# once registry credentials are in place.
docker:
name: Docker – build verification
runs-on: ubuntu-latest
needs: backend
steps:
- uses: actions/checkout@v4
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: vortex-backend:ci
sdk-publish:
name: Publish generated SDK
runs-on: ubuntu-latest
needs: [backend, docker]
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm ci
- name: Regenerate client SDK
run: npm run generate:client
- name: Verify packaged SDK installs cleanly
run: |
tmpdir=$(mktemp -d)
cd "$tmpdir"
npm init -y
npm install --silent "$GITHUB_WORKSPACE/src/generated"
npm install --silent typescript @types/node
cat <<'TS' > index.ts
import type { paths, components } from '@vortex-protocol/backend-sdk';
type IntentList = paths['/api/v1/intents']['get'];
type Intent = components['schemas']['Intent'];
const fallback: Intent | undefined = undefined;
void fallback;
void IntentList;
TS
npx tsc --noEmit --moduleResolution node --module commonjs --target es2020 index.ts
- name: Publish SDK to npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
version="${GITHUB_REF_NAME#v}"
npm --prefix src/generated version "$version" --no-git-tag-version
npm --prefix src/generated publish --access public