-
Notifications
You must be signed in to change notification settings - Fork 1
895 lines (823 loc) · 32.5 KB
/
pr-orchestrator.yml
File metadata and controls
895 lines (823 loc) · 32.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
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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
# yamllint disable rule:line-length rule:truthy
name: PR Orchestrator - SpecFact CLI
on:
pull_request:
branches: [main, dev]
push:
branches: [main, dev]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
PIP_PREFER_BINARY: "1"
jobs:
changes:
name: Detect code changes
runs-on: ubuntu-latest
outputs:
code_changed: ${{ steps.out.outputs.code_changed }}
workflow_changed: ${{ steps.out.outputs.workflow_changed }}
pyproject_changed: ${{ steps.out.outputs.pyproject_changed }}
license_inputs_changed: ${{ steps.out.outputs.license_inputs_changed }}
version_sources_changed: ${{ steps.out.outputs.version_sources_changed }}
skip_tests_dev_to_main: ${{ steps.out.outputs.skip_tests_dev_to_main }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
code:
- '**'
- '!**/*.md'
- '!**/*.mdc'
- '!docs/**'
- '!.github/workflows/**'
pyproject:
- 'pyproject.toml'
license_inputs:
- 'pyproject.toml'
- 'modules/**/module-package.yaml'
- 'src/specfact_cli/modules/**/module-package.yaml'
- 'scripts/check_license_compliance.py'
- 'scripts/license_allowlist.yaml'
- 'scripts/module_pip_dependencies_licenses.yaml'
version_sources:
- 'pyproject.toml'
- 'setup.py'
- 'src/__init__.py'
- 'src/specfact_cli/__init__.py'
workflow:
- '.github/workflows/**'
- 'scripts/run_actionlint.sh'
- 'scripts/yaml-tools.sh'
- id: out
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
PR_BASE_REF="${PR_BASE_REF:-}"
PR_HEAD_REF="${PR_HEAD_REF:-}"
PR_BASE_SHA="${PR_BASE_SHA:-}"
PR_HEAD_SHA="${PR_HEAD_SHA:-}"
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
{
echo "code_changed=true"
echo "workflow_changed=true"
echo "pyproject_changed=true"
echo "license_inputs_changed=true"
echo "version_sources_changed=true"
} >> "$GITHUB_OUTPUT"
else
{
echo "code_changed=${{ steps.filter.outputs.code }}"
echo "workflow_changed=${{ steps.filter.outputs.workflow }}"
echo "pyproject_changed=${{ steps.filter.outputs.pyproject }}"
echo "license_inputs_changed=${{ steps.filter.outputs.license_inputs }}"
echo "version_sources_changed=${{ steps.filter.outputs.version_sources }}"
} >> "$GITHUB_OUTPUT"
fi
SKIP_TESTS=false
if [ "$EVENT_NAME" = "pull_request" ] && [ "$PR_BASE_REF" = "main" ] && [ "$PR_HEAD_REF" = "dev" ]; then
PR_BASE_REV=""
PR_HEAD_REV=""
MERGE_BASE=""
if [ -n "$PR_BASE_SHA" ]; then
PR_BASE_REV=$(git rev-parse "${PR_BASE_SHA}^{commit}" 2>/dev/null || true)
fi
if [ -n "$PR_HEAD_SHA" ]; then
PR_HEAD_REV=$(git rev-parse "${PR_HEAD_SHA}^{commit}" 2>/dev/null || true)
fi
if [ -n "$PR_BASE_REV" ] && [ -n "$PR_HEAD_REV" ]; then
MERGE_BASE=$(git merge-base "$PR_BASE_REV" "$PR_HEAD_REV" 2>/dev/null || true)
fi
if [ -n "$PR_BASE_REV" ] && [ -n "$PR_HEAD_REV" ] && [ "$PR_BASE_REV" = "$PR_HEAD_REV" ] && [ "$MERGE_BASE" = "$PR_HEAD_REV" ]; then
SKIP_TESTS=true
echo "✅ Proven release parity between dev and main; skipping duplicate validation."
else
echo "ℹ️ Release parity proof unavailable for dev→main PR; running required validation set."
fi
fi
echo "skip_tests_dev_to_main=${SKIP_TESTS}" >> "$GITHUB_OUTPUT"
verify-module-signatures:
name: Verify Module Signatures
needs: [changes]
if: needs.changes.outputs.code_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install verifier dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pyyaml beartype icontract cryptography cffi
- name: Verify bundled module manifests (PR = relaxed checksum; push = payload checksum + version)
run: |
set -euo pipefail
# shellcheck disable=SC1091
source scripts/module-verify-policy.sh
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
python scripts/verify-modules-signature.py "${VERIFY_MODULES_PR[@]}" --version-check-base "$BASE_REF"
else
BEFORE="${{ github.event.before }}"
if [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
BEFORE="HEAD~1"
fi
python scripts/verify-modules-signature.py "${VERIFY_MODULES_PUSH_ORCHESTRATOR[@]}" --version-check-base "$BEFORE"
fi
workflow-lint:
name: Workflow Lint
needs: [changes]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Skip when no workflow changes are present
if: needs.changes.outputs.workflow_changed != 'true' && github.event_name != 'workflow_dispatch'
run: |
echo "✅ No workflow changes detected; skipping workflow lint."
- name: Set up Python 3.12
if: needs.changes.outputs.workflow_changed == 'true' || github.event_name == 'workflow_dispatch'
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Set up Go for actionlint
if: needs.changes.outputs.workflow_changed == 'true' || github.event_name == 'workflow_dispatch'
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Install lint dependencies
if: needs.changes.outputs.workflow_changed == 'true' || github.event_name == 'workflow_dispatch'
run: |
python -m pip install --upgrade pip
pip install "hatch" "virtualenv<21"
go install github.com/rhysd/actionlint/cmd/actionlint@v1.7.11
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Run workflow lint
if: needs.changes.outputs.workflow_changed == 'true' || github.event_name == 'workflow_dispatch'
run: |
echo "🔍 Running actionlint for workflow changes..."
hatch run lint-workflows
tests:
name: Tests (Python 3.12)
needs: [changes, verify-module-signatures]
if: needs.changes.outputs.code_changed == 'true'
outputs:
run_unit_coverage: ${{ steps.detect-unit.outputs.run_unit_coverage }}
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Skip full run (dev→main PR)
if: needs.changes.outputs.skip_tests_dev_to_main == 'true'
run: |
echo "✅ Dev→main PR: tests already passed on dev; skipping full test run."
- uses: actions/checkout@v4
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
with:
fetch-depth: 0
- name: Checkout module bundles repo
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
uses: actions/checkout@v4
with:
repository: nold-ai/specfact-cli-modules
path: specfact-cli-modules
ref: ${{ (github.ref == 'refs/heads/main' || github.head_ref == 'main') && 'main' || 'dev' }}
- name: Export module bundles path
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
run: echo "SPECFACT_MODULES_REPO=${GITHUB_WORKSPACE}/specfact-cli-modules" >> "$GITHUB_ENV"
- name: Set up Python 3.12
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install hatch and fallback test dependencies
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
run: |
python -m pip install --upgrade pip
pip install "hatch" "virtualenv<21" coverage "coverage[toml]" pytest pytest-cov pytest-mock pytest-asyncio pytest-xdist pytest-timeout
pip install -e ".[dev]"
- name: Verify version strings are synchronized
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
shell: bash
run: |
set -euo pipefail
BASE=""
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE="${{ github.event.pull_request.base.sha }}"
elif [ "${{ github.event_name }}" = "push" ]; then
BEFORE="${{ github.event.before }}"
if [ -n "$BEFORE" ] && [ "$BEFORE" != "0000000000000000000000000000000000000000" ]; then
BASE="$BEFORE"
fi
fi
if [ -n "$BASE" ]; then
python scripts/check_version_sources.py --changed-vs "$BASE"
else
python scripts/check_version_sources.py
fi
- name: Verify local version is ahead of PyPI
if: >-
needs.changes.outputs.skip_tests_dev_to_main != 'true' &&
needs.changes.outputs.version_sources_changed == 'true'
env:
SPECFACT_PYPI_VERSION_CHECK_LENIENT_NETWORK: "1"
shell: bash
run: |
set -euo pipefail
BASE=""
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE="${{ github.event.pull_request.base.sha }}"
elif [ "${{ github.event_name }}" = "push" ]; then
BEFORE="${{ github.event.before }}"
if [ -n "$BEFORE" ] && [ "$BEFORE" != "0000000000000000000000000000000000000000" ]; then
BASE="$BEFORE"
fi
fi
if [ -n "$BASE" ]; then
python scripts/check_local_version_ahead_of_pypi.py --skip-when-version-unchanged-vs "$BASE"
else
python scripts/check_local_version_ahead_of_pypi.py
fi
- name: Cache hatch environments
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
uses: actions/cache@v4
with:
path: |
~/.cache/uv
key: ${{ runner.os }}-hatch-tests-py312-${{ hashFiles('pyproject.toml', 'src/specfact_cli/modules/*/__init__.py') }}
restore-keys: |
${{ runner.os }}-hatch-tests-py312-
${{ runner.os }}-hatch-
- name: Create test output directories
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
shell: bash
run: |
mkdir -p logs/tests/junit logs/tests/coverage logs/tests/workflows
- name: Set run_unit_coverage (or skip for dev→main)
id: detect-unit
shell: bash
run: |
if [ "${{ needs.changes.outputs.skip_tests_dev_to_main }}" = "true" ]; then
echo "run_unit_coverage=false" >> "$GITHUB_OUTPUT"
else
COUNT=$(find tests/unit -name "test_*.py" 2>/dev/null | wc -l)
if [ "$COUNT" -gt 0 ]; then
echo "run_unit_coverage=true" >> "$GITHUB_OUTPUT"
echo "RUN_UNIT_COVERAGE=true" >> "$GITHUB_ENV"
echo "Detected $COUNT unit test files. Will run coverage steps."
else
echo "run_unit_coverage=false" >> "$GITHUB_OUTPUT"
echo "RUN_UNIT_COVERAGE=false" >> "$GITHUB_ENV"
echo "No unit tests detected. Skipping coverage steps."
fi
fi
- name: Run full test suite (direct smart-test-full)
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
shell: bash
env:
CONTRACT_FIRST_TESTING: "true"
TEST_MODE: "true"
SMART_TEST_TIMEOUT_SECONDS: "1800"
PYTEST_ADDOPTS: "-r fEw"
run: |
echo "🧪 Running full test suite (direct smart-test-full, Python 3.12)..."
python tools/smart_test_coverage.py run --level full
- name: Generate coverage XML for quality gates
if: needs.changes.outputs.skip_tests_dev_to_main != 'true' && env.RUN_UNIT_COVERAGE == 'true'
run: |
python -m coverage xml -o logs/tests/coverage/coverage.xml --data-file=logs/tests/coverage/.coverage
- name: Upload test logs
if: needs.changes.outputs.skip_tests_dev_to_main != 'true'
uses: actions/upload-artifact@v4
with:
name: test-logs
path: logs/tests/
if-no-files-found: ignore
- name: Upload coverage artifacts
if: needs.changes.outputs.skip_tests_dev_to_main != 'true' && env.RUN_UNIT_COVERAGE == 'true'
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: logs/tests/coverage/coverage.xml
if-no-files-found: error
compat-py311:
name: Compatibility (Python 3.11)
runs-on: ubuntu-latest
needs: [changes, verify-module-signatures]
if: needs.changes.outputs.code_changed == 'true' && needs.changes.outputs.skip_tests_dev_to_main != 'true'
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Checkout module bundles repo
uses: actions/checkout@v4
with:
repository: nold-ai/specfact-cli-modules
path: specfact-cli-modules
ref: ${{ (github.ref == 'refs/heads/main' || github.head_ref == 'main') && 'main' || 'dev' }}
- name: Export module bundles path
run: echo "SPECFACT_MODULES_REPO=${GITHUB_WORKSPACE}/specfact-cli-modules" >> "$GITHUB_ENV"
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install hatch
run: |
python -m pip install --upgrade pip
pip install "hatch" "virtualenv<21"
- name: Cache hatch environments
uses: actions/cache@v4
with:
path: |
~/.cache/uv
key: ${{ runner.os }}-hatch-compat-py311-${{ hashFiles('pyproject.toml', 'src/specfact_cli/modules/*/__init__.py') }}
restore-keys: |
${{ runner.os }}-hatch-compat-py311-
${{ runner.os }}-hatch-
- name: Run Python 3.11 compatibility tests (hatch-test matrix env)
run: |
echo "🔁 Python 3.11 compatibility checks"
mkdir -p logs/compat-py311
COMPAT_LOG="logs/compat-py311/compat_$(date -u +%Y%m%d_%H%M%S).log"
{
hatch -e hatch-test.py3.11 run run -- -r fEw tests/unit tests/integration
hatch -e hatch-test.py3.11 run xml || true
} 2>&1 | tee "$COMPAT_LOG"
exit "${PIPESTATUS[0]:-$?}"
- name: Upload compat-py311 logs
if: always()
uses: actions/upload-artifact@v4
with:
name: compat-py311-logs
path: logs/compat-py311/
if-no-files-found: ignore
contract-first-ci:
name: Contract-First CI
runs-on: ubuntu-latest
needs: [changes, verify-module-signatures]
if: needs.changes.outputs.code_changed == 'true' && needs.changes.outputs.skip_tests_dev_to_main != 'true'
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Checkout module bundles repo
uses: actions/checkout@v4
with:
repository: nold-ai/specfact-cli-modules
path: specfact-cli-modules
ref: ${{ (github.ref == 'refs/heads/main' || github.head_ref == 'main') && 'main' || 'dev' }}
- name: Export module bundles path
run: echo "SPECFACT_MODULES_REPO=${GITHUB_WORKSPACE}/specfact-cli-modules" >> "$GITHUB_ENV"
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install "hatch" "virtualenv<21"
- name: Cache hatch environments
uses: actions/cache@v4
with:
path: |
~/.cache/uv
key: ${{ runner.os }}-hatch-contract-first-py312-${{ hashFiles('pyproject.toml', 'src/specfact_cli/modules/*/__init__.py') }}
restore-keys: |
${{ runner.os }}-hatch-contract-first-py312-
${{ runner.os }}-hatch-
- name: Prepare repro log directory
run: mkdir -p logs/repro
- name: Run contract validation and exploration
id: repro
run: |
echo "🔍 Validating runtime contracts..."
REPRO_LOG="logs/repro/repro_$(date -u +%Y%m%d_%H%M%S).log"
echo "Running contract-first validation with required CrossHair... (log: $REPRO_LOG)"
hatch run contract-test 2>&1 | tee "$REPRO_LOG"
exit "${PIPESTATUS[0]:-$?}"
- name: Upload repro logs
if: always()
uses: actions/upload-artifact@v4
with:
name: repro-logs
path: logs/repro/
if-no-files-found: ignore
- name: Upload repro reports
if: always()
uses: actions/upload-artifact@v4
with:
name: repro-reports
path: .specfact/reports/enforcement/
if-no-files-found: ignore
cli-validation:
name: CLI Command Validation
runs-on: ubuntu-latest
needs: [changes, verify-module-signatures]
if: needs.changes.outputs.code_changed == 'true' && needs.changes.outputs.skip_tests_dev_to_main != 'true'
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install CLI
run: |
echo "Installing SpecFact CLI..."
pip install -e .
- name: Validate CLI commands
run: |
echo "🔍 Validating CLI commands..."
specfact --help
echo "✅ CLI validation complete"
quality-gates:
name: Quality Gates (Advisory)
runs-on: ubuntu-latest
needs: [changes, tests]
if: needs.changes.outputs.skip_tests_dev_to_main != 'true' && needs.tests.outputs.run_unit_coverage == 'true'
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Download coverage artifacts from Tests
uses: actions/download-artifact@v4
with:
name: coverage-reports
path: logs/tests/coverage
- name: Validate coverage artifact presence
run: |
test -f logs/tests/coverage/coverage.xml || (echo "❌ Missing coverage.xml" && exit 1)
echo "✅ Found coverage.xml"
- name: Run quality gates (advisory)
run: |
mkdir -p logs/quality-gates
QG_LOG="logs/quality-gates/quality-gates_$(date -u +%Y%m%d_%H%M%S).log"
{
echo "🔍 Checking coverage (advisory only)..."
COVERAGE_PERCENT_XML=$(grep -o "line-rate=\"[0-9.]*\"" logs/tests/coverage/coverage.xml | head -1 | sed 's/line-rate=\"//' | sed 's/\"//')
if [ -n "$COVERAGE_PERCENT_XML" ] && [ "$COVERAGE_PERCENT_XML" != "0" ]; then
COVERAGE_PERCENT_INT=$(echo "$COVERAGE_PERCENT_XML * 100" | bc -l | cut -d. -f1)
else
COVERAGE_PERCENT_INT=0
fi
echo "📊 Line coverage (advisory): ${COVERAGE_PERCENT_INT}%"
if [ "$COVERAGE_PERCENT_INT" -lt 30 ]; then
echo "⚠️ Advisory: coverage below 30% — permitted under contract-first; prioritize contract/scenario gaps."
else
echo "✅ Advisory: coverage acceptable"
fi
} 2>&1 | tee "$QG_LOG"
- name: Upload quality-gates logs
if: always()
uses: actions/upload-artifact@v4
with:
name: quality-gates-logs
path: logs/quality-gates/
if-no-files-found: ignore
type-checking:
name: Type Checking (basedpyright)
runs-on: ubuntu-latest
needs: [changes, verify-module-signatures]
if: needs.changes.outputs.code_changed == 'true' && needs.changes.outputs.skip_tests_dev_to_main != 'true'
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install type-check dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run type checking
run: |
echo "🔍 Running basedpyright type checking..."
mkdir -p logs/type-check
TYPE_CHECK_LOG="logs/type-check/type-check_$(date -u +%Y%m%d_%H%M%S).log"
python -m basedpyright --pythonpath "$(python -c 'import sys; print(sys.executable)')" 2>&1 | tee "$TYPE_CHECK_LOG"
exit "${PIPESTATUS[0]:-$?}"
- name: Upload type-check logs
if: always()
uses: actions/upload-artifact@v4
with:
name: type-check-logs
path: logs/type-check/
if-no-files-found: ignore
linting:
name: Linting (ruff, pylint, safe-write guard)
runs-on: ubuntu-latest
needs: [changes, verify-module-signatures]
if: needs.changes.outputs.code_changed == 'true' && needs.changes.outputs.skip_tests_dev_to_main != 'true'
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install lint dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run linting
run: |
echo "🔍 Running linting checks..."
mkdir -p logs/lint
LINT_LOG="logs/lint/lint_$(date -u +%Y%m%d_%H%M%S).log"
{
set -euo pipefail
ruff format . --check
python -m basedpyright --level error --pythonpath "$(python -c 'import sys; print(sys.executable)')"
ruff check .
pylint src tests tools
python scripts/verify_safe_project_writes.py
} 2>&1 | tee "$LINT_LOG"
exit "${PIPESTATUS[0]:-$?}"
- name: Upload lint logs
if: always()
uses: actions/upload-artifact@v4
with:
name: lint-logs
path: logs/lint/
if-no-files-found: ignore
license-check:
name: License Compliance Gate
runs-on: ubuntu-latest
needs: [changes, verify-module-signatures]
if: needs.changes.outputs.code_changed == 'true' && needs.changes.outputs.license_inputs_changed == 'true' && needs.changes.outputs.skip_tests_dev_to_main != 'true'
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run license compliance gate
run: |
echo "🔍 Running license compliance gate..."
python scripts/check_license_compliance.py
security-audit:
name: Security Audit (pip-audit)
runs-on: ubuntu-latest
needs: [changes, verify-module-signatures]
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run CVE security audit
run: |
echo "🔍 Running CVE security audit..."
python scripts/security_audit_gate.py
package-validation:
name: Package Validation (uvx/pip)
runs-on: ubuntu-latest
needs: [tests, compat-py311, contract-first-ci, cli-validation, type-checking, linting, license-check, security-audit]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install build tools
run: |
python -m pip install --upgrade pip
pip install build twine "hatch" "virtualenv<21"
- name: Build package
run: |
echo "📦 Building SpecFact CLI package..."
hatch build
ls -lh dist/
- name: Validate package
run: |
echo "🔍 Validating package with twine..."
twine check dist/*
- name: Test installation
run: |
echo "📥 Testing pip installation..."
pip install dist/*.whl
specfact --version || echo "⚠️ CLI not yet fully implemented"
pip uninstall -y specfact-cli
- name: Upload package artifacts
uses: actions/upload-artifact@v4
with:
name: python-package
path: dist/
if-no-files-found: error
publish-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [package-validation]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
outputs:
published: ${{ steps.publish.outputs.published }}
version: ${{ steps.publish.outputs.version }}
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine packaging
# Note: tomllib is part of Python 3.11+ standard library
# This project requires Python >= 3.11, so no additional TOML library needed
- name: Make script executable
run: chmod +x .github/workflows/scripts/check-and-publish-pypi.sh
- name: Check version and publish to PyPI
id: publish
env:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
./.github/workflows/scripts/check-and-publish-pypi.sh
- name: Summary
if: always()
run: |
PUBLISHED="${{ steps.publish.outputs.published }}"
VERSION="${{ steps.publish.outputs.version }}"
{
echo "## PyPI Publication Summary"
echo "| Parameter | Value |"
echo "|-----------|--------|"
echo "| Version | $VERSION |"
echo "| Published | $PUBLISHED |"
if [ "$PUBLISHED" = "true" ]; then
echo "| Status | ✅ Published to PyPI |"
else
echo "| Status | ⏭️ Skipped (version not newer) |"
fi
} >> "$GITHUB_STEP_SUMMARY"
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [publish-pypi]
if: needs.publish-pypi.outputs.published == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitHub CLI
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Make scripts executable
run: |
chmod +x .github/workflows/scripts/generate-release-notes.sh
chmod +x .github/workflows/scripts/create-github-release.sh
chmod +x scripts/sign-module.sh
- name: Sign bundled module manifests (release hardening)
env:
SPECFACT_MODULE_PRIVATE_SIGN_KEY: ${{ secrets.SPECFACT_MODULE_PRIVATE_SIGN_KEY }}
SPECFACT_MODULE_PRIVATE_SIGN_KEY_PASSPHRASE: ${{ secrets.SPECFACT_MODULE_PRIVATE_SIGN_KEY_PASSPHRASE }}
run: |
if [ -z "${SPECFACT_MODULE_PRIVATE_SIGN_KEY}" ]; then
echo "❌ Missing required secret: SPECFACT_MODULE_PRIVATE_SIGN_KEY"
exit 1
fi
if [ -z "${SPECFACT_MODULE_PRIVATE_SIGN_KEY_PASSPHRASE}" ]; then
echo "❌ Missing required secret: SPECFACT_MODULE_PRIVATE_SIGN_KEY_PASSPHRASE"
exit 1
fi
python -m pip install --upgrade pip
python -m pip install pyyaml beartype icontract cryptography cffi
python - <<'PY'
import beartype
import cffi
import cryptography
import icontract
import yaml
print("✅ signing dependencies available:", yaml.__version__, cryptography.__version__, cffi.__version__, beartype.__version__, icontract.__version__)
PY
BASE_REF="${{ github.event.before }}"
if [ -z "$BASE_REF" ] || [ "$BASE_REF" = "0000000000000000000000000000000000000000" ]; then
BASE_REF="HEAD~1"
fi
git rev-parse --verify "$BASE_REF" >/dev/null 2>&1 || BASE_REF="HEAD~1"
echo "Using module-signing base ref: $BASE_REF"
python scripts/sign-modules.py --changed-only --base-ref "$BASE_REF" --bump-version patch --payload-from-filesystem
- name: Get version from PyPI publish step
id: get_version
run: |
# Use version from publish-pypi job output
VERSION="${{ needs.publish-pypi.outputs.version }}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "📦 Version: $VERSION"
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.get_version.outputs.version }}"
echo "🚀 Creating GitHub release for version $VERSION..."
./.github/workflows/scripts/create-github-release.sh "$VERSION"
- name: Release Summary
if: always()
run: |
VERSION="${{ steps.get_version.outputs.version }}"
{
echo "## GitHub Release Summary"
echo "| Parameter | Value |"
echo "|-----------|--------|"
echo "| Version | $VERSION |"
echo "| Status | ✅ Release created |"
echo "| URL | https://github.com/${{ github.repository }}/releases/tag/v${VERSION} |"
} >> "$GITHUB_STEP_SUMMARY"