-
Notifications
You must be signed in to change notification settings - Fork 31
414 lines (367 loc) · 14.5 KB
/
Copy pathbuild.yml
File metadata and controls
414 lines (367 loc) · 14.5 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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
name: Build
on:
pull_request:
branches: [main]
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.10"
- name: Restore node_modules cache
id: cache-deps
uses: actions/cache/restore@v5
with:
path: ./node_modules
key: bun-deps-linux-x64-${{ hashFiles('bun.lock') }}
- name: Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: bun install
- name: Save node_modules cache
if: steps.cache-deps.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: ./node_modules
key: bun-deps-linux-x64-${{ hashFiles('bun.lock') }}
- name: Generate build files
run: bun scripts/generate-build-info.ts && bun scripts/generate-changelog.ts
- name: Type check
run: bun run lint
test_shards:
name: test (${{ matrix.shard }}/${{ strategy.job-total }})
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5]
steps:
- uses: actions/checkout@v5
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.10"
- name: Restore node_modules cache
id: cache-deps
uses: actions/cache/restore@v5
with:
path: ./node_modules
key: bun-deps-linux-x64-${{ hashFiles('bun.lock') }}
- name: Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: bun install
- name: Save node_modules cache
if: steps.cache-deps.outputs.cache-hit != 'true' && matrix.shard == 1
uses: actions/cache/save@v5
with:
path: ./node_modules
key: bun-deps-linux-x64-${{ hashFiles('bun.lock') }}
- name: Generate build files
run: bun scripts/generate-build-info.ts && bun scripts/generate-changelog.ts
# Each suite is teed to a per-suite log so the aggregate `test` job can
# surface the exact failing tests without anyone opening this shard job.
#
# `shell: bash` is MANDATORY on every step that pipes: the default `run:`
# shell is `bash -e {0}` WITHOUT pipefail, so `vitest | tee` reports tee's
# exit code (0) and a genuinely failing suite gets recorded as success —
# which silently turned this gate into a rubber stamp once already.
# `shell: bash` runs `bash --noprofile --norc -eo pipefail {0}`.
- name: Run mainview tests
id: mainview_tests
continue-on-error: true
shell: bash
run: |
mkdir -p test-shard-result
bunx vitest run --shard=${{ matrix.shard }}/${{ strategy.job-total }} \
2>&1 | tee "test-shard-result/shard-${{ matrix.shard }}-mainview.log"
- name: Run bun tests
id: bun_tests
continue-on-error: true
shell: bash
run: |
mkdir -p test-shard-result
bunx vitest run --config vitest.config.bun.ts --shard=${{ matrix.shard }}/${{ strategy.job-total }} \
2>&1 | tee "test-shard-result/shard-${{ matrix.shard }}-bun.log"
- name: Run CLI tests
id: cli_tests
continue-on-error: true
shell: bash
run: |
mkdir -p test-shard-result
bunx vitest run --config vitest.config.cli.ts --shard=${{ matrix.shard }}/${{ strategy.job-total }} \
2>&1 | tee "test-shard-result/shard-${{ matrix.shard }}-cli.log"
- name: Record shard result
if: always()
env:
SHARD: ${{ matrix.shard }}
SHARD_TOTAL: ${{ strategy.job-total }}
MAINVIEW_RESULT: ${{ steps.mainview_tests.outcome }}
BUN_RESULT: ${{ steps.bun_tests.outcome }}
CLI_RESULT: ${{ steps.cli_tests.outcome }}
run: |
mkdir -p test-shard-result
printf '%s %s %s %s %s\n' "$SHARD" "$SHARD_TOTAL" "$MAINVIEW_RESULT" "$BUN_RESULT" "$CLI_RESULT" \
> "test-shard-result/shard-$SHARD.txt"
# For each failed suite, distil a concise failure summary the aggregate
# can print verbatim; drop the bulky raw logs so the artifact stays tiny.
strip_ansi() { sed -E 's/\x1b\[[0-9;]*m//g'; }
for suite in mainview bun cli; do
case "$suite" in
mainview) outcome="$MAINVIEW_RESULT" ;;
bun) outcome="$BUN_RESULT" ;;
cli) outcome="$CLI_RESULT" ;;
esac
log="test-shard-result/shard-$SHARD-$suite.log"
fail="test-shard-result/shard-$SHARD-$suite.fail"
if [ "$outcome" != "success" ] && [ -f "$log" ]; then
strip_ansi < "$log" \
| grep -E ' FAIL |Test Files +[0-9]+ failed|Tests +[0-9]+ failed| × ' \
| head -80 > "$fail" || true
if [ ! -s "$fail" ]; then
strip_ansi < "$log" | tail -80 > "$fail" || true
fi
fi
rm -f "$log"
done
- name: Upload shard result
if: always()
uses: actions/upload-artifact@v7
with:
name: test-shard-${{ matrix.shard }}
path: test-shard-result/
if-no-files-found: error
retention-days: 1
test:
name: test
if: always()
needs: test_shards
runs-on: ubuntu-latest
steps:
- name: Download shard results
uses: actions/download-artifact@v8
with:
pattern: test-shard-*
path: test-shard-results
merge-multiple: true
- name: Verify test shards
run: |
shopt -s nullglob
result_files=(test-shard-results/shard-*.txt)
failed=0
expected_total=0
declare -A seen=()
failed_suites=() # "shard/total suite" for every non-success suite
if [ "${#result_files[@]}" -eq 0 ]; then
echo "::error::No test shard results were downloaded"
exit 1
fi
for result_file in "${result_files[@]}"; do
if ! read -r shard total mainview bun cli < "$result_file"; then
echo "::error::Malformed result in $result_file"
failed=1
continue
fi
if [[ ! "$shard" =~ ^[1-9][0-9]*$ ]] || [[ ! "$total" =~ ^[1-9][0-9]*$ ]]; then
echo "::error::Invalid shard identity in $result_file: shard=$shard total=$total"
failed=1
continue
fi
if [ "$result_file" != "test-shard-results/shard-$shard.txt" ]; then
echo "::error::Shard identity does not match artifact filename: $result_file declares $shard"
failed=1
continue
fi
if [ "$expected_total" -eq 0 ]; then
expected_total="$total"
elif [ "$total" -ne "$expected_total" ]; then
echo "::error::Inconsistent shard total in $result_file: expected=$expected_total actual=$total"
failed=1
fi
if [ "$shard" -gt "$total" ] || [[ -n "${seen[$shard]:-}" ]]; then
echo "::error::Invalid or duplicate test shard $shard/$total"
failed=1
continue
fi
seen[$shard]=1
echo "shard $shard/$total: mainview=$mainview bun=$bun cli=$cli"
for suite in mainview bun cli; do
case "$suite" in
mainview) outcome="$mainview" ;;
bun) outcome="$bun" ;;
cli) outcome="$cli" ;;
esac
if [ "$outcome" != "success" ]; then
failed=1
failed_suites+=("$shard/$total $suite")
fi
done
done
if [ "$expected_total" -eq 0 ] || [ "${#result_files[@]}" -ne "$expected_total" ]; then
echo "::error::Expected $expected_total shard results, found ${#result_files[@]}"
failed=1
else
for ((shard = 1; shard <= expected_total; shard++)); do
if [[ -z "${seen[$shard]:-}" ]]; then
echo "::error::Missing result for test shard $shard/$expected_total"
failed=1
fi
done
fi
# Self-contained failure report: which shard, which suite, which tests —
# visible right here and on the run summary, no need to open a shard job.
if [ "${#failed_suites[@]}" -gt 0 ]; then
echo ""
echo "=================================================================="
echo " ❌ TEST SHARDS FAILED (${#failed_suites[@]} suite(s)):"
for entry in "${failed_suites[@]}"; do
echo " ✗ shard ${entry%% *} · ${entry##* }"
done
echo "=================================================================="
echo ""
echo " This job only reads the shard artifacts — it never runs a test."
echo " Re-running ONLY this job re-reads the same artifacts and fails"
echo " identically. Re-run the whole workflow instead:"
echo " gh run rerun $GITHUB_RUN_ID # all jobs"
echo " gh run rerun $GITHUB_RUN_ID --failed # failed jobs (incl. shards)"
echo ""
{
echo "## ❌ Failing test suites"
echo ""
for entry in "${failed_suites[@]}"; do
echo "- **shard ${entry%% *}** · \`${entry##* }\`"
done
echo ""
echo "> ⚠️ **Re-running the \`test\` job alone will not help.** It only reads the"
echo "> shard artifacts; re-run the whole workflow with"
echo "> \`gh run rerun $GITHUB_RUN_ID\` (or **Re-run all jobs**) so the shards"
echo "> actually execute again."
echo ""
} >> "$GITHUB_STEP_SUMMARY"
for entry in "${failed_suites[@]}"; do
shard_total="${entry%% *}"
suite="${entry##* }"
shard="${shard_total%%/*}"
fail="test-shard-results/shard-${shard}-${suite}.fail"
echo ""
echo "::group::❌ shard ${shard_total} · ${suite} — failing tests"
if [ -s "$fail" ]; then
cat "$fail"
else
echo "(no captured failure detail — inspect the shard job log)"
fi
echo "::endgroup::"
first_fail="$(grep -E ' FAIL | × ' "$fail" 2>/dev/null | head -1 | sed -E 's/^[[:space:]]*//')"
echo "::error title=Test shard ${shard_total} (${suite})::${first_fail:-suite ${suite} failed — see the failing-tests group above}"
{
echo "<details><summary>shard ${shard_total} · <code>${suite}</code></summary>"
echo ""
echo '```'
if [ -s "$fail" ]; then cat "$fail"; else echo "(no captured detail)"; fi
echo '```'
echo ""
echo "</details>"
echo ""
} >> "$GITHUB_STEP_SUMMARY"
done
fi
exit "$failed"
build-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.10"
- name: Restore node_modules cache
id: cache-deps
uses: actions/cache/restore@v5
with:
path: ./node_modules
key: bun-deps-linux-x64-${{ hashFiles('bun.lock') }}
- name: Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: bun install
- name: Save node_modules cache
if: steps.cache-deps.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: ./node_modules
key: bun-deps-linux-x64-${{ hashFiles('bun.lock') }}
- name: Generate build files
run: bun scripts/generate-build-info.ts && bun scripts/generate-changelog.ts
- name: Build check
run: bunx vite build && bun run build:cli
trivy-scan:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v5
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'table'
output: 'trivy-results.txt'
exit-code: '0'
severity: 'CRITICAL,HIGH,MEDIUM'
trivy-config: ''
env:
TRIVY_INCLUDE_DEV_DEPS: 'true'
continue-on-error: true
- name: Post Trivy results to PR
if: always()
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const { buildTrivyCommentBody } = require('./src/bun/trivy-pr-comment.js');
let body = null;
if (fs.existsSync('trivy-results.txt')) {
const results = fs.readFileSync('trivy-results.txt', 'utf8');
body = buildTrivyCommentBody(results);
} else {
body = '## 🔍 Trivy Vulnerability Scan\n\n⚠️ Trivy results file not found.\n';
}
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const trivyComment = comments.find((comment) =>
comment.body.includes('Trivy Vulnerability Scan'),
);
if (!body) {
if (trivyComment) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: trivyComment.id,
});
}
return;
}
if (trivyComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: trivyComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
continue-on-error: true