Repository navigation
529 lines (466 loc) · 21.6 KB
/
Copy pathci.yml
File metadata and controls
529 lines (466 loc) · 21.6 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
---
# Pullbox CI Pipeline
# Quality gate — lint, typecheck, test, migration check, accessibility, E2E.
# GitHub Actions is the canonical PR CI runner. Pull request pushes run a
# cheap preflight until same-repository maintainer PRs receive `ci:full`.
#
# Security: All actions pinned to full SHA. No pull_request_target.
# See: docs/development/INFRASTRUCTURE.md
name: CI
on:
pull_request:
branches:
- develop
- main
types:
- opened
- synchronize
- reopened
- ready_for_review
- labeled
- unlabeled
workflow_dispatch:
inputs:
e2e_diagnostics:
description: Retain E2E failure video and traces
required: false
type: boolean
default: false
permissions:
contents: read
concurrency:
group: ci-${{ github.event.pull_request.number || github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
E2E_WORKERS: "3"
E2E_VIDEO_MODE: "${{ github.event_name == 'workflow_dispatch' && inputs.e2e_diagnostics && 'retain-on-failure' || 'off' }}"
PULLBOX_E2E_TRACE: "${{ github.event_name == 'workflow_dispatch' && inputs.e2e_diagnostics && 'true' || 'false' }}"
PYTHON_DEFAULT: "3.14"
PYTEST_WORKERS: "5"
jobs:
release_sync_check:
name: Release Sync Check
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
is_sync: ${{ steps.release-sync.outputs.is_sync }}
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Detect safe post-release sync PR
id: release-sync
env:
RELEASE_SYNC_EVENT_NAME: ${{ github.event_name }}
RELEASE_SYNC_BASE_REF: ${{ github.base_ref || '' }}
RELEASE_SYNC_HEAD_REF: ${{ github.head_ref || '' }}
RELEASE_SYNC_REPOSITORY: ${{ github.repository }}
RELEASE_SYNC_HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name || '' }}
RELEASE_SYNC_ACTOR: ${{ github.actor }}
run: |
git fetch --no-tags origin main:refs/remotes/origin/main
if ! git cat-file -e origin/main:.github/scripts/validate-release-sync-pr.py 2>/dev/null; then
echo "is_sync=false" >> "$GITHUB_OUTPUT"
echo "reason=trusted release sync validator is not available on origin/main yet" >> "$GITHUB_OUTPUT"
echo "release_sync=false"
echo "reason=trusted release sync validator is not available on origin/main yet"
exit 0
fi
git show origin/main:.github/scripts/validate-release-sync-pr.py > /tmp/pullbox-release-sync-validator.py
python /tmp/pullbox-release-sync-validator.py
full_ci_check:
name: Full CI Gate
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
run_full: ${{ steps.gate.outputs.run_full }}
label_required: ${{ steps.gate.outputs.label_required }}
permissions:
contents: read
steps:
- name: Resolve full CI gate
id: gate
run: |
echo "run_full=${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && !github.event.pull_request.draft && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]' || startsWith(github.event.pull_request.head.ref, 'dependabot/') || contains(github.event.pull_request.labels.*.name, 'ci:full'))) }}" >> "$GITHUB_OUTPUT"
echo "label_required=${{ github.event_name == 'pull_request' && !github.event.pull_request.draft && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' && !startsWith(github.event.pull_request.head.ref, 'dependabot/') && !contains(github.event.pull_request.labels.*.name, 'ci:full') }}" >> "$GITHUB_OUTPUT"
# ──────────────────────────────────────────────
# Job 1: Quality Gate (~45s)
# ──────────────────────────────────────────────
quality-gate:
name: Quality Gate
needs: [release_sync_check, full_ci_check]
if: needs.release_sync_check.outputs.is_sync != 'true'
runs-on: ${{ fromJSON(((github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')) || vars.PULLBOX_CHECKS_RUNNER == 'github-hosted') && '["ubuntu-latest"]' || '["self-hosted","Linux","X64","ci"]') }}
timeout-minutes: 15
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ env.PYTHON_DEFAULT }}
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: "24"
- name: Setup runner-local venv
run: .github/scripts/setup-runner-venv.sh "dev"
- name: Runner preflight
run: .github/scripts/preflight-runner.sh python node
- name: Ruff lint
run: ruff check src/ tests/
- name: Ruff format check
run: ruff format --check src/ tests/
- name: Install Tailwind
run: npm ci
- name: Rebuild Tailwind CSS
run: npm run css:build
- name: Check for uncommitted CSS changes
run: |
git diff --exit-code src/pullbox/ui/static/css/tailwind.css || {
echo "::error::Tailwind CSS output is stale. Run 'make css-build' and commit the result."
exit 1
}
echo "✅ Tailwind CSS is up to date"
# ──────────────────────────────────────────────
# Job 2: Type Check (~1-2 min)
# ──────────────────────────────────────────────
typecheck:
name: Type Check
needs: [release_sync_check, full_ci_check]
if: needs.release_sync_check.outputs.is_sync != 'true' && needs.full_ci_check.outputs.run_full == 'true'
runs-on: ${{ fromJSON(((github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')) || vars.PULLBOX_CHECKS_RUNNER == 'github-hosted') && '["ubuntu-latest"]' || '["self-hosted","Linux","X64","ci"]') }}
timeout-minutes: 15
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ env.PYTHON_DEFAULT }}
- name: Setup runner-local venv
run: .github/scripts/setup-runner-venv.sh "dev"
- name: Runner preflight
run: .github/scripts/preflight-runner.sh python
- name: Mypy
run: mypy src/pullbox/
# ──────────────────────────────────────────────
# Job 3: Tests + Coverage (matrix: 3.12, 3.13, 3.14)
# Every version runs the complete suite and publishes coverage. The blocking
# 90% release gate follows the production/default Python 3.14 runtime.
# ──────────────────────────────────────────────
test:
name: Test (Python ${{ matrix.python-version }})
runs-on: ${{ fromJSON(((github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')) || vars.PULLBOX_CHECKS_RUNNER == 'github-hosted') && '["ubuntu-latest"]' || '["self-hosted","Linux","X64","ci"]') }}
needs: [release_sync_check, full_ci_check, quality-gate, typecheck, alembic-check]
if: needs.release_sync_check.outputs.is_sync != 'true' && needs.full_ci_check.outputs.run_full == 'true'
timeout-minutes: 30
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- python-version: "3.12"
coverage_fail_under: 0
- python-version: "3.13"
coverage_fail_under: 0
- python-version: "3.14"
coverage_fail_under: 90
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ matrix.python-version }}
- name: Setup runner-local venv
run: .github/scripts/setup-runner-venv.sh "dev"
- name: Runner preflight
run: .github/scripts/preflight-runner.sh python
- name: Run tests with coverage
run: |
pytest tests/ \
--ignore=tests/e2e \
-n "${PYTEST_WORKERS}" \
--dist=worksteal \
--cov=pullbox \
--cov-report=xml \
--cov-report=term-missing \
--cov-fail-under="${COVERAGE_FAIL_UNDER}" \
--junitxml=test-results.xml \
-v
env:
COVERAGE_FAIL_UNDER: ${{ matrix.coverage_fail_under }}
PULLBOX_SECRET_KEY: test-ci-key
PYTEST_WORKERS: ${{ env.PYTEST_WORKERS }}
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage-report-py${{ matrix.python-version }}
path: coverage.xml
if-no-files-found: error
retention-days: 30
- name: Upload test results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: test-results-py${{ matrix.python-version }}
path: test-results.xml
retention-days: 30
# ──────────────────────────────────────────────
# Job 4: Alembic Migration Sanity Check
# ──────────────────────────────────────────────
alembic-check:
name: Migration Check
needs: [release_sync_check, full_ci_check]
if: needs.release_sync_check.outputs.is_sync != 'true' && needs.full_ci_check.outputs.run_full == 'true'
runs-on: ${{ fromJSON(((github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')) || vars.PULLBOX_CHECKS_RUNNER == 'github-hosted') && '["ubuntu-latest"]' || '["self-hosted","Linux","X64","ci"]') }}
timeout-minutes: 15
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ env.PYTHON_DEFAULT }}
- name: Setup runner-local venv
run: .github/scripts/setup-runner-venv.sh "dev"
- name: Runner preflight
run: .github/scripts/preflight-runner.sh python
- name: Verify migrations apply from empty DB
run: |
alembic -c alembic/alembic.ini upgrade head
echo "✅ Migrations applied successfully"
alembic -c alembic/alembic.ini downgrade base
echo "✅ Downgrade to base successful"
env:
PULLBOX_SECRET_KEY: test-ci-key
PULLBOX_DB_URL: "sqlite+aiosqlite:///test_migration.db"
- name: Verify app boots after migration
run: |
alembic -c alembic/alembic.ini upgrade head
timeout 10 python -c "
import asyncio
from pullbox.app import create_app
app = create_app()
print('✅ App factory created successfully')
"
env:
PULLBOX_SECRET_KEY: test-ci-key
PULLBOX_DB_URL: "sqlite+aiosqlite:///test_boot.db"
# ──────────────────────────────────────────────
# Job 5: Accessibility Checks (contrast + WCAG scans in Chromium)
# ──────────────────────────────────────────────
accessibility:
name: Accessibility Checks
runs-on: ${{ fromJSON(((github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')) || vars.PULLBOX_CHECKS_RUNNER == 'github-hosted') && '["ubuntu-latest"]' || '["self-hosted","Linux","X64","checks"]') }}
needs: [release_sync_check, full_ci_check, quality-gate, typecheck, alembic-check]
if: needs.release_sync_check.outputs.is_sync != 'true' && needs.full_ci_check.outputs.run_full == 'true'
timeout-minutes: 30
permissions:
contents: read
env:
PULLBOX_SECRET_KEY: test-ci-key
PULLBOX_DB_URL: "sqlite+aiosqlite:///test_a11y_${{ github.run_id }}_${{ github.run_attempt }}.db"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ env.PYTHON_DEFAULT }}
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: "24"
- name: Install Node dependencies
run: npm ci
- name: Setup runner-local venv
run: .github/scripts/setup-runner-venv.sh "dev,e2e"
- name: Runner preflight
run: .github/scripts/preflight-runner.sh python node playwright
- name: Install Playwright Chromium
run: playwright install chromium
- name: Run contrast audit
run: python scripts/check_ui_contrast.py
- name: Run accessibility browser tests
run: |
mkdir -p test-results/accessibility test-results/e2e
pytest tests/e2e/ \
-v \
-m accessibility \
--browser chromium \
--video "${E2E_VIDEO_MODE}" \
--screenshot only-on-failure \
--full-page-screenshot \
--output=test-results/e2e \
--junitxml=test-results/accessibility-junit.xml
- name: Upload accessibility JUnit results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: accessibility-results
path: test-results/accessibility-junit.xml
retention-days: 14
- name: Upload accessibility failure artifacts
if: failure() || cancelled()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: accessibility-artifacts
path: test-results/
if-no-files-found: ignore
retention-days: 14
- name: Accessibility job summary
if: always()
run: |
{
echo "## Accessibility Checks"
echo ""
echo "- Contrast audit: semantic color token gate"
echo "- Browser audit: marked accessibility E2E coverage"
echo "- Failure artifacts: uploaded only when the job fails or is canceled"
} >> "$GITHUB_STEP_SUMMARY"
# ──────────────────────────────────────────────
# Job 6: E2E Tests (per-browser isolated pytest sessions, after tests pass)
# ──────────────────────────────────────────────
e2e:
name: E2E Tests (${{ matrix.browser }})
runs-on: ${{ fromJSON(((github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')) || vars.PULLBOX_CHECKS_RUNNER == 'github-hosted') && '["ubuntu-latest"]' || '["self-hosted","Linux","X64","ci"]') }}
needs: [release_sync_check, full_ci_check, test]
if: needs.release_sync_check.outputs.is_sync != 'true' && needs.full_ci_check.outputs.run_full == 'true'
timeout-minutes: 30
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- browser: chromium
pytest_extra_args: ""
- browser: firefox
pytest_extra_args: "--durations=25 --durations-min=1.0"
env:
PULLBOX_SECRET_KEY: test-ci-key
PULLBOX_RATE_LIMIT_ENABLED: "false"
PULLBOX_DB_URL: "sqlite+aiosqlite:///test_e2e_${{ github.run_id }}_${{ github.run_attempt }}_${{ matrix.browser }}.db"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ env.PYTHON_DEFAULT }}
- name: Setup runner-local venv
run: .github/scripts/setup-runner-venv.sh "dev,e2e"
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: "24"
- name: Install Node dependencies
run: npm ci
- name: Runner preflight
run: .github/scripts/preflight-runner.sh python node playwright
- name: Install Playwright browsers
run: playwright install ${{ matrix.browser }}
- name: Run E2E tests
run: |
mkdir -p test-results/e2e test-results/playwright
pytest tests/e2e/ \
-v \
-m "not accessibility" \
-n "${E2E_WORKERS}" \
--dist=worksteal \
--browser ${{ matrix.browser }} \
${{ matrix.pytest_extra_args }} \
--video "${E2E_VIDEO_MODE}" \
--screenshot only-on-failure \
--full-page-screenshot \
--output=test-results/e2e \
--junitxml=test-results/e2e-junit.xml
- name: Upload E2E JUnit results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: e2e-results-${{ matrix.browser }}
path: test-results/e2e-junit.xml
retention-days: 14
- name: Upload Playwright failure artifacts
if: failure() || cancelled()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: playwright-artifacts-${{ matrix.browser }}
path: test-results/
if-no-files-found: ignore
retention-days: 14
- name: E2E job summary
if: always()
run: |
{
echo "## E2E Checks (${{ matrix.browser }})"
echo ""
echo "- Browser: ${{ matrix.browser }}"
echo "- Failure artifacts: uploaded only when the job fails or is canceled"
} >> "$GITHUB_STEP_SUMMARY"
# Stable aggregate required check for branch rulesets.
ci-required:
name: CI Required
runs-on: ubuntu-latest
needs:
- release_sync_check
- full_ci_check
- quality-gate
- typecheck
- alembic-check
- test
- accessibility
- e2e
if: always()
timeout-minutes: 5
permissions:
contents: read
steps:
- name: Verify required CI jobs
env:
NEEDS_CONTEXT: ${{ toJson(needs) }}
RELEASE_SYNC_PR: ${{ needs.release_sync_check.outputs.is_sync }}
RUN_FULL: ${{ needs.full_ci_check.outputs.run_full }}
LABEL_REQUIRED: ${{ needs.full_ci_check.outputs.label_required }}
run: |
python - <<'PY'
import json
import os
import sys
needs = json.loads(os.environ["NEEDS_CONTEXT"])
release_sync_pr = os.environ["RELEASE_SYNC_PR"].lower() == "true"
run_full = os.environ["RUN_FULL"].lower() == "true"
label_required = os.environ["LABEL_REQUIRED"].lower() == "true"
if release_sync_pr:
release_sync = needs.get("release_sync_check", {}).get("result")
if release_sync != "success":
print(f"Release sync validation failed: {release_sync}", file=sys.stderr)
sys.exit(1)
unexpected = {
name: info.get("result")
for name, info in needs.items()
if name != "release_sync_check" and info.get("result") not in {"skipped", "success"}
}
if unexpected:
print(f"Release sync fast path saw unexpected job results: {unexpected}", file=sys.stderr)
sys.exit(1)
print("Release sync fast path validated; heavyweight CI jobs intentionally skipped.")
sys.exit(0)
if not run_full:
preflight = needs.get("quality-gate", {}).get("result")
if preflight != "success":
print(f"CI preflight did not pass: {preflight}", file=sys.stderr)
sys.exit(1)
if label_required:
print("CI preflight passed. Add the ci:full label when the PR is ready for the full required gate.", file=sys.stderr)
else:
print("CI preflight passed, but full CI was intentionally not requested for this PR state.", file=sys.stderr)
sys.exit(1)
failed = {
name: info.get("result")
for name, info in needs.items()
if info.get("result") != "success"
}
if failed:
print(f"Required CI jobs did not all pass: {failed}", file=sys.stderr)
sys.exit(1)
print("All required CI jobs passed.")
PY