-
Notifications
You must be signed in to change notification settings - Fork 4
179 lines (156 loc) · 5.3 KB
/
python_tests.yml
File metadata and controls
179 lines (156 loc) · 5.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
name: Python Tests
on:
push:
paths-ignore:
- 'docs/**'
- '*.md'
- 'examples/**'
- 'benchmarks/**'
- '.gitignore'
- 'LICENSE'
branches: [main, master]
pull_request:
paths-ignore:
- 'docs/**'
- '*.md'
- 'examples/**'
- 'benchmarks/**'
- '.gitignore'
- 'LICENSE'
branches: [main, master]
workflow_dispatch:
jobs:
python-test:
name: ${{ matrix.os }} / Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python-version: "3.11"
- os: ubuntu-latest
python-version: "3.12"
- os: ubuntu-latest
python-version: "3.13"
- os: ubuntu-latest
python-version: "3.14"
- os: macos-14
python-version: "3.12"
- os: windows-latest
python-version: "3.12"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install OS specific dependencies
if: matrix.os == 'macos-14'
run: |
brew update
brew install libomp
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
_rust/target
key: ${{ runner.os }}-cargo-${{ hashFiles('_rust/Cargo.lock') }}
- name: Create virtual environment with uv
run: uv venv
- name: Install maturin
run: uv pip install maturin
- name: Build Rust extension
shell: bash
working-directory: _rust
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
source ../.venv/Scripts/activate
else
source ../.venv/bin/activate
fi
maturin develop --release
- name: Install project with test dependencies
run: uv sync --extra test
- name: Run Python tests with coverage
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
shell: bash
working-directory: stratum
run: |
source ../.venv/bin/activate
pytest -v --cov=stratum --cov-config=../pyproject.toml --cov-branch --cov-report=term-missing --cov-report=xml tests
- name: Run Python tests
if: matrix.os != 'ubuntu-latest' || matrix.python-version != '3.12'
shell: bash
working-directory: stratum
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
source ../.venv/Scripts/activate
else
source ../.venv/bin/activate
fi
pytest -v tests
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
uses: codecov/codecov-action@v4
with:
file: ./stratum/coverage.xml
flags: unittests
name: codecov-ubuntu-py3.12
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
- name: Upload coverage artifact
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: ./stratum/coverage.xml
retention-days: 1
coverage-check:
name: Coverage Threshold Check
runs-on: ubuntu-latest
needs: python-test
if: needs.python-test.result == 'success'
steps:
- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
name: coverage-report
- name: Check coverage threshold
run: |
python3 -c "
import xml.etree.ElementTree as ET
import sys
tree = ET.parse('coverage.xml')
root = tree.getroot()
# Get coverage percentage from XML
line_rate = float(root.get('line-rate', 0))
branch_rate_str = root.get('branch-rate')
if branch_rate_str is not None:
branch_rate = float(branch_rate_str)
coverage_percent = (line_rate + branch_rate) / 2 * 100
print(f'Line coverage: {line_rate * 100:.2f}%')
print(f'Branch coverage: {branch_rate * 100:.2f}%')
print(f'Overall coverage: {coverage_percent:.2f}%')
else:
# Fallback to line coverage only if branch coverage not available
coverage_percent = line_rate * 100
print(f'Line coverage: {line_rate * 100:.2f}%')
print(f'Branch coverage: Not available (use --cov-branch flag)')
print(f'Overall coverage: {coverage_percent:.2f}% (line coverage only)')
# Coverage threshold (adjust as needed)
threshold = 80.0
print(f'Threshold: {threshold}%')
if coverage_percent < threshold:
print(f'ERROR: Coverage {coverage_percent:.2f}% is below threshold {threshold}%')
sys.exit(1)
else:
print(f'SUCCESS: Coverage {coverage_percent:.2f}% meets threshold {threshold}%')
"