-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (59 loc) · 2.22 KB
/
coverage-check.yml
File metadata and controls
70 lines (59 loc) · 2.22 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
name: Coverage Check
on:
pull_request:
branches: [ "**" ]
permissions:
contents: read
pull-requests: read
jobs:
coverage-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Get base branch coverage
run: |
git checkout origin/mainline
pip install -e ".[dev]"
python -m pytest tests/ -m "not integration" --cov=src --cov-report=json:coverage-base.json --tb=no -q || true
BASE_COVERAGE=$(python -c "import json; print(json.load(open('coverage-base.json'))['totals']['percent_covered'])")
echo "BASE_COVERAGE=$BASE_COVERAGE" >> $GITHUB_ENV
echo "Base branch coverage: $BASE_COVERAGE%"
- name: Get PR coverage
run: |
git checkout ${{ github.event.pull_request.head.sha }}
pip install -e ".[dev]"
python -m pytest tests/ -m "not integration" --cov=src --cov-report=json:coverage-pr.json --tb=no -q || true
PR_COVERAGE=$(python -c "import json; print(json.load(open('coverage-pr.json'))['totals']['percent_covered'])")
echo "PR_COVERAGE=$PR_COVERAGE" >> $GITHUB_ENV
echo "PR branch coverage: $PR_COVERAGE%"
- name: Compare coverage and enforce increase
run: |
python -c "
import sys
base = float('${{ env.BASE_COVERAGE }}')
pr = float('${{ env.PR_COVERAGE }}')
diff = pr - base
print(f'Coverage Report')
print(f'Base coverage: {base:.2f}%')
print(f'PR coverage: {pr:.2f}%')
print(f'Coverage change: {diff:+.2f}%')
print()
if diff < -0.01: # Allow small floating point differences
print('❌ Coverage decreased! This PR reduces test coverage.')
print('Please add tests to maintain or improve coverage.')
sys.exit(1)
elif diff > 0.01:
print('✅ Coverage increased! Great job improving test coverage.')
else:
print('➡️ Coverage unchanged (within tolerance).')
"