-
Notifications
You must be signed in to change notification settings - Fork 71
1544 lines (1373 loc) · 61.4 KB
/
tidy3d-python-client-tests.yml
File metadata and controls
1544 lines (1373 loc) · 61.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
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
name: "public/tidy3d/python-client-tests"
on:
merge_group:
push:
branches:
- develop
workflow_dispatch:
inputs:
remote_tests:
description: 'remote-tests'
type: boolean
default: true
local_tests:
description: 'local-tests'
type: boolean
default: false
cli_tests:
description: 'develop-cli'
type: boolean
default: false
submodule_tests:
description: 'submodule-tests'
type: boolean
default: false
version_match_tests:
description: 'version-consistency-checks'
type: boolean
default: false
extras_integration_tests:
description: 'integration-tidy3d-extras'
type: boolean
default: false
test_type:
description: 'test-type (basic or full)'
type: choice
options:
- basic
- full
default: 'basic'
test_selection:
description: 'test-selection (testmon or full)'
type: choice
options:
- testmon
- full
default: 'testmon'
release_tag:
description: 'Release Tag (v2.10.0, v2.10.0rc1)'
required: false
type: string
default: ''
workflow_call:
inputs:
remote_tests:
description: 'remote-tests'
type: boolean
required: false
default: true
local_tests:
description: 'local-tests'
type: boolean
required: false
default: true
cli_tests:
description: 'Run develop-cli tests'
type: boolean
required: false
default: false
submodule_tests:
description: 'Run submodule tests'
type: boolean
required: false
default: false
version_match_tests:
description: 'Run version consistency checks'
type: boolean
required: false
default: false
extras_integration_tests:
description: 'Run tidy3d-extras integration tests'
type: boolean
required: false
default: false
test_type:
description: 'Test type for extras integration tests (basic or full)'
type: string
required: false
default: 'basic'
test_selection:
description: 'Test selection mode for local and remote tests (testmon or full)'
type: string
required: false
default: 'testmon'
release_tag:
description: 'Release Tag (v2.10.0, v2.10.0rc1)'
required: false
type: string
default: ''
outputs:
workflow_success:
description: 'Overall test workflow success status'
value: ${{ jobs.workflow-validation.result == 'success' }}
pull_request:
branches:
- latest
- develop
- 'pre/*'
types: ['opened', 'reopened', 'synchronize', 'ready_for_review', 'edited']
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref == 'refs/heads/develop' }}
env:
VERIFICATIONS_PY_VERSION: '3.11'
jobs:
determine-test-scope:
runs-on: ubuntu-latest
if: |
github.event.pull_request.draft == false ||
github.ref == 'refs/heads/develop' ||
github.event_name == 'workflow_dispatch'
outputs:
code_quality_tests: ${{ steps.determine-test-type.outputs.code_quality_tests }}
pr_review_tests: ${{ steps.determine-test-type.outputs.pr_review_tests }}
local_tests: ${{ steps.determine-test-type.outputs.local_tests }}
remote_tests: ${{ steps.determine-test-type.outputs.remote_tests }}
cli_tests: ${{ steps.determine-test-type.outputs.cli_tests }}
submodule_tests: ${{ steps.determine-test-type.outputs.submodule_tests }}
version_match_tests: ${{ steps.determine-test-type.outputs.version_match_tests }}
extras_integration_tests: ${{ steps.determine-test-type.outputs.extras_integration_tests }}
test_type: ${{ steps.determine-test-type.outputs.test_type }}
test_selection: ${{ steps.determine-test-type.outputs.test_selection }}
steps:
- name: determine-test-type
id: determine-test-type
env:
DRAFT_STATE: ${{ github.event.pull_request.draft }}
EVENT_NAME: ${{ github.event_name }}
REVIEW_STATE: ${{ github.event.review.state }}
REF: ${{ github.ref }}
INPUT_LOCAL: ${{ github.event.inputs.local_tests || inputs.local_tests }}
INPUT_REMOTE: ${{ github.event.inputs.remote_tests || inputs.remote_tests }}
INPUT_CLI: ${{ github.event.inputs.cli_tests || inputs.cli_tests }}
INPUT_SUBMODULE: ${{ github.event.inputs.submodule_tests || inputs.submodule_tests }}
INPUT_VERSION_MATCH: ${{ github.event.inputs.version_match_tests || inputs.version_match_tests }}
INPUT_EXTRAS_INTEGRATION: ${{ github.event.inputs.extras_integration_tests || inputs.extras_integration_tests }}
INPUT_TEST_TYPE: ${{ github.event.inputs.test_type || inputs.test_type }}
INPUT_TEST_SELECTION: ${{ github.event.inputs.test_selection || inputs.test_selection }}
run: |
echo "Event: $EVENT_NAME"
echo "Draft: $DRAFT_STATE"
echo "Review State: $REVIEW_STATE"
echo "Git REF: $REF"
echo "Input local: $INPUT_LOCAL"
echo "Input remote: $INPUT_REMOTE"
echo "Input cli: $INPUT_CLI"
echo "Input submodule: $INPUT_SUBMODULE"
echo "Input version_match: $INPUT_VERSION_MATCH"
echo "Input extras_integration: $INPUT_EXTRAS_INTEGRATION"
echo "Input test_type: $INPUT_TEST_TYPE"
echo "Input test_selection: $INPUT_TEST_SELECTION"
remote_tests=false
local_tests=false
cli_tests=false
submodule_tests=false
version_match_tests=false
code_quality_tests=false
pr_review_tests=false
extras_integration_tests=false
test_type="basic"
test_selection="testmon"
# Workflow_dispatch and workflow_call input override
if [[ "$EVENT_NAME" == "workflow_dispatch" || "$EVENT_NAME" == "workflow_call" ]]; then
code_quality_tests=true
# Each option is self contained
if [[ "$INPUT_REMOTE" == "true" ]]; then
remote_tests=true
fi
if [[ "$INPUT_LOCAL" == "true" ]]; then
local_tests=true
fi
if [[ "$INPUT_CLI" == "true" ]]; then
cli_tests=true
fi
if [[ "$INPUT_SUBMODULE" == "true" ]]; then
submodule_tests=true
fi
if [[ "$INPUT_VERSION_MATCH" == "true" ]]; then
version_match_tests=true
fi
if [[ "$INPUT_EXTRAS_INTEGRATION" == "true" ]]; then
extras_integration_tests=true
fi
if [[ -n "$INPUT_TEST_SELECTION" ]]; then
test_selection="$INPUT_TEST_SELECTION"
fi
fi
# All PRs that have been triggered need local tests (remote reserved for merge queue/manual)
if [[ "$EVENT_NAME" == "pull_request" ]]; then
local_tests=true
code_quality_tests=true
pr_review_tests=true
test_selection="testmon"
fi
if [[ "$EVENT_NAME" == "merge_group" ]]; then
local_tests=true
remote_tests=true
code_quality_tests=true
extras_integration_tests=true
test_type="basic"
test_selection="full"
fi
if [[ "$EVENT_NAME" == "push" ]]; then
local_tests=true
remote_tests=true
extras_integration_tests=true
test_type="basic"
test_selection="full"
fi
# Set test_type based on input or event
if [[ -n "$INPUT_TEST_TYPE" ]]; then
test_type="$INPUT_TEST_TYPE"
fi
echo "local_tests=$local_tests" >> $GITHUB_OUTPUT
echo "remote_tests=$remote_tests" >> $GITHUB_OUTPUT
echo "cli_tests=$cli_tests" >> $GITHUB_OUTPUT
echo "submodule_tests=$submodule_tests" >> $GITHUB_OUTPUT
echo "version_match_tests=$version_match_tests" >> $GITHUB_OUTPUT
echo "code_quality_tests=$code_quality_tests" >> $GITHUB_OUTPUT
echo "pr_review_tests=$pr_review_tests" >> $GITHUB_OUTPUT
echo "extras_integration_tests=$extras_integration_tests" >> $GITHUB_OUTPUT
echo "test_type=$test_type" >> $GITHUB_OUTPUT
echo "test_selection=$test_selection" >> $GITHUB_OUTPUT
echo "code_quality_tests=$code_quality_tests"
echo "pr_review_tests=$pr_review_tests"
echo "local_tests=$local_tests"
echo "remote_tests=$remote_tests"
echo "cli_tests=$cli_tests"
echo "submodule_tests=$submodule_tests"
echo "version_match_tests=$version_match_tests"
echo "extras_integration_tests=$extras_integration_tests"
echo "test_type=$test_type"
echo "test_selection=$test_selection"
move-type-imports:
name: move-type-imports
needs: determine-test-scope
if: needs.determine-test-scope.outputs.code_quality_tests == 'true'
runs-on: ubuntu-latest
steps:
- name: checkout-branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
persist-credentials: false
- name: setup-python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ env.VERIFICATIONS_PY_VERSION }}
- name: install-dependencies
run: |
set -euo pipefail
python -m venv .venv
source .venv/bin/activate
pip install libcst
- name: verify-type-import-guards
run: |
set -euo pipefail
source .venv/bin/activate
python scripts/move_type_imports.py --mode check_on_change
lint:
needs: determine-test-scope
if: needs.determine-test-scope.outputs.code_quality_tests == 'true'
name: verify-linting
runs-on: ubuntu-latest
container: ghcr.io/astral-sh/uv:debian
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 1
submodules: false
persist-credentials: false
- uses: astral-sh/ruff-action@4919ec5cf1f49eff0871dbcea0da843445b837e6 # v3.6.1
with:
version: 0.11.11
- name: Run ruff format
run: ruff format --check --diff
- name: Run ruff check
run: ruff check tidy3d
mypy:
name: static-type-checks (mypy)
needs: determine-test-scope
if: needs.determine-test-scope.outputs.code_quality_tests == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 1
submodules: false
persist-credentials: false
- name: setup-python-${{ env.VERIFICATIONS_PY_VERSION }}
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ env.VERIFICATIONS_PY_VERSION }}
- name: Install mypy
run: |
python -m pip install --upgrade pip
pip install "mypy==1.13.0"
- name: Run mypy
run: |
mypy --config-file=pyproject.toml
zizmor:
name: Run zizmor 🌈
runs-on: ubuntu-latest
needs: determine-test-scope
if: needs.determine-test-scope.outputs.code_quality_tests == 'true'
permissions:
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install the latest version of uv
uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.7.0
- name: Run zizmor 🌈
run: uvx --from "zizmor==1.19.0" zizmor .github/workflows/*.y* --format=sarif . > results.sarif
env:
GH_TOKEN: ${{ github.token }}
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@192325c86100d080feab897ff886c34abd4c83a3 # v3.30.3
with:
sarif_file: results.sarif
category: zizmor
- name: run zizmor directly # this gets a success or fail result
run: uvx --from "zizmor==1.19.0" zizmor .github/workflows/*.y*
env:
GH_TOKEN: ${{ github.token }}
lint-branch-name:
needs: determine-test-scope
runs-on: ubuntu-latest
if: needs.determine-test-scope.outputs.pr_review_tests == 'true'
name: lint-branch-name
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
steps:
- name: extract-branch-name
id: extract-branch-name
run: |
BRANCH_NAME="${GITHUB_HEAD_REF}"
if [[ -z "$BRANCH_NAME" && -n "$PR_BRANCH" ]]; then
BRANCH_NAME="$PR_BRANCH"
echo "(fallback) Using PR head branch name: $BRANCH_NAME"
fi
if [[ -z "$BRANCH_NAME" ]]; then
BRANCH_NAME="${GITHUB_REF_NAME:-${GITHUB_REF#refs/heads/}}"
echo "(fallback) Using ref-derived branch name: $BRANCH_NAME"
fi
echo "Branch name: $BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: enforce-jira-key
id: enforce-jira-key
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.user.login != 'dependabot[bot]' &&
!startsWith(github.event.pull_request.head.ref, 'chore/build-changelog-')
env:
STEPS_EXTRACT_BRANCH_NAME_OUTPUTS_BRANCH_NAME: ${{ steps.extract-branch-name.outputs.branch_name }}
run: |
BRANCH_NAME="${STEPS_EXTRACT_BRANCH_NAME_OUTPUTS_BRANCH_NAME}"
echo $BRANCH_NAME
# Allow only Jira keys from known projects, even if the branch has an author prefix
ALLOWED_JIRA_PROJECTS=("FXC" "SCEM" "SCRF")
JIRA_PROJECT_PATTERN=$(IFS='|'; echo "${ALLOWED_JIRA_PROJECTS[*]}")
JIRA_PATTERN="(${JIRA_PROJECT_PATTERN})-[0-9]+"
# List of exempt prefixes (case-insensitive)
EXEMPT_PREFIXES=("chore" "hotfix" "daily-chore")
# Convert branch name to lowercase for comparison
BRANCH_LOWER=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]')
# Check if branch starts with any exempt prefix
for prefix in "${EXEMPT_PREFIXES[@]}"; do
if [[ "$BRANCH_LOWER" == $prefix* ]]; then
echo "ℹ️ Branch starts with '$prefix' - Jira key not required"
exit 0
fi
done
if [[ "$BRANCH_NAME" =~ $JIRA_PATTERN ]]; then
echo "✅ Jira key found in branch name: ${BASH_REMATCH[0]}"
else
echo "❌ No Jira key found in branch name, checking PR name as fallback"
if [[ "$PR_TITLE" =~ $JIRA_PATTERN ]]; then
echo "✅ Jira key found in PR-title: ${BASH_REMATCH[0]}"
else
echo "❌ No Jira key found in branch name and PR title"
echo "ℹ️ Expected Jira key prefixes: ${ALLOWED_JIRA_PROJECTS[*]}"
exit 1
fi
fi
enforce-changelog-policy:
needs: determine-test-scope
runs-on: ubuntu-latest
if: needs.determine-test-scope.outputs.pr_review_tests == 'true'
name: enforce-changelog-policy
steps:
- name: Check out source code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: disallow-manual-changelog-edits
env:
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
run: |
set -euo pipefail
if ! git cat-file -e "${PR_BASE_SHA}:changelog.d/README.md" 2>/dev/null; then
echo "Towncrier changelog workflow not detected in base commit; skipping check."
exit 0
fi
if [[ "$PR_BRANCH" == chore/build-changelog-* ]]; then
echo "Auto-generated changelog branch detected; allowing CHANGELOG.md edits."
exit 0
fi
if git diff --name-only "$PR_BASE_SHA" "$PR_HEAD_SHA" | grep -Fxq "CHANGELOG.md"; then
echo "❌ Manual edits to CHANGELOG.md are not allowed."
echo "Add changelog fragments under changelog.d/ instead."
exit 1
fi
echo "✅ No direct CHANGELOG.md edits detected."
lint-commit-messages:
needs: determine-test-scope
runs-on: ubuntu-latest
if: needs.determine-test-scope.outputs.code_quality_tests == 'true'
name: lint-commit-messages
# Soft-fail on PRs (early feedback), hard-fail in merge queue (enforced)
continue-on-error: ${{ github.event_name == 'pull_request' }}
steps:
- name: Check out source code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0 # fetch all commits in the PR
persist-credentials: false
- name: Setup node
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: lts/*
- name: Install commitlint
run: npm install -D @commitlint/cli @commitlint/config-conventional
- name: Print versions
run: |
git --version
node --version
npm --version
npx commitlint --version
- name: Check commit messages (pull_request)
if: github.event_name == 'pull_request'
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
npx commitlint --from $BASE_SHA --to $HEAD_SHA --verbose || {
echo "::warning::Commit messages don't follow conventional commits format. Fix before merge queue."
exit 1
}
- name: Check commit messages (merge_group)
if: github.event_name == 'merge_group'
env:
GITHUB_EVENT_MERGE_GROUP_HEAD_SHA: ${{ github.event.merge_group.head_sha }}
run: |
# For merge groups, check the commits being merged
npx commitlint --from ${{ github.event.merge_group.base_sha }} --to ${GITHUB_EVENT_MERGE_GROUP_HEAD_SHA} --verbose || {
echo "Commit message linting failed; please follow the conventional commits format at https://www.conventionalcommits.org/"
exit 1
}
verify-schema-change:
name: verify-schema-change
needs: determine-test-scope
if: needs.determine-test-scope.outputs.code_quality_tests == 'true'
runs-on: ubuntu-latest
container: ghcr.io/astral-sh/uv:debian
defaults:
run:
shell: bash
steps:
- name: checkout-branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
persist-credentials: false
- name: git-config
run: |
cd $GITHUB_WORKSPACE
git config --global --add safe.directory $GITHUB_WORKSPACE
- name: install-depedencies
run: |
uv venv $GITHUB_WORKSPACE/.venv -p "$VERIFICATIONS_PY_VERSION"
source $GITHUB_WORKSPACE/.venv/bin/activate
uv pip install -e "$GITHUB_WORKSPACE"
- name: get-tidy3d-version
id: get-version
run: |
source $GITHUB_WORKSPACE/.venv/bin/activate
version=$(python -c "import tidy3d; print(tidy3d.__version__)")
echo "tidy3d version is $version"
echo "version=$version" >> $GITHUB_OUTPUT
- name: verify-committed-schema
run: |
set -euo pipefail
echo "Regenerating docs-free canonical schemas into repo schemas/ ..."
source $GITHUB_WORKSPACE/.venv/bin/activate
python $GITHUB_WORKSPACE/scripts/regenerate_schema.py
echo "Verifying committed schemas match generated output..."
if ! git diff --name-status --exit-code -- schemas; then
echo "❌ Committed schemas are not up-to-date. See diff above."
exit 1
fi
echo "✅ Committed schemas are up-to-date."
- name: run-schema-diff
id: schema-diff
env:
GITHUB_EVENT_PULL_REQUEST_BASE_REPO_FULL_NAME: ${{ github.event.pull_request.base.repo.full_name }}
GITHUB_EVENT_PULL_REQUEST_BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
set -euo pipefail
cd "$GITHUB_WORKSPACE"
# Determine base repo/ref for PRs; default to current repo and 'develop' otherwise
BASE_REPO="${GITHUB_EVENT_PULL_REQUEST_BASE_REPO_FULL_NAME}"
BASE_REF="${GITHUB_EVENT_PULL_REQUEST_BASE_REF}"
if [ -z "$BASE_REPO" ]; then
BASE_REPO="${{ github.repository }}"
fi
if [ -z "$BASE_REF" ]; then
BASE_REF="develop"
fi
echo "Fetching base branch $BASE_REPO@$BASE_REF (shallow)..."
git remote add upstream "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${BASE_REPO}.git" || true
git fetch --no-tags --prune --depth=1 upstream "+refs/heads/${BASE_REF}:refs/remotes/upstream/${BASE_REF}"
# Store base repo/ref for use in subsequent steps
echo "base_repo=${BASE_REPO}" >> "$GITHUB_OUTPUT"
echo "base_ref=${BASE_REF}" >> "$GITHUB_OUTPUT"
# Name-status diff between base and head limited to schemas/
DIFF_OUTPUT=$(git diff --name-status "upstream/${BASE_REF}...HEAD" -- schemas || true)
if [ -z "$DIFF_OUTPUT" ]; then
echo "✅ No schema changes relative to ${BASE_REF}."
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Schema changes detected relative to ${BASE_REF}."
echo "changed=true" >> "$GITHUB_OUTPUT"
# Summarize changes
{
echo "### Schema Change Summary"
echo "| Status | File |"
echo "|:---:|:---|"
} >> "$GITHUB_STEP_SUMMARY"
while IFS=$'\t' read -r status file; do
# Map short status to human-friendly
case "$status" in
A|AM) label="Added 🟢" ;;
M|MM) label="Modified 🟡" ;;
D) label="Removed 🔴" ;;
R*) label="Renamed 🟠" ;;
*) label="$status" ;;
esac
echo "| $label | \`$file\` |" >> "$GITHUB_STEP_SUMMARY"
done <<< "$DIFF_OUTPUT"
- name: compare-versions
id: compare-versions
if: steps.schema-diff.outputs.changed == 'true'
env:
PR_VERSION: ${{ steps.get-version.outputs.version }}
BASE_REPO: ${{ steps.schema-diff.outputs.base_repo }}
BASE_REF: ${{ steps.schema-diff.outputs.base_ref }}
run: |
set -euo pipefail
cd "$GITHUB_WORKSPACE"
PR_VERSION="${PR_VERSION}"
BASE_REPO="${BASE_REPO}"
BASE_REF="${BASE_REF}"
echo "PR branch version: $PR_VERSION"
# Checkout base branch temporarily to get its version
echo "Checking out base branch ${BASE_REF} to get version..."
git checkout -q "refs/remotes/upstream/${BASE_REF}"
# Install dependencies and get version from base branch
source $GITHUB_WORKSPACE/.venv/bin/activate
uv pip install -e "$GITHUB_WORKSPACE" --quiet
BASE_VERSION=$(python -c "import tidy3d; print(tidy3d.__version__)")
echo "Base branch (${BASE_REF}) version: $BASE_VERSION"
echo "base_version=${BASE_VERSION}" >> "$GITHUB_OUTPUT"
# Return to HEAD branch
git checkout -q HEAD
# Compare versions
if [[ "$PR_VERSION" != "$BASE_VERSION" ]]; then
echo "⚠️ Version mismatch detected: PR branch ($PR_VERSION) != base branch ($BASE_VERSION)"
echo "This appears to be a version bump PR. Skipping schema change verification."
echo "is_version_bump=true" >> "$GITHUB_OUTPUT"
else
echo "✅ Versions match: PR branch ($PR_VERSION) == base branch ($BASE_VERSION)"
echo "Proceeding with schema change verification."
echo "is_version_bump=false" >> "$GITHUB_OUTPUT"
fi
- name: verify-allowed-changes
if: steps.schema-diff.outputs.changed == 'true' && steps.compare-versions.outputs.is_version_bump == 'false'
env:
BASE_VERSION: ${{ steps.compare-versions.outputs.base_version }}
BASE_REF: ${{ steps.schema-diff.outputs.base_ref }}
run: |
set -e
base_version="${BASE_VERSION}"
base_ref="${BASE_REF}"
if [[ "$base_version" == *rc* ]] || [[ "$base_version" == *dev* ]]; then
echo "✅ Passing: Schema changed on a pre-release version ($base_version) in base branch '${base_ref}', which is permitted."
else
echo "❌ Failing: Schema changed on a non-pre-release version ($base_version) in base branch '${base_ref}'."
exit 1
fi
local-tests:
# Run on open PRs OR when manually triggered with local_tests=true
needs: determine-test-scope
if: needs.determine-test-scope.outputs.local_tests == 'true'
name: python-${{ matrix.python-version }}-self-hosted-runner
runs-on: [ slurm-runner, 4xcpu, container=ghcr.io/astral-sh/uv:debian ]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name }}-${{ matrix.python-version }}-local
cancel-in-progress: true
strategy:
matrix:
python-version: ['3.10', '3.13']
defaults:
run:
shell: bash
env:
PIP_ONLY_BINARY: gdstk
MPLBACKEND: agg
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag || inputs.release_tag }}
TEST_SELECTION: ${{ needs.determine-test-scope.outputs.test_selection }}
permissions:
pull-requests: write
steps:
- name: checkout-head
if: ${{ !env.RELEASE_TAG }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
submodules: false
persist-credentials: false
lfs: true
- name: checkout-tag
if: ${{ env.RELEASE_TAG }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: refs/tags/${{ env.RELEASE_TAG }}
fetch-depth: 0
submodules: false
persist-credentials: false
lfs: true
- name: compute-testmon-cache-key
id: testmon-cache-key
if: needs.determine-test-scope.outputs.test_selection == 'testmon' || github.event_name == 'merge_group'
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch || 'develop' }}
run: |
default_branch="$DEFAULT_BRANCH"
case "$default_branch" in
''|*[!A-Za-z0-9._/-]*)
echo "::warning::Invalid default branch '$default_branch'; using 'develop'."
default_branch="develop"
;;
esac
default_branch_sha=$(git ls-remote --heads origin "refs/heads/${default_branch}" | awk '{print $1}')
if [[ -z "${default_branch_sha}" ]]; then
echo "::warning::Unable to resolve SHA for default branch '${default_branch}'."
default_branch_sha="unknown"
fi
dep_hash=$(
{
git show HEAD:pyproject.toml
git show HEAD:poetry.lock
} | sha256sum | awk '{print $1}'
)
cache_layout="v2"
if [[ "${GITHUB_EVENT_NAME}" == "merge_group" ]]; then
cache_sha="${GITHUB_SHA}"
else
cache_sha="${default_branch_sha}"
fi
echo "default_branch=$default_branch" >> "$GITHUB_OUTPUT"
echo "default_branch_sha=$default_branch_sha" >> "$GITHUB_OUTPUT"
echo "dep_hash=$dep_hash" >> "$GITHUB_OUTPUT"
echo "cache_layout=$cache_layout" >> "$GITHUB_OUTPUT"
echo "cache_sha=$cache_sha" >> "$GITHUB_OUTPUT"
- name: restore-testmon-cache
id: testmon-cache-restore
if: needs.determine-test-scope.outputs.test_selection == 'testmon' || github.event_name == 'merge_group'
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: .testmondata
key: testmon-local-${{ steps.testmon-cache-key.outputs.cache_layout }}-${{ runner.os }}-py${{ matrix.python-version }}-${{ steps.testmon-cache-key.outputs.default_branch }}-${{ steps.testmon-cache-key.outputs.dep_hash }}-${{ steps.testmon-cache-key.outputs.cache_sha }}
restore-keys: |
testmon-local-${{ steps.testmon-cache-key.outputs.cache_layout }}-${{ runner.os }}-py${{ matrix.python-version }}-${{ steps.testmon-cache-key.outputs.default_branch }}-${{ steps.testmon-cache-key.outputs.dep_hash }}-
- name: telemetry-cache-exact-hit
if: >-
(needs.determine-test-scope.outputs.test_selection == 'testmon' || github.event_name == 'merge_group') &&
steps.testmon-cache-restore.outputs.cache-hit == 'true'
run: echo "testmon cache exact hit"
- name: telemetry-cache-fallback-hit
if: >-
(needs.determine-test-scope.outputs.test_selection == 'testmon' || github.event_name == 'merge_group') &&
steps.testmon-cache-restore.outputs.cache-hit != 'true' &&
steps.testmon-cache-restore.outputs.cache-matched-key != ''
run: echo "testmon cache fallback hit"
- name: telemetry-cache-miss
if: >-
(needs.determine-test-scope.outputs.test_selection == 'testmon' || github.event_name == 'merge_group') &&
steps.testmon-cache-restore.outputs.cache-matched-key == ''
run: echo "testmon cache miss"
- name: install-project
env:
PYTHON_VERSION: ${{ matrix.python-version }}
run: |
if [ -f /.dockerenv ]; then
echo "Running inside a Docker container (detected via /.dockerenv)"
else
echo "Not running inside a Docker container (/.dockerenv not found)"
fi
uv venv -p $PYTHON_VERSION ${GITHUB_WORKSPACE}/.venv
source ${GITHUB_WORKSPACE}/.venv/bin/activate
which python
which uv
python --version
uv pip list
uv pip install gdstk --only-binary gdstk
uv pip install -e ".[dev]"
echo "Testing vtk is correctly installed."
python -c "import vtk"
- name: determine-pytest-selection-flags
id: pytest-selection-flags
env:
EVENT_NAME: ${{ github.event_name }}
run: |
if [[ "${TEST_SELECTION}" == "testmon" ]]; then
echo "flags=--testmon --testmon-forceselect" >> "$GITHUB_OUTPUT"
echo "mode=testmon_forceselect" >> "$GITHUB_OUTPUT"
echo "Using pytest testmon selection mode."
elif [[ "${TEST_SELECTION}" == "full" && "${EVENT_NAME}" == "merge_group" ]]; then
echo "flags=--testmon-noselect" >> "$GITHUB_OUTPUT"
echo "mode=full_with_testmon_collection" >> "$GITHUB_OUTPUT"
echo "Using full test execution with testmon collection mode."
else
echo "flags=--no-testmon" >> "$GITHUB_OUTPUT"
echo "mode=full_no_testmon" >> "$GITHUB_OUTPUT"
echo "Using full pytest execution mode."
fi
- name: telemetry-selection-testmon
if: steps.pytest-selection-flags.outputs.mode == 'testmon_forceselect'
run: echo "pytest selection testmon forceselect"
- name: telemetry-selection-full-with-testmon-collection
if: steps.pytest-selection-flags.outputs.mode == 'full_with_testmon_collection'
run: echo "pytest selection full with testmon collection"
- name: telemetry-selection-full-no-testmon
if: steps.pytest-selection-flags.outputs.mode == 'full_no_testmon'
run: echo "pytest selection full no testmon"
- name: run-tests-coverage
env:
PYTHONUNBUFFERED: "1"
PYTEST_SELECTION_FLAGS: ${{ steps.pytest-selection-flags.outputs.flags }}
run: |
source ${GITHUB_WORKSPACE}/.venv/bin/activate
# pytest --cov=tidy3d -rF --tb=short tests/_test_data/_test_datasets_no_vtk.py
pytest ${PYTEST_SELECTION_FLAGS} --cov=tidy3d -rF --tb=short tests
coverage report -m
coverage xml -o ${GITHUB_WORKSPACE}/coverage.xml
TOTAL_COVERAGE=$(coverage report --format=total)
echo "total=$TOTAL_COVERAGE" >> "$GITHUB_ENV"
echo "### Total coverage: ${TOTAL_COVERAGE}%"
- name: stage-testmon-cache-candidate
if: success() && github.event_name == 'merge_group' && hashFiles('.testmondata') != ''
env:
CACHE_KEY: testmon-local-${{ steps.testmon-cache-key.outputs.cache_layout }}-${{ runner.os }}-py${{ matrix.python-version }}-${{ steps.testmon-cache-key.outputs.default_branch }}-${{ steps.testmon-cache-key.outputs.dep_hash }}-${{ steps.testmon-cache-key.outputs.cache_sha }}
run: |
set -euo pipefail
candidate_dir="$RUNNER_TEMP/testmon-cache-candidate-local-py${{ matrix.python-version }}"
rm -rf "$candidate_dir"
mkdir -p "$candidate_dir"
cp -R .testmondata "$candidate_dir/.testmondata"
cat > "$candidate_dir/metadata.json" <<EOF
{
"cache_key": "${CACHE_KEY}",
"job_class": "local",
"runner_os": "${{ runner.os }}",
"python_version": "${{ matrix.python-version }}"
}
EOF
- name: upload-testmon-cache-candidate
if: success() && github.event_name == 'merge_group' && hashFiles('.testmondata') != ''
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: testmon-cache-candidate-local-${{ runner.os }}-py${{ matrix.python-version }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/testmon-cache-candidate-local-py${{ matrix.python-version }}
include-hidden-files: true
retention-days: 1
- name: save-testmon-cache
if: success() && github.event_name == 'merge_group' && steps.testmon-cache-restore.outputs.cache-hit != 'true' && hashFiles('.testmondata') != ''
uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: .testmondata
key: testmon-local-${{ steps.testmon-cache-key.outputs.cache_layout }}-${{ runner.os }}-py${{ matrix.python-version }}-${{ steps.testmon-cache-key.outputs.default_branch }}-${{ steps.testmon-cache-key.outputs.dep_hash }}-${{ steps.testmon-cache-key.outputs.cache_sha }}
- name: diff-coverage-report
if: >-
matrix.python-version == '3.13' &&
github.event_name == 'pull_request' &&
!contains(github.event.pull_request.labels.*.name, 'ignore_diff_coverage')
env:
GITHUB_EVENT_PULL_REQUEST_BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
source ${GITHUB_WORKSPACE}/.venv/bin/activate
git config --global --add safe.directory ${GITHUB_WORKSPACE}
diff-cover ${GITHUB_WORKSPACE}/coverage.xml \
--compare-branch origin/${GITHUB_EVENT_PULL_REQUEST_BASE_REF} \
--format markdown:diff-coverage.md
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
if: >-
matrix.python-version == '3.13' &&
github.event_name == 'pull_request' &&
!contains(github.event.pull_request.labels.*.name, 'ignore_diff_coverage') &&
github.event.pull_request.head.repo.fork == false
with:
result-encoding: string
script: |
const fs = require('fs');
const marker = '<!-- diff-cover-report -->';
const body = fs.readFileSync('diff-coverage.md','utf8');
const report = `${marker}\n${body}`;
const {data:comments}=await github.rest.issues.listComments({
owner:context.repo.owner,
repo:context.repo.repo,
issue_number:context.issue.number,
});
const existing = comments.find(c=>c.body.startsWith(marker));
if(existing) {
await github.rest.issues.updateComment({
owner:context.repo.owner,
repo:context.repo.repo,
comment_id:existing.id,
body:report,
});
} else {
await github.rest.issues.createComment({
owner:context.repo.owner,
repo:context.repo.repo,
issue_number:context.issue.number,
body:report,
});
}
remote-tests:
# Run tests on a push event OR a workflow dispatch with remote_tests
needs: determine-test-scope
if: needs.determine-test-scope.outputs.remote_tests == 'true'
name: python-${{ matrix.python-version }}-${{ matrix.platform }}
runs-on: ${{ matrix.platform }}
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name }}-${{ matrix.platform }}-${{ matrix.python-version }}-remote
cancel-in-progress: true
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
platform: [windows-latest, ubuntu-latest, macos-latest]
defaults:
run:
shell: bash
env:
PIP_ONLY_BINARY: gdstk
MPLBACKEND: agg
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag || inputs.release_tag }}
TEST_SELECTION: ${{ needs.determine-test-scope.outputs.test_selection }}
steps:
- name: checkout-head
if: ${{ !env.RELEASE_TAG }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 1
submodules: false
persist-credentials: false
lfs: true
- name: checkout-tag
if: ${{ env.RELEASE_TAG }}