-
Notifications
You must be signed in to change notification settings - Fork 0
561 lines (474 loc) · 17.3 KB
/
Copy pathci.yml
File metadata and controls
561 lines (474 loc) · 17.3 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
name: CI Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
PYTHON_VERSION: "3.14"
PYTHONDONTWRITEBYTECODE: 1
FORCE_COLOR: 1
jobs:
# ============================================================================
# STAGE 1: Code Quality Gates (fail-fast)
# ============================================================================
lint:
name: Lint and Type Check
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
ref: ${{ github.head_ref }}
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v5
with:
path: .venv
key: venv-lint-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-lint-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --only dev --no-interaction
- name: Lint with Ruff
run: poetry run ruff check .
- name: Auto-format with Ruff
if: github.event_name == 'pull_request'
run: |
poetry run ruff format .
if ! git diff --quiet; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -am "style: auto-format with ruff"
git push
fi
- name: Check code formatting with Ruff
run: poetry run ruff format --check --diff .
- name: Type checking with mypy
run: poetry run mypy app/
# ============================================================================
# STAGE 2: Test Matrix (parallel execution)
# ============================================================================
test-unit:
name: Unit Tests
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --with dev --no-interaction
- name: Run unit tests
run: |
poetry run pytest tests/ \
-m "not integration and not slow and not benchmark and not property" \
--cov=app \
--cov-report= \
--cov-fail-under=0 \
--junitxml=test-results-unit.xml \
--benchmark-disable \
-n auto \
-v
- name: Rename coverage data
run: mv .coverage .coverage.unit
- name: Upload coverage data
uses: actions/upload-artifact@v7
with:
name: coverage-data-unit
path: .coverage.unit
include-hidden-files: true
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results-unit
path: test-results-unit.xml
test-integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --with dev --no-interaction
- name: Run integration tests
run: |
poetry run pytest tests/ \
-m "integration" \
--cov=app \
--cov-report= \
--cov-fail-under=0 \
--junitxml=test-results-integration.xml \
-v
- name: Rename coverage data
run: mv .coverage .coverage.integration
- name: Upload coverage data
uses: actions/upload-artifact@v7
with:
name: coverage-data-integration
path: .coverage.integration
include-hidden-files: true
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results-integration
path: test-results-integration.xml
test-security:
name: Security Scan
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --only dev --no-interaction
- name: Upgrade pip to patched version
run: poetry run pip install --upgrade pip
- name: Audit dependencies for known vulnerabilities
run: poetry run pip-audit
- name: Bandit security lint
run: poetry run ruff check . --select S
test-property:
name: Property-Based Tests
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --with dev --no-interaction
- name: Run property-based tests
run: |
poetry run pytest tests/ \
-m "property" \
--cov=app \
--cov-report= \
--cov-fail-under=0 \
--junitxml=test-results-property.xml \
-v
- name: Rename coverage data
run: mv .coverage .coverage.property
- name: Upload coverage data
uses: actions/upload-artifact@v7
with:
name: coverage-data-property
path: .coverage.property
include-hidden-files: true
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results-property
path: test-results-property.xml
test-performance:
name: Performance Tests
runs-on: ubuntu-latest
needs: lint
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --with dev --no-interaction
- name: Run performance tests
run: |
poetry run pytest tests/ \
-m "benchmark or slow" \
--junitxml=test-results-performance.xml \
--timeout=120 \
--no-cov \
-v
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results-performance
path: test-results-performance.xml
test-e2e:
name: E2E Tests (Playwright)
runs-on: ubuntu-latest
needs: lint
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
browser: [chromium, firefox]
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --with dev --no-interaction
- name: Install Playwright browser (${{ matrix.browser }})
run: poetry run playwright install ${{ matrix.browser }} --with-deps
- name: Start Streamlit server
run: poetry run streamlit run main.py --server.headless=true --server.port=8501 > /tmp/streamlit.log 2>&1 &
- name: Wait for server to be ready
run: |
poetry run python - <<'EOF'
import sys
import time
import urllib.error
import urllib.request
url = "http://localhost:8501"
for attempt in range(30):
try:
urllib.request.urlopen(url, timeout=2)
print(f"Server ready after {attempt + 1}s", flush=True)
sys.exit(0)
except (urllib.error.URLError, OSError):
time.sleep(1)
print("ERROR: Streamlit server did not start within 30 seconds.")
sys.exit(1)
EOF
- name: Run E2E tests (${{ matrix.browser }})
run: |
mkdir -p test-results-e2e-${{ matrix.browser }}/artifacts
poetry run pytest tests/e2e/ \
-m "e2e" \
-p no:xdist \
--browser ${{ matrix.browser }} \
--screenshot only-on-failure \
--tracing retain-on-failure \
--output test-results-e2e-${{ matrix.browser }}/artifacts \
--junitxml=test-results-e2e-${{ matrix.browser }}.xml \
--html=test-results-e2e-${{ matrix.browser }}/report.html \
--self-contained-html \
--reruns 2 \
--reruns-delay 1 \
--only-rerun "TimeoutError|Page closed|Target closed" \
--timeout=60 \
-v
- name: Link HTML report from job summary
if: always()
run: |
echo "## E2E report — ${{ matrix.browser }}" >> "$GITHUB_STEP_SUMMARY"
echo "Download \`test-results-e2e-${{ matrix.browser }}\` artifact and open \`report.html\`." >> "$GITHUB_STEP_SUMMARY"
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results-e2e-${{ matrix.browser }}
path: |
test-results-e2e-${{ matrix.browser }}/
test-results-e2e-${{ matrix.browser }}.xml
retention-days: 7
- name: Upload E2E artifacts on failure
uses: actions/upload-artifact@v7
if: failure()
with:
name: e2e-artifacts-${{ matrix.browser }}
path: |
test-results-e2e-${{ matrix.browser }}/
/tmp/streamlit.log
retention-days: 7
# ============================================================================
# STAGE 3: Coverage Report and Summary
# ============================================================================
coverage-report:
name: Coverage Report
runs-on: ubuntu-latest
needs: [test-unit, test-integration, test-security, test-property, test-performance, test-e2e]
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
run: poetry install --with dev --no-interaction
- name: Download all coverage data
uses: actions/download-artifact@v8
continue-on-error: true
with:
pattern: coverage-data-*
merge-multiple: true
path: .
- name: Combine and generate coverage report
run: |
poetry run coverage combine
poetry run coverage json
poetry run coverage html
poetry run coverage xml
echo "## Coverage Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f coverage.json ]; then
COVERAGE=$(python3 -c "import json; data=json.load(open('coverage.json')); print(data['totals']['percent_covered_display'])")
echo "**Total Coverage: ${COVERAGE}%**" >> $GITHUB_STEP_SUMMARY
fi
- name: Upload final coverage report
uses: actions/upload-artifact@v7
with:
name: coverage-report-final
path: |
coverage.xml
coverage.json
htmlcov/
retention-days: 30
# ============================================================================
# STAGE 4: CI Summary
# ============================================================================
ci-summary:
name: CI Summary
runs-on: ubuntu-latest
needs: [lint, test-unit, test-integration, test-security, test-property, test-performance, test-e2e]
if: always()
steps:
- name: Generate CI Summary
run: |
echo "## CI Pipeline Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Stage | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Lint and Type Check | ${{ needs.lint.result == 'success' && 'PASSED' || 'FAILED' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Unit Tests | ${{ needs.test-unit.result == 'success' && 'PASSED' || 'FAILED' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Integration Tests | ${{ needs.test-integration.result == 'success' && 'PASSED' || 'FAILED' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security Scan | ${{ needs.test-security.result == 'success' && 'PASSED' || 'FAILED' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Property Tests | ${{ needs.test-property.result == 'success' && 'PASSED' || 'FAILED' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Performance Tests | ${{ needs.test-performance.result == 'success' && 'PASSED' || 'FAILED' }} |" >> $GITHUB_STEP_SUMMARY
echo "| E2E Tests (Playwright) | ${{ needs.test-e2e.result == 'success' && 'PASSED' || 'FAILED' }} |" >> $GITHUB_STEP_SUMMARY
- name: Fail if any job failed
if: |
needs.lint.result == 'failure' ||
needs.test-unit.result == 'failure' ||
needs.test-integration.result == 'failure' ||
needs.test-security.result == 'failure' ||
needs.test-property.result == 'failure' ||
needs.test-performance.result == 'failure' ||
needs.test-e2e.result == 'failure'
run: exit 1