-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcloudbuild-test.yaml
More file actions
189 lines (175 loc) · 5.96 KB
/
cloudbuild-test.yaml
File metadata and controls
189 lines (175 loc) · 5.96 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
# Crypto Vision — Cloud Build Test Pipeline
#
# Runs all quality checks: typecheck, lint, unit tests, integration tests,
# and optional smoke load test. Uploads test results to GCS.
#
# Trigger: Pull request to main, or manual
# Usage: gcloud builds submit --config cloudbuild-test.yaml .
#
# Substitutions:
# _BUCKET — GCS bucket for test results (default: crypto-vision-test-results)
# _RUN_LOAD_TEST — whether to run k6 smoke test (default: "false")
substitutions:
_BUCKET: crypto-vision-test-results
_RUN_LOAD_TEST: "false"
steps:
# ── 1. Install dependencies ────────────────────────────────
- name: node:22-alpine
id: install
entrypoint: npm
args: ["ci"]
# ── 2. Parallel quality checks ─────────────────────────────
- name: node:22-alpine
id: typecheck
entrypoint: npx
args: ["tsc", "--noEmit"]
waitFor: ["install"]
- name: node:22-alpine
id: lint
entrypoint: npm
args: ["run", "lint"]
waitFor: ["install"]
# ── 3. Unit tests with coverage ────────────────────────────
- name: node:22-alpine
id: unit-tests
entrypoint: npx
args:
- vitest
- run
- --reporter=default
- --reporter=junit
- --outputFile=/workspace/test-results/unit.xml
- --coverage
- --coverage.reporter=json-summary
- --coverage.reportsDirectory=/workspace/test-results/coverage
env:
- "NODE_ENV=test"
- "LOG_LEVEL=error"
waitFor: ["install"]
# ── 4. Build (needed for integration tests) ────────────────
- name: node:22-alpine
id: build
entrypoint: npm
args: ["run", "build"]
waitFor: ["install"]
# ── 5. Integration tests ───────────────────────────────────
- name: node:22-alpine
id: integration-tests
entrypoint: bash
args:
- -c
- |
set -e
# Start server in background on random port
export PORT=0
node dist/src/index.js &
SERVER_PID=$!
# Wait for server to be ready
sleep 8
# Run integration tests
npx vitest run tests/integration/ \
--reporter=default \
--reporter=junit \
--outputFile=/workspace/test-results/integration.xml \
|| true
# Clean up
kill $SERVER_PID 2>/dev/null || true
env:
- "NODE_ENV=test"
- "LOG_LEVEL=error"
waitFor: ["build"]
# ── 6. Fuzz tests ──────────────────────────────────────────
- name: node:22-alpine
id: fuzz-tests
entrypoint: bash
args:
- -c
- |
set -e
export PORT=0
node dist/src/index.js &
SERVER_PID=$!
sleep 8
npx vitest run tests/fuzz/ \
--reporter=default \
--reporter=junit \
--outputFile=/workspace/test-results/fuzz.xml \
|| true
kill $SERVER_PID 2>/dev/null || true
env:
- "NODE_ENV=test"
- "LOG_LEVEL=error"
waitFor: ["build"]
# ── 7. Benchmarks ──────────────────────────────────────────
- name: node:22-alpine
id: benchmarks
entrypoint: npx
args:
- vitest
- bench
- --reporter=default
- --outputFile=/workspace/test-results/benchmarks.json
env:
- "NODE_ENV=test"
waitFor: ["install"]
# ── 8. k6 smoke load test (optional) ───────────────────────
- name: grafana/k6:latest
id: load-smoke
entrypoint: sh
args:
- -c
- |
if [ "${_RUN_LOAD_TEST}" = "true" ]; then
k6 run \
--env BASE_URL=http://localhost:8080 \
--out json=/workspace/test-results/k6-smoke.json \
/workspace/tests/load/smoke.js
else
echo "Load test skipped (_RUN_LOAD_TEST != true)"
fi
waitFor: ["integration-tests"]
# ── 9. Upload test results to GCS ──────────────────────────
- name: gcr.io/cloud-builders/gsutil
id: upload-results
args:
- -m
- cp
- -r
- /workspace/test-results/
- "gs://${_BUCKET}/test-results/${SHORT_SHA}/"
waitFor:
- unit-tests
- integration-tests
- fuzz-tests
- benchmarks
# ── 10. Print summary ──────────────────────────────────────
- name: node:22-alpine
id: summary
entrypoint: bash
args:
- -c
- |
echo "═══════════════════════════════════════"
echo " Test Pipeline Complete"
echo "═══════════════════════════════════════"
echo ""
echo " Commit: ${SHORT_SHA}"
echo " Results: gs://${_BUCKET}/test-results/${SHORT_SHA}/"
echo ""
if [ -f /workspace/test-results/coverage/coverage-summary.json ]; then
echo " Coverage:"
cat /workspace/test-results/coverage/coverage-summary.json | \
node -e "const d=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).total; \
console.log(' Statements: '+d.statements.pct+'%'); \
console.log(' Branches: '+d.branches.pct+'%'); \
console.log(' Functions: '+d.functions.pct+'%'); \
console.log(' Lines: '+d.lines.pct+'%');"
fi
waitFor:
- unit-tests
- integration-tests
- fuzz-tests
timeout: 1800s
options:
machineType: E2_HIGHCPU_8
logging: CLOUD_LOGGING_ONLY