-
Notifications
You must be signed in to change notification settings - Fork 36
348 lines (293 loc) · 12.7 KB
/
coverage.yml
File metadata and controls
348 lines (293 loc) · 12.7 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
name: Coverage
on:
pull_request:
branches:
- main
- release*
- release/*
- release-*
permissions:
actions: read
contents: read
pull-requests: write
jobs:
coverage:
name: Coverage
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
- os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Post Coverage Started Comment (Linux)
if: startsWith(matrix.os, 'ubuntu')
uses: marocchino/sticky-pull-request-comment@v2
with:
header: coverage-linux
message: |
## Test Coverage Report (Linux)
:hourglass_flowing_sand: **Coverage analysis in progress...**
This comment will be updated with results when the analysis completes.
- name: Post Coverage Started Comment (Windows)
if: startsWith(matrix.os, 'windows')
uses: marocchino/sticky-pull-request-comment@v2
with:
header: coverage-windows
message: |
## Test Coverage Report (Windows)
:hourglass_flowing_sand: **Coverage analysis in progress...**
This comment will be updated with results when the analysis completes.
- name: Set Python to PATH
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Add Conda to PATH (Windows)
if: startsWith(matrix.os, 'windows')
run: |
$path = $env:PATH + ";" + $env:CONDA + "\condabin"
echo "PATH=$path" >> $env:GITHUB_ENV
- name: Add Conda to PATH (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: echo "PATH=$PATH:$CONDA/condabin" >> $GITHUB_ENV
shell: bash
- name: Check Conda version
run: conda info --all
- name: Create Conda Environments
run: |
conda create -n test-env1 python=3.12 -y
conda create -n test-env-no-python -y
conda create -p ./prefix-envs/.conda1 python=3.12 -y
conda create -p ./prefix-envs/.conda-nopy -y
- name: Install pipenv
run: pip install pipenv
- name: Check pipenv version
run: pipenv --version
- name: Create a Pipenv Environment
run: pipenv install
- name: Install virtualenvwrapper (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
pip install virtualenvwrapper
echo "WORKON_HOME=$HOME/.virtualenvs" >> $GITHUB_ENV
mkdir -p $HOME/.virtualenvs
source virtualenvwrapper.sh
mkvirtualenv venv_wrapper_env1
shell: bash
- name: Install virtualenvwrapper-win (Windows)
if: startsWith(matrix.os, 'windows')
run: |
pip install virtualenvwrapper-win
echo "WORKON_HOME=$HOME/.virtualenvs" >> $GITHUB_ENV
shell: bash
- name: Install pyenv (Windows)
if: startsWith(matrix.os, 'windows')
run: |
choco install pyenv-win -y
echo "PATH=$PATH;$HOME/.pyenv/pyenv-win/bin;$HOME/.pyenv/pyenv-win/shims" >> $GITHUB_ENV
echo "PYENV_ROOT=$HOME/.pyenv" >> $GITHUB_ENV
shell: bash
- name: Install pyenv and pyenv-virtualenv (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
curl https://pyenv.run | bash
echo "PYENV_ROOT=$HOME/.pyenv" >> $GITHUB_ENV
echo "PATH=$HOME/.pyenv/bin:$PATH" >> $GITHUB_ENV
shell: bash
- name: Check Pyenv version
run: pyenv --version
shell: bash
- name: Install Pyenv Python(s) (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
pyenv install --list
pyenv install 3.13:latest 3.12:latest 3.9:latest
shell: bash
- name: Install Pyenv Python(s) (Windows)
if: startsWith(matrix.os, 'windows')
run: |
pyenv install --list
pyenv install 3.10.5 3.8.10
shell: bash
- name: Create pyenv-virtualenv envs (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
eval "$(pyenv virtualenv-init -)"
pyenv virtualenv 3.12 pyenv-virtualenv-env1
shell: bash
- name: Create .venv
run: python -m venv .venv
shell: bash
- name: Create .venv2
run: python -m venv .venv2
shell: bash
- name: Install Pixi
uses: prefix-dev/setup-pixi@v0.8.1
with:
run-install: false
- name: Create Pixi environments
run: |
pixi init
pixi add python
pixi add --feature dev python
pixi project environment add --feature dev dev
pixi install --environment dev
shell: bash
- name: Rust Tool Chain setup
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Cargo Fetch
run: cargo fetch
shell: bash
- name: Run Tests with Coverage
run: cargo llvm-cov --features ci --lcov --output-path lcov.info -- --nocapture --test-threads=1
env:
RUST_BACKTRACE: 1
RUST_LOG: trace
shell: bash
- name: Upload PR Coverage Artifact
uses: actions/upload-artifact@v4
with:
name: coverage-pr-${{ matrix.os }}
path: lcov.info
- name: Download Baseline Coverage
uses: dawidd6/action-download-artifact@v6
id: download-baseline
continue-on-error: true
with:
workflow: coverage-baseline.yml
branch: main
name: coverage-baseline-${{ matrix.os }}
path: baseline-coverage
- name: Install lcov (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get update && sudo apt-get install -y lcov
- name: Install lcov (Windows)
if: startsWith(matrix.os, 'windows')
run: choco install lcov -y
shell: bash
- name: Generate Coverage Report (Linux)
if: startsWith(matrix.os, 'ubuntu')
id: coverage-linux
run: |
# Extract PR coverage
PR_LINES=$(lcov --summary lcov.info 2>&1 | grep "lines" | sed 's/.*: //' | sed 's/%.*//' | tr -d ' ')
PR_FUNCTIONS=$(lcov --summary lcov.info 2>&1 | grep "functions" | sed 's/.*: //' | sed 's/%.*//' | tr -d ' ')
# Extract baseline coverage (default to 0 if not available)
if [ -f baseline-coverage/lcov.info ]; then
BASELINE_LINES=$(lcov --summary baseline-coverage/lcov.info 2>&1 | grep "lines" | sed 's/.*: //' | sed 's/%.*//' | tr -d ' ')
BASELINE_FUNCTIONS=$(lcov --summary baseline-coverage/lcov.info 2>&1 | grep "functions" | sed 's/.*: //' | sed 's/%.*//' | tr -d ' ')
else
BASELINE_LINES="0"
BASELINE_FUNCTIONS="0"
fi
# Calculate diff
LINE_DIFF=$(echo "$PR_LINES - $BASELINE_LINES" | bc)
FUNC_DIFF=$(echo "$PR_FUNCTIONS - $BASELINE_FUNCTIONS" | bc)
# Determine delta indicator
if (( $(echo "$LINE_DIFF > 0" | bc -l) )); then
DELTA_INDICATOR=":white_check_mark:"
elif (( $(echo "$LINE_DIFF < 0" | bc -l) )); then
DELTA_INDICATOR=":x:"
else
DELTA_INDICATOR=":heavy_minus_sign:"
fi
# Set outputs
echo "pr_lines=$PR_LINES" >> $GITHUB_OUTPUT
echo "baseline_lines=$BASELINE_LINES" >> $GITHUB_OUTPUT
echo "line_diff=$LINE_DIFF" >> $GITHUB_OUTPUT
echo "delta_indicator=$DELTA_INDICATOR" >> $GITHUB_OUTPUT
# Write step summary
echo "## Test Coverage Report (${{ matrix.os }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Current Coverage | ${PR_LINES}% |" >> $GITHUB_STEP_SUMMARY
echo "| Base Branch Coverage | ${BASELINE_LINES}% |" >> $GITHUB_STEP_SUMMARY
echo "| Delta | ${LINE_DIFF}% ${DELTA_INDICATOR} |" >> $GITHUB_STEP_SUMMARY
shell: bash
- name: Generate Coverage Report (Windows)
if: startsWith(matrix.os, 'windows')
id: coverage-windows
run: |
# Extract PR coverage
$prContent = Get-Content -Path "lcov.info" -Raw
$prLinesFound = ($prContent | Select-String -Pattern "LF:(\d+)" -AllMatches).Matches | ForEach-Object { [int]$_.Groups[1].Value } | Measure-Object -Sum | Select-Object -ExpandProperty Sum
$prLinesHit = ($prContent | Select-String -Pattern "LH:(\d+)" -AllMatches).Matches | ForEach-Object { [int]$_.Groups[1].Value } | Measure-Object -Sum | Select-Object -ExpandProperty Sum
if ($prLinesFound -gt 0) {
$prPct = [math]::Round(($prLinesHit / $prLinesFound) * 100, 2)
} else {
$prPct = 0
}
# Extract baseline coverage (default to 0 if not available)
if (Test-Path "baseline-coverage/lcov.info") {
$baselineContent = Get-Content -Path "baseline-coverage/lcov.info" -Raw
$baselineLinesFound = ($baselineContent | Select-String -Pattern "LF:(\d+)" -AllMatches).Matches | ForEach-Object { [int]$_.Groups[1].Value } | Measure-Object -Sum | Select-Object -ExpandProperty Sum
$baselineLinesHit = ($baselineContent | Select-String -Pattern "LH:(\d+)" -AllMatches).Matches | ForEach-Object { [int]$_.Groups[1].Value } | Measure-Object -Sum | Select-Object -ExpandProperty Sum
if ($baselineLinesFound -gt 0) {
$baselinePct = [math]::Round(($baselineLinesHit / $baselineLinesFound) * 100, 2)
} else {
$baselinePct = 0
}
} else {
$baselinePct = 0
}
$diff = [math]::Round($prPct - $baselinePct, 2)
if ($diff -gt 0) {
$deltaIndicator = ":white_check_mark:"
} elseif ($diff -lt 0) {
$deltaIndicator = ":x:"
} else {
$deltaIndicator = ":heavy_minus_sign:"
}
# Set outputs
echo "pr_lines=$prPct" >> $env:GITHUB_OUTPUT
echo "baseline_lines=$baselinePct" >> $env:GITHUB_OUTPUT
echo "line_diff=$diff" >> $env:GITHUB_OUTPUT
echo "delta_indicator=$deltaIndicator" >> $env:GITHUB_OUTPUT
# Write step summary
echo "## Test Coverage Report (${{ matrix.os }})" >> $env:GITHUB_STEP_SUMMARY
echo "" >> $env:GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $env:GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $env:GITHUB_STEP_SUMMARY
echo "| Current Coverage | ${prPct}% |" >> $env:GITHUB_STEP_SUMMARY
echo "| Base Branch Coverage | ${baselinePct}% |" >> $env:GITHUB_STEP_SUMMARY
echo "| Delta | ${diff}% ${deltaIndicator} |" >> $env:GITHUB_STEP_SUMMARY
shell: pwsh
- name: Post Coverage Comment (Linux)
if: startsWith(matrix.os, 'ubuntu')
uses: marocchino/sticky-pull-request-comment@v2
with:
header: coverage-linux
message: |
## Test Coverage Report (Linux)
| Metric | Value |
|--------|-------|
| Current Coverage | ${{ steps.coverage-linux.outputs.pr_lines }}% |
| Base Branch Coverage | ${{ steps.coverage-linux.outputs.baseline_lines }}% |
| Delta | ${{ steps.coverage-linux.outputs.line_diff }}% ${{ steps.coverage-linux.outputs.delta_indicator }} |
---
${{ steps.coverage-linux.outputs.line_diff > 0 && 'Coverage increased! Great work!' || (steps.coverage-linux.outputs.line_diff < 0 && 'Coverage decreased. Please add tests for new code.' || 'Coverage unchanged.') }}
- name: Post Coverage Comment (Windows)
if: startsWith(matrix.os, 'windows')
uses: marocchino/sticky-pull-request-comment@v2
with:
header: coverage-windows
message: |
## Test Coverage Report (Windows)
| Metric | Value |
|--------|-------|
| Current Coverage | ${{ steps.coverage-windows.outputs.pr_lines }}% |
| Base Branch Coverage | ${{ steps.coverage-windows.outputs.baseline_lines }}% |
| Delta | ${{ steps.coverage-windows.outputs.line_diff }}% ${{ steps.coverage-windows.outputs.delta_indicator }} |
---
${{ steps.coverage-windows.outputs.line_diff > 0 && 'Coverage increased! Great work!' || (steps.coverage-windows.outputs.line_diff < 0 && 'Coverage decreased. Please add tests for new code.' || 'Coverage unchanged.') }}