-
Notifications
You must be signed in to change notification settings - Fork 66
292 lines (258 loc) · 10.4 KB
/
Copy pathnode-ci.yml
File metadata and controls
292 lines (258 loc) · 10.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
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
name: Node CI
on:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, reopened]
jobs:
ci:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14.4
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: db
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U user"
--health-interval=10s
--health-timeout=5s
--health-retries=5
env:
NODE_ENV: test
DATABASE_URL: postgresql://user:pass@localhost:5432/db
WALLET_ENCRYPTION_KEY: a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2
# Non-secret stubs required by env.ts at module-load time
STELLAR_NETWORK: testnet
STELLAR_RPC_URL: https://rpc.example.com
STELLAR_AGENT_SECRET_KEY: SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
VAULT_CONTRACT_ID: CDUMMYVAULTCONTRACTID
USDC_TOKEN_ADDRESS: CDUMMYUSDC
ANTHROPIC_API_KEY: sk-ant-smoke-key
JWT_SEED: smoke-jwt-seed-0123456789abcdef0123456789
JWT_SESSION_TTL_HOURS: '24'
JWT_NONCE_TTL_MS: '300000'
JWT_CLEANUP_INTERVAL_MS: '86400000'
TWILIO_AUTH_TOKEN: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
INTERNAL_SERVICE_TOKEN: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
TRUSTED_IPS: 127.0.0.1
CORS_ORIGINS: '*'
HTTP_CLIENT_TIMEOUT_MS: '1000'
steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
# Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
# Install dependencies
- name: Install dependencies
run: npm ci
- name: Prisma generate
run: npx prisma generate
- name: Prisma migrate deploy
run: npx prisma migrate deploy
# Run TypeScript lint check
- name: Run lint
run: npm run lint
- name: Run format check
run: npm run format:check
# Build the project
- name: Build project
run: npm run build
# Run tests
- name: Run tests
run: npm test
# ── Security scanning ─────────────────────────────────────────────────────
# Issue #114: npm audit for known vulnerabilities
# Fails on high or critical CVEs to prevent merging vulnerable dependencies
#
# Policy: Builds fail on HIGH or CRITICAL vulnerabilities
# - HIGH/CRITICAL: Must be fixed before merge (blocking)
# - MODERATE: Review required, fix in follow-up PR (non-blocking via Dependabot)
# - LOW: Tracked via Dependabot, fix during regular maintenance
#
# Dependabot automatically creates PRs for vulnerable dependencies
security-scan:
name: Security audit
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run npm audit (HIGH and CRITICAL only)
run: npm audit --audit-level=high
continue-on-error: false
- name: License check (block GPL/AGPL/LGPL)
# Prevents copyleft licences from entering the dependency tree.
# Allowed: MIT, ISC, Apache-2.0, BSD-2-Clause, BSD-3-Clause, 0BSD, BlueOak-1.0.0, CC0-1.0,
# Python-2.0 (PSF — permissive, transitive argparse@2),
# CC-BY-4.0 (attribution-only, transitive caniuse-lite data),
# Unlicense (public-domain dedication, transitive fast-sha256)
run: |
npx license-checker --onlyAllow \
'MIT;ISC;Apache-2.0;BSD-2-Clause;BSD-3-Clause;0BSD;BlueOak-1.0.0;CC0-1.0;Python-2.0;CC-BY-4.0;Unlicense' \
--excludePrivatePackages
# ── Issue #100: migration smoke gate ──────────────────────────────────────
# Isolated job that re-applies migrations against a clean DB and runs the
# smoke test. Fails the pipeline if either step errors, preventing a broken
# migration from reaching production.
migration-smoke:
name: Migration smoke test
runs-on: ubuntu-latest
needs: ci
services:
postgres:
image: postgres:14.4
env:
POSTGRES_USER: smoke_user
POSTGRES_PASSWORD: smoke_pass
POSTGRES_DB: smoke_db
ports:
- 5433:5432
options: >-
--health-cmd="pg_isready -U smoke_user"
--health-interval=10s
--health-timeout=5s
--health-retries=5
env:
NODE_ENV: test
# scripts/smoke-health.sh probes port 3001 — the server must listen there.
PORT: '3001'
DATABASE_URL: postgresql://smoke_user:smoke_pass@localhost:5433/smoke_db
# Non-secret stubs required by env.ts at module-load time
STELLAR_NETWORK: testnet
# This job boots the real server; startEventListener() calls
# getLatestLedger() with no client timeout before app.listen(), so the
# endpoint must resolve or startup stalls.
STELLAR_RPC_URL: https://soroban-testnet.stellar.org
STELLAR_AGENT_SECRET_KEY: SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
VAULT_CONTRACT_ID: CDUMMYVAULTCONTRACTID
USDC_TOKEN_ADDRESS: CDUMMYUSDC
ANTHROPIC_API_KEY: sk-ant-smoke-key
JWT_SEED: smoke-jwt-seed-0123456789abcdef0123456789
JWT_SESSION_TTL_HOURS: '24'
JWT_NONCE_TTL_MS: '300000'
JWT_CLEANUP_INTERVAL_MS: '86400000'
WALLET_ENCRYPTION_KEY: a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2
# Required by env.ts and asserted again by initServices().
TWILIO_AUTH_TOKEN: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Prisma generate
run: npx prisma generate
# Informational only: on a fresh smoke database every migration is
# pending, and `migrate status` exits non-zero whenever that is true.
# The real gate is "Confirm no pending migrations after deploy" below.
- name: Check migration status (pre-deploy, informational)
run: npx prisma migrate status || true
- name: Apply migrations to smoke DB
run: npx prisma migrate deploy
- name: Confirm no pending migrations after deploy
run: |
npx prisma migrate status | tee /tmp/migrate-status.txt
if grep -q "following migration have not yet been applied" /tmp/migrate-status.txt; then
echo "::error::Pending migrations remain after migrate deploy"
exit 1
fi
# smoke-health.sh runs the compiled server, so the artifact must exist.
- name: Build project
run: npm run build
- name: Run smoke test
run: npm run smoke
# ── Issue #195: Docs and deployment manifests validation ───────────────────
# Validates Markdown links, code fences, and Kubernetes manifests to catch
# broken examples, stale commands, and malformed manifests before they reach operators.
docs-validation:
name: Docs and manifests validation
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install markdown-link-check
run: npm install -g markdown-link-check
- name: Check Markdown links in docs
run: |
# Check internal links only (ignore external links that may be flaky)
for file in docs/*.md; do
if [ -f "$file" ]; then
echo "Checking links in $file"
markdown-link-check --config .markdown-link-check.json "$file" || {
echo "::error file=$file::Markdown link check failed"
exit 1
}
fi
done
- name: Validate code fences in docs
run: |
# Check for unclosed code fences in markdown files
for file in docs/*.md; do
if [ -f "$file" ]; then
# Count opening and closing code fences
open=$(grep -c '^```' "$file" || true)
if [ $((open % 2)) -ne 0 ]; then
echo "::error file=$file::Unclosed code fence detected"
exit 1
fi
fi
done
# Kubernetes manifest validation lives in k8s-validate.yml (kubeconform,
# fully offline) and triggers whenever deploy/k8s changes. kubectl's
# client dry-run needs a live cluster for API discovery, so it can never
# pass on a bare runner and was removed from this job.
- name: Check referenced file paths in docs
run: |
# Extract file paths from markdown code blocks and check if they exist
for file in docs/*.md; do
if [ -f "$file" ]; then
# Extract paths like `src/config/env.ts` or `docs/OBSERVABILITY.md`
grep -oE '\`[a-zA-Z0-9_./-]+\.[a-z]+\`' "$file" | sed 's/`//g' | while read path; do
if [ -n "$path" ] && [ ! -f "$path" ] && [ ! -d "$path" ]; then
# Only warn for likely file references (contains .)
if [[ "$path" == *.* ]]; then
echo "::warning file=$file::Referenced file may not exist: $path"
fi
fi
done
fi
done
- name: Check command examples in docs
run: |
# Check for common command patterns that might be outdated
for file in docs/*.md; do
if [ -f "$file" ]; then
# Check for npm scripts that don't exist in package.json
grep -oE 'npm (run|test) [a-z0-9_-]+' "$file" | while read cmd; do
script=$(echo "$cmd" | awk '{print $NF}')
if ! grep -q "\"$script\"" package.json; then
echo "::warning file=$file::npm script may not exist: $script"
fi
done
fi
done