-
Notifications
You must be signed in to change notification settings - Fork 9
1112 lines (1047 loc) · 42.7 KB
/
Copy pathci.yml
File metadata and controls
1112 lines (1047 loc) · 42.7 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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# MDK private monorepo (mdk-prv): backend/core/*, backend/workers/**, ui (all npm).
# Aligned with MiningOS CI Checks: per-package lockfile check, node cache actions, parallel jobs, PR audits.
name: CI Checks
on:
push:
branches: [main, develop, staging, "release/**"]
pull_request:
branches: [main, develop, staging, "release/**"]
types: [opened, reopened, synchronize]
workflow_dispatch:
inputs:
target:
description: "Which pipeline to run"
required: true
default: auto
type: choice
options:
- auto
- ui
- core
- workers
- examples
- all
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: "lts/*"
UI_DIR: ui
jobs:
detect-target:
name: Detect changed areas
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
run_ui: ${{ steps.flags.outputs.run_ui }}
run_core: ${{ steps.flags.outputs.run_core }}
run_workers: ${{ steps.flags.outputs.run_workers }}
run_examples: ${{ steps.flags.outputs.run_examples }}
reason: ${{ steps.flags.outputs.reason }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
persist-credentials: false
- name: Detect changed paths
id: changed
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
HEAD_SHA: ${{ github.sha }}
run: |
ui=false; core=false; workers=false; examples=false; docs_only=false
if [ "$EVENT_NAME" != "workflow_dispatch" ]; then
if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
git fetch origin main --depth=1 2>/dev/null || true
BASE_SHA=$(git merge-base HEAD origin/main 2>/dev/null || echo "")
fi
[ -n "$BASE_SHA" ] && CHANGED=$(git diff --name-only "${BASE_SHA}...${HEAD_SHA}") || CHANGED=""
echo "$CHANGED" | grep -q "^ui/" && ui=true || true
echo "$CHANGED" | grep -q "^backend/core/" && core=true || true
echo "$CHANGED" | grep -q "^backend/workers/" && workers=true || true
echo "$CHANGED" | grep -q "^examples/" && examples=true || true
# docs/meta-only: every changed file is docs or repo-meta with no build/runtime
# impact. Markdown link correctness is covered separately by link-check.yml, so
# these changes need none of the domain build/test suites. Anything NOT on this
# allowlist (root package.json, ci.yml, .gitignore, composite actions, source...)
# falls through to the conservative run-all below.
if [ -n "$CHANGED" ]; then
NON_DOCS=$(printf '%s\n' "$CHANGED" | grep -vE '(^docs/|\.md$|^LICENSE$|^linkinator\.config\.json$)' || true)
[ -z "$NON_DOCS" ] && docs_only=true
fi
fi
echo "ui=$ui" >> "$GITHUB_OUTPUT"
echo "core=$core" >> "$GITHUB_OUTPUT"
echo "workers=$workers" >> "$GITHUB_OUTPUT"
echo "examples=$examples" >> "$GITHUB_OUTPUT"
echo "docs_only=$docs_only" >> "$GITHUB_OUTPUT"
- name: Resolve which pipelines should run
id: flags
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_TARGET: ${{ github.event_name == 'workflow_dispatch' && inputs.target || 'auto' }}
UI_CHANGED: ${{ steps.changed.outputs.ui }}
CORE_CHANGED: ${{ steps.changed.outputs.core }}
WORKERS_CHANGED: ${{ steps.changed.outputs.workers }}
EXAMPLES_CHANGED: ${{ steps.changed.outputs.examples }}
DOCS_ONLY: ${{ steps.changed.outputs.docs_only }}
run: |
run_ui=false
run_core=false
run_workers=false
run_examples=false
reason=""
has_ui_lock=false
[ -f "${{ env.UI_DIR }}/package-lock.json" ] && has_ui_lock=true
if [ "$EVENT_NAME" = "workflow_dispatch" ] && [ "$INPUT_TARGET" != "auto" ]; then
case "$INPUT_TARGET" in
ui) run_ui=true; run_core=false; run_workers=false; run_examples=false; reason="manual=ui" ;;
core) run_ui=false; run_core=true; run_workers=false; run_examples=false; reason="manual=core" ;;
workers) run_ui=false; run_core=false; run_workers=true; run_examples=false; reason="manual=workers" ;;
examples) run_ui=false; run_core=false; run_workers=false; run_examples=true; reason="manual=examples" ;;
all) run_ui=true; run_core=true; run_workers=true; run_examples=true; reason="manual=all" ;;
*) run_ui=true; run_core=true; run_workers=true; run_examples=true; reason="manual=unknown-fallback-all" ;;
esac
else
if [ "$UI_CHANGED" = "true" ] && [ "$has_ui_lock" = "true" ]; then run_ui=true; fi
if [ "$CORE_CHANGED" = "true" ]; then run_core=true; fi
if [ "$WORKERS_CHANGED" = "true" ]; then run_workers=true; fi
if [ "$EXAMPLES_CHANGED" = "true" ]; then run_examples=true; fi
if [ "$run_ui" = "false" ] && [ "$run_core" = "false" ] && [ "$run_workers" = "false" ] && [ "$run_examples" = "false" ]; then
if [ "$DOCS_ONLY" = "true" ]; then
# docs/meta-only change: nothing to build or test here (link-check.yml
# handles markdown links in its own workflow). Skip all domain suites.
reason="auto=docs/meta-only->skip-domains"
else
# No domain matched but the change touches shared/root files that can
# affect any domain (root package.json, ci.yml, .gitignore, ...): run all.
run_ui=$([ "$has_ui_lock" = "true" ] && echo true || echo false)
run_core=true
run_workers=true
run_examples=true
reason="auto=no-targeted-change->run-all"
fi
else
reason="auto=changed-paths"
fi
fi
echo "run_ui=$run_ui" >> "$GITHUB_OUTPUT"
echo "run_core=$run_core" >> "$GITHUB_OUTPUT"
echo "run_workers=$run_workers" >> "$GITHUB_OUTPUT"
echo "run_examples=$run_examples" >> "$GITHUB_OUTPUT"
echo "reason=$reason" >> "$GITHUB_OUTPUT"
echo "Selected: ui=$run_ui core=$run_core workers=$run_workers examples=$run_examples ($reason)"
list-workers:
name: List worker packages
runs-on: ubuntu-latest
needs: [detect-target]
if: needs.detect-target.outputs.run_workers == 'true'
outputs:
dirs: ${{ steps.list.outputs.dirs }}
buildable_dirs: ${{ steps.list.outputs.buildable_dirs }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Discover worker package directories
id: list
shell: bash
run: |
set -euo pipefail
mapfile -t dirs < <(
find backend/workers -name package.json -not -path '*/node_modules/*' \
| xargs -I{} dirname {} | sort -u
)
if [ "${#dirs[@]}" -eq 0 ]; then
echo "::error::No package.json under backend/workers/"
exit 1
fi
json=$(printf '%s\n' "${dirs[@]}" | jq -R . | jq -s -c .)
echo "dirs=${json}" >> "$GITHUB_OUTPUT"
echo "Worker packages: ${json}"
buildable=()
for dir in "${dirs[@]}"; do
node -e "const s=require('./${dir}/package.json').scripts||{}; process.exit(s.build?0:1)" 2>/dev/null \
&& buildable+=("$dir") || true
done
if [ "${#buildable[@]}" -gt 0 ]; then
buildable_json=$(printf '%s\n' "${buildable[@]}" | jq -R . | jq -s -c .)
else
buildable_json='[]'
fi
echo "buildable_dirs=${buildable_json}" >> "$GITHUB_OUTPUT"
echo "Buildable worker packages: ${buildable_json}"
list-core:
name: List core packages
runs-on: ubuntu-latest
needs: [detect-target]
if: needs.detect-target.outputs.run_core == 'true'
outputs:
dirs: ${{ steps.list.outputs.dirs }}
buildable_dirs: ${{ steps.list.outputs.buildable_dirs }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Discover core package directories
id: list
shell: bash
run: |
set -euo pipefail
mapfile -t dirs < <(
find backend/core -name package.json -not -path '*/node_modules/*' \
| xargs -I{} dirname {} | sort -u
)
if [ "${#dirs[@]}" -eq 0 ]; then
echo "::error::No package.json under backend/core/"
exit 1
fi
json=$(printf '%s\n' "${dirs[@]}" | jq -R . | jq -s -c .)
echo "dirs=${json}" >> "$GITHUB_OUTPUT"
echo "Core packages: ${json}"
buildable=()
for dir in "${dirs[@]}"; do
node -e "const s=require('./${dir}/package.json').scripts||{}; process.exit(s.build?0:1)" 2>/dev/null \
&& buildable+=("$dir") || true
done
if [ "${#buildable[@]}" -gt 0 ]; then
buildable_json=$(printf '%s\n' "${buildable[@]}" | jq -R . | jq -s -c .)
else
buildable_json='[]'
fi
echo "buildable_dirs=${buildable_json}" >> "$GITHUB_OUTPUT"
echo "Buildable core packages: ${buildable_json}"
list-examples:
name: List example packages
runs-on: ubuntu-latest
needs: [detect-target]
if: needs.detect-target.outputs.run_examples == 'true'
outputs:
dirs: ${{ steps.list.outputs.dirs }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Discover example package directories
id: list
shell: bash
run: |
set -euo pipefail
mapfile -t dirs < <(
find examples -name package.json -not -path '*/node_modules/*' \
| xargs -I{} dirname {} | sort -u
)
if [ "${#dirs[@]}" -eq 0 ]; then
echo "::error::No package.json under examples/"
exit 1
fi
json=$(printf '%s\n' "${dirs[@]}" | jq -R . | jq -s -c .)
echo "dirs=${json}" >> "$GITHUB_OUTPUT"
echo "Example packages: ${json}"
setup-examples:
name: 📦 Setup Example (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, list-examples]
if: needs.detect-target.outputs.run_examples == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-examples.outputs.dirs) }}
outputs:
cache-key: ${{ steps.setup-deps.outputs.cache-key }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Install dependencies and cache node_modules
id: setup-deps
uses: ./.github/actions/node-setup-cache
with:
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
test-examples:
name: 🧪 Test Example (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [detect-target, list-examples, setup-examples]
if: needs.detect-target.outputs.run_examples == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-examples.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-examples.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- run: npm run test:coverage --if-present || npm test --if-present
setup-ui:
name: 📦 Setup UI (ui)
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target]
if: needs.detect-target.outputs.run_ui == 'true'
outputs:
cache-key: ${{ steps.setup-deps.outputs.cache-key }}
lockfile-outcome: ${{ steps.lockfile.outcome }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ env.NODE_VERSION }}
- name: Lockfile consistency check
id: lockfile
shell: bash
working-directory: ${{ env.UI_DIR }}
run: |
set -euo pipefail
if [ ! -f package-lock.json ]; then
echo "No package-lock.json; skipping lockfile check"
exit 0
fi
npm install --package-lock-only --ignore-scripts --no-audit --no-fund
git -C "${GITHUB_WORKSPACE}" diff --exit-code "${{ env.UI_DIR }}/package-lock.json" || (
echo "::error::package-lock.json is out of sync with package.json."
echo "::error::Regenerate with: npm install --package-lock-only --ignore-scripts --no-audit --no-fund"
exit 1
)
- name: Install dependencies and cache node_modules
id: setup-deps
uses: ./.github/actions/node-setup-cache
with:
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ env.UI_DIR }}
lint-ui:
name: ✨ Lint UI
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [detect-target, setup-ui]
if: needs.detect-target.outputs.run_ui == 'true'
defaults:
run:
working-directory: ${{ env.UI_DIR }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-ui.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ env.UI_DIR }}
- run: npm run lint --if-present
typecheck-ui:
name: 🔎 Typecheck UI
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, setup-ui]
if: needs.detect-target.outputs.run_ui == 'true'
defaults:
run:
working-directory: ${{ env.UI_DIR }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-ui.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ env.UI_DIR }}
- run: npm run typecheck --if-present
# 🧪 Test UI — sharded matrix.
# react-devkit is the bottleneck (~13 min, 296 test files), so it is split
# across 4 parallel runners via `vitest --shard`. Each shard writes a blob
# report; the coverage-ui job merges them and enforces thresholds. The smaller
# packages (ui-foundation, react-adapter, cli) run once on shard 1 via turbo.
test-ui:
name: 🧪 Test UI (shard ${{ matrix.shard }}/4)
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, setup-ui]
if: needs.detect-target.outputs.run_ui == 'true'
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
env:
NODE_OPTIONS: --max-old-space-size=4096
defaults:
run:
working-directory: ${{ env.UI_DIR }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-ui.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ env.UI_DIR }}
- name: Cache Turbo
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: ${{ env.UI_DIR }}/.turbo
key: turbo-ui-test-${{ runner.os }}-${{ hashFiles('ui/package-lock.json') }}-${{ github.sha }}-shard-${{ matrix.shard }}
restore-keys: |
turbo-ui-${{ runner.os }}-${{ hashFiles('ui/package-lock.json') }}-
turbo-ui-${{ runner.os }}-
- name: Cache Vitest transforms
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
# All tested packages set `cacheDir: '.cache'` in vitest.config.js.
path: |
ui/packages/react-devkit/.cache
ui/packages/ui-foundation/.cache
ui/packages/react-adapter/.cache
ui/packages/cli/.cache
key: vitest-ui-${{ runner.os }}-${{ hashFiles('ui/packages/**/*.ts', 'ui/packages/**/*.tsx', 'ui/packages/**/vitest.config.js') }}-shard-${{ matrix.shard }}
restore-keys: |
vitest-ui-${{ runner.os }}-
- name: Restore react-devkit build from Turbo cache
run: |
# node_modules is restored with --ignore-scripts, so workspace dist/
# outputs are absent; vitest needs them to resolve sibling packages.
npx turbo run build --filter=@tetherto/mdk-react-devkit
- name: Test smaller packages (shard 1 only)
if: matrix.shard == 1
# Only react-devkit is sharded; the rest run here once. Packages without
# a test:coverage task (fonts, catalog app) are skipped by turbo.
run: |
npx turbo run test:coverage --filter='!@tetherto/mdk-react-devkit'
- name: Test react-devkit shard ${{ matrix.shard }}/4
working-directory: ${{ env.UI_DIR }}/packages/react-devkit
# Thresholds are disabled per-shard (each shard covers only a subset of
# files); they are enforced on the merged report in the coverage-ui job.
run: |
npx vitest run \
--shard=${{ matrix.shard }}/4 \
--coverage \
--reporter=blob \
--coverage.thresholds.lines=0 \
--coverage.thresholds.functions=0 \
--coverage.thresholds.branches=0 \
--coverage.thresholds.statements=0
- name: Upload blob report
uses: actions/upload-artifact@v4
with:
name: ui-blob-report-${{ matrix.shard }}
path: ${{ env.UI_DIR }}/packages/react-devkit/.vitest-reports/
retention-days: 1
if-no-files-found: error
include-hidden-files: true
coverage-ui:
name: 📊 Coverage Merge UI
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [detect-target, setup-ui, test-ui]
if: needs.detect-target.outputs.run_ui == 'true'
defaults:
run:
working-directory: ${{ env.UI_DIR }}/packages/react-devkit
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-ui.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ env.UI_DIR }}
- name: Download all blob reports
uses: actions/download-artifact@v4
with:
path: ${{ env.UI_DIR }}/packages/react-devkit/.vitest-reports
pattern: ui-blob-report-*
merge-multiple: true
- name: Merge coverage and enforce thresholds
run: |
ls -la .vitest-reports/
npx vitest run --mergeReports --coverage --coverage.reporter=text-summary --reporter=default
build-ui:
name: 🏗️ Build UI
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [detect-target, setup-ui]
if: needs.detect-target.outputs.run_ui == 'true'
defaults:
run:
working-directory: ${{ env.UI_DIR }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-ui.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ env.UI_DIR }}
- run: npm run build --if-present
setup-core:
name: 📦 Setup Core (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, list-core]
if: needs.detect-target.outputs.run_core == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-core.outputs.dirs) }}
outputs:
cache-key: ${{ steps.setup-deps.outputs.cache-key }}
lockfile-outcome: ${{ steps.lockfile.outcome }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Install dependencies and cache node_modules
id: setup-deps
uses: ./.github/actions/node-setup-cache
with:
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- name: Lockfile consistency check
id: lockfile
shell: bash
working-directory: ${{ matrix.dir }}
run: |
set -euo pipefail
if [ ! -f package-lock.json ]; then
echo "No package-lock.json; skipping lockfile check"
exit 0
fi
npm install --package-lock-only --ignore-scripts --no-audit --no-fund
git -C "${GITHUB_WORKSPACE}" diff --exit-code "${{ matrix.dir }}/package-lock.json" || (
echo "::error::package-lock.json is out of sync with package.json in ${{ matrix.dir }}."
echo "::error::Regenerate with: npm install --package-lock-only --ignore-scripts --no-audit --no-fund"
exit 1
)
lint-core:
name: ✨ Lint Core (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [detect-target, list-core, setup-core]
if: needs.detect-target.outputs.run_core == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-core.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-core.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- run: npm run lint --if-present
typecheck-core:
name: 🔎 Typecheck Core (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, list-core, setup-core]
if: needs.detect-target.outputs.run_core == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-core.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-core.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- run: npm run typecheck --if-present
test-core:
name: 🧪 Test Core (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [detect-target, list-core, setup-core]
if: needs.detect-target.outputs.run_core == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-core.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-core.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- name: Install cross-package dependencies
shell: bash
working-directory: ${{ github.workspace }}
run: |
# Core packages use relative requires into sibling core packages
# (e.g. mdk -> kernel) and into backend/workers/** (base, lib,
# http.node.wrk, containers). Each test runner only restores the
# matrix package's node_modules, so the reachable sibling packages
# must be installed here too.
find backend/core backend/workers -name package.json \
-not -path '*/node_modules/*' -not -path '*/examples/*' \
| xargs -I{} dirname {} \
| grep -v "^${{ matrix.dir }}$" \
| while read -r dir; do
echo "Installing deps: $dir"
if [ -f "$dir/package-lock.json" ]; then
(cd "$dir" && npm ci --ignore-scripts --no-audit --no-fund)
else
(cd "$dir" && npm install --ignore-scripts --no-audit --no-fund)
fi
done
- run: npm run test:coverage --if-present || npm test --if-present
build-core:
name: 🏗️ Build Core (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [detect-target, list-core, setup-core]
if: needs.detect-target.outputs.run_core == 'true' && needs.list-core.outputs.buildable_dirs != '[]'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-core.outputs.buildable_dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-core.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- run: npm run build
setup-workers:
name: 📦 Setup Worker (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, list-workers]
if: needs.detect-target.outputs.run_workers == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-workers.outputs.dirs) }}
outputs:
cache-key: ${{ steps.setup-deps.outputs.cache-key }}
lockfile-outcome: ${{ steps.lockfile.outcome }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Lockfile consistency check
id: lockfile
shell: bash
working-directory: ${{ matrix.dir }}
run: |
set -euo pipefail
if [ ! -f package-lock.json ]; then
echo "No package-lock.json; skipping lockfile check"
exit 0
fi
npm install --package-lock-only --ignore-scripts --no-audit --no-fund
git -C "${GITHUB_WORKSPACE}" diff --exit-code "${{ matrix.dir }}/package-lock.json" || (
echo "::error::package-lock.json is out of sync with package.json in ${{ matrix.dir }}."
echo "::error::Regenerate with: npm install --package-lock-only --ignore-scripts --no-audit --no-fund"
exit 1
)
- name: Install dependencies and cache node_modules
id: setup-deps
uses: ./.github/actions/node-setup-cache
with:
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
lint-workers:
name: ✨ Lint Worker (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [detect-target, list-workers, setup-workers]
if: needs.detect-target.outputs.run_workers == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-workers.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-workers.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- run: npm run lint --if-present
typecheck-workers:
name: 🔎 Typecheck Worker (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, list-workers, setup-workers]
if: needs.detect-target.outputs.run_workers == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-workers.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-workers.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- run: npm run typecheck --if-present
test-workers:
name: 🧪 Test Worker (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [detect-target, list-workers, setup-workers]
if: needs.detect-target.outputs.run_workers == 'true'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-workers.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-workers.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- name: Install shared package dependencies
shell: bash
working-directory: ${{ github.workspace }}
run: |
# Worker packages use relative requires into the shared core packages
# (mdk → kernel, mdk-worker, client) and the mock toolkit. Each test
# runner only restores the matrix package's node_modules, so those
# shared packages must be installed here too. The base packages this
# step used to install were deleted with the WorkerRuntime migration.
for dir in backend/core/kernel backend/core/client backend/core/mdk backend/core/mdk-worker backend/workers/mock backend/core/mock-control-service; do
[ -f "$dir/package.json" ] || continue
[ "$dir" = "${{ matrix.dir }}" ] && continue
echo "Installing deps: $dir"
(cd "$dir" && npm ci --ignore-scripts --no-audit --no-fund)
done
- run: npm run test:coverage --if-present || npm test --if-present
build-workers:
name: 🏗️ Build Worker (${{ matrix.dir }})
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [detect-target, list-workers, setup-workers]
if: needs.detect-target.outputs.run_workers == 'true' && needs.list-workers.outputs.buildable_dirs != '[]'
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-workers.outputs.buildable_dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-workers.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- run: npm run build
security_checks:
name: 🔐 Security Checks
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Dependency Review
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
with:
fail-on-severity: moderate
vulnerability-check: true
license-check: true
security_audit_ui:
name: 🔐 Security Audit UI
if: github.event_name == 'pull_request' && needs.detect-target.outputs.run_ui == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, setup-ui]
permissions:
contents: read
defaults:
run:
working-directory: ${{ env.UI_DIR }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-ui.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ env.UI_DIR }}
- name: Security audit (npm)
run: |
set +e
npm audit signatures 2>&1
SIGNATURES_EXIT=$?
npm audit --audit-level=moderate 2>&1
MODERATE_EXIT=$?
npm exec --yes -- audit-ci@7 --config "${GITHUB_WORKSPACE}/.github/scripts/audit-ci.jsonc" 2>&1
HIGH_EXIT=$?
set -e
[ $SIGNATURES_EXIT -eq 0 ] && SIGNATURES_STATUS="PASS" || SIGNATURES_STATUS="WARN"
[ $MODERATE_EXIT -eq 0 ] && MODERATE_STATUS="PASS" || MODERATE_STATUS="WARN"
[ $HIGH_EXIT -eq 0 ] && HIGH_STATUS="PASS" || HIGH_STATUS="WARN"
# Only emit a summary block when the audit found something; a clean
# PR should not produce a wall of PASS tables.
if [ $MODERATE_EXIT -ne 0 ] || [ $HIGH_EXIT -ne 0 ]; then
AUD_JSON="${RUNNER_TEMP:-/tmp}/npm-audit-ui.json"
npm audit --json > "${AUD_JSON}" 2>/dev/null || true
{
echo "## Security Audit — UI (\`${{ env.UI_DIR }}\`)"
echo ""
echo "| Signatures | Moderate | High/Critical (audit-ci) |"
echo "|---|---|---|"
echo "| ${SIGNATURES_STATUS} | ${MODERATE_STATUS} | ${HIGH_STATUS} |"
} >> "$GITHUB_STEP_SUMMARY"
bash "${GITHUB_WORKSPACE}/.github/scripts/github-summary-npm-audit-high-critical.sh" "${AUD_JSON}" >> "$GITHUB_STEP_SUMMARY" || true
fi
[ $HIGH_EXIT -eq 0 ]
security_audit_core:
name: 🔐 Security Audit Core (${{ matrix.dir }})
if: github.event_name == 'pull_request' && needs.detect-target.outputs.run_core == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, list-core, setup-core]
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-core.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- uses: ./.github/actions/node-restore-cache
with:
cache-key: ${{ needs.setup-core.outputs.cache-key }}
node-version: ${{ env.NODE_VERSION }}
working-directory: ${{ matrix.dir }}
- name: Security audit (npm)
run: |
set +e
npm audit signatures 2>&1
SIGNATURES_EXIT=$?
npm audit --audit-level=moderate 2>&1
MODERATE_EXIT=$?
npm exec --yes -- audit-ci@7 --config "${GITHUB_WORKSPACE}/.github/scripts/audit-ci.jsonc" 2>&1
HIGH_EXIT=$?
set -e
[ $SIGNATURES_EXIT -eq 0 ] && SIGNATURES_STATUS="PASS" || SIGNATURES_STATUS="WARN"
[ $MODERATE_EXIT -eq 0 ] && MODERATE_STATUS="PASS" || MODERATE_STATUS="WARN"
[ $HIGH_EXIT -eq 0 ] && HIGH_STATUS="PASS" || HIGH_STATUS="WARN"
# Only emit a per-package summary block when the audit found
# something; a clean PR should not produce a wall of PASS tables.
if [ $MODERATE_EXIT -ne 0 ] || [ $HIGH_EXIT -ne 0 ]; then
AUD_JSON="${RUNNER_TEMP:-/tmp}/npm-audit-${{ matrix.dir }}.json"
npm audit --json > "${AUD_JSON}" 2>/dev/null || true
{
echo "## Security Audit — Core (\`${{ matrix.dir }}\`)"
echo ""
echo "| Signatures | Moderate | High/Critical (audit-ci) |"
echo "|---|---|---|"
echo "| ${SIGNATURES_STATUS} | ${MODERATE_STATUS} | ${HIGH_STATUS} |"
} >> "$GITHUB_STEP_SUMMARY"
bash "${GITHUB_WORKSPACE}/.github/scripts/github-summary-npm-audit-high-critical.sh" "${AUD_JSON}" >> "$GITHUB_STEP_SUMMARY" || true
fi
[ $HIGH_EXIT -eq 0 ]
security_audit_workers:
name: 🔐 Security Audit Worker (${{ matrix.dir }})
if: github.event_name == 'pull_request' && needs.detect-target.outputs.run_workers == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [detect-target, list-workers, setup-workers]
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.list-workers.outputs.dirs) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- uses: ./.github/actions/node-restore-cache