-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (114 loc) · 3.29 KB
/
coverage.yml
File metadata and controls
131 lines (114 loc) · 3.29 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
name: Code Coverage
on:
push:
branches: [main]
paths:
- 'cli/**'
- 'tests/**'
- 'pytest.ini'
- 'setup.cfg'
pull_request:
branches: [main]
paths:
- 'cli/**'
- 'tests/**'
- 'pytest.ini'
- 'setup.cfg'
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
jobs:
coverage:
name: Test Coverage Report
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .
pip install pytest pytest-cov coverage
- name: Run tests with coverage
run: |
pytest tests/ \
--cov=cli \
--cov-report=term-missing \
--cov-report=html:htmlcov \
--cov-report=xml \
--cov-report=json \
--cov-branch \
-v
- name: Check coverage threshold
run: |
coverage report --fail-under=75
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Generate coverage badge
run: |
pip install coverage-badge
coverage-badge -o coverage.svg -f
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-reports
path: |
htmlcov/
coverage.xml
coverage.json
coverage.svg
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
- name: Archive coverage results
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-archive-${{ github.run_number }}
path: htmlcov/
coverage-check:
name: Coverage Threshold Check
runs-on: ubuntu-latest
needs: coverage
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download coverage reports
uses: actions/download-artifact@v4
with:
name: coverage-reports
- name: Display coverage summary
run: |
echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- name: Fail if coverage too low
run: |
if grep -q "statements=" coverage.json; then
python -c "
import json
with open('coverage.json') as f:
data = json.load(f)
total_coverage = data['totals']['percent_covered']
if total_coverage < 75:
print(f'Coverage {total_coverage}% is below 75% threshold')
exit(1)
else:
print(f'✓ Coverage {total_coverage}% meets threshold')
"
fi