Skip to content

Commit b79622e

Browse files
authored
Merge pull request #283 from SiLab-Bonn/update-coverage
Banish the ghost of codecov
2 parents 7f47c86 + cf3e596 commit b79622e

4 files changed

Lines changed: 82 additions & 8 deletions

File tree

.github/workflows/regression-tests.yml

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
branches:
99
- master
1010

11+
permissions:
12+
contents: read
13+
1114
jobs:
1215

1316
pre-commit:
@@ -18,11 +21,16 @@ jobs:
1821
with:
1922
python-version: "3.12"
2023
- uses: pre-commit/action@v3.0.1
24+
env:
25+
SKIP: coverage # Run all normal formatting hooks in CI, but skip the local coverage hook because the coverage job handles it separately.
2126

2227
tests:
2328

2429
name: Python ${{matrix.python-version}} | ${{matrix.sim}}
2530
runs-on: ubuntu-24.04
31+
permissions:
32+
contents: read
33+
checks: write
2634
env:
2735
SIM: ${{matrix.sim}}
2836

@@ -42,6 +50,7 @@ jobs:
4250

4351
- sim: icarus
4452
python-version: '3.13'
53+
coverage: true
4554

4655
- sim: verilator
4756
sim-version: 5.044
@@ -50,6 +59,8 @@ jobs:
5059

5160
steps:
5261
- uses: actions/checkout@v6
62+
with:
63+
fetch-depth: ${{ matrix.coverage && '0' || '1' }}
5364
- name: Set up miniforge ${{matrix.python-version}}
5465
uses: conda-incubator/setup-miniconda@v3
5566
with:
@@ -71,21 +82,63 @@ jobs:
7182
- name: Install Python dependencies
7283
shell: bash -l {0}
7384
run: |
74-
pip install pyvisa pyvisa-sim pytest coverage coveralls pytest-cov cocotb>=2 cocotb-bus
85+
pip install pyvisa pyvisa-sim pytest cocotb>=2 cocotb-bus
86+
87+
- name: Install coverage dependency
88+
if: matrix.coverage
89+
shell: bash -l {0}
90+
run: |
91+
pip install coverage diff-cover
7592
7693
- name: Install basil
7794
shell: bash -l {0}
7895
run: |
7996
pip install -e .
8097
8198
- name: Test
99+
if: ${{ !matrix.coverage }}
82100
shell: bash -l {0}
83101
run: |
84-
pytest ${{matrix.pytest-marker}} --cov=basil tests/test_*.py examples/*/*/test_*.py
102+
pytest ${{matrix.pytest-marker}} tests/test_*.py examples/*/*/test_*.py
85103
86-
- name: Upload to codecov
104+
- name: Test with coverage
105+
if: matrix.coverage
106+
shell: bash -l {0}
107+
run: |
108+
coverage run --source=basil -m pytest ${{matrix.pytest-marker}} \
109+
tests/test_*.py examples/*/*/test_*.py
110+
coverage xml -o coverage.xml
111+
coverage report --format=total | awk '{print "### Test coverage: " $1 "%"}' >> "$GITHUB_STEP_SUMMARY"
112+
113+
- name: Create differential coverage report
114+
if: matrix.coverage && github.event_name == 'pull_request'
115+
env:
116+
BASE_REF: ${{github.base_ref}}
87117
shell: bash -l {0}
88118
run: |
89-
curl -Os https://uploader.codecov.io/latest/linux/codecov
90-
chmod +x codecov
91-
./codecov -t ${CODECOV_TOKEN}
119+
diff-cover coverage.xml \
120+
--compare-branch="origin/${BASE_REF}" \
121+
--format=markdown:diff-cover.md
122+
cat diff-cover.md >> "$GITHUB_STEP_SUMMARY"
123+
124+
- name: Publish differential coverage check
125+
if: >-
126+
matrix.coverage &&
127+
github.event_name == 'pull_request' &&
128+
github.event.pull_request.head.repo.full_name == github.repository
129+
continue-on-error: true
130+
env:
131+
GH_TOKEN: ${{github.token}}
132+
HEAD_SHA: ${{github.event.pull_request.head.sha}}
133+
run: |
134+
gh api --method POST \
135+
--header "Accept: application/vnd.github+json" \
136+
--header "X-GitHub-Api-Version: 2022-11-28" \
137+
"repos/${GITHUB_REPOSITORY}/check-runs" \
138+
--raw-field name="Coverage (informational)" \
139+
--raw-field head_sha="$HEAD_SHA" \
140+
--raw-field status=completed \
141+
--raw-field conclusion=neutral \
142+
--raw-field "output[title]=Differential coverage" \
143+
--field "output[summary]=@diff-cover.md" \
144+
--silent

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Makefile
4141
*.out
4242
examples/lx9/device/src/SiTCP
4343

44+
# Test coverage
45+
.coverage
46+
coverage.xml
47+
4448
# PyDev files
4549
.project
4650
.pydevproject

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,21 @@ repos:
1515
hooks:
1616
- id: end-of-file-fixer
1717
- id: trailing-whitespace
18+
- repo: local
19+
hooks:
20+
- id: coverage
21+
name: Coverage
22+
entry: >-
23+
bash -c 'SIM=icarus coverage run
24+
--source=basil -m pytest
25+
-q --disable-warnings
26+
tests/test_*.py examples/*/*/test_*.py
27+
&& coverage xml -q -o coverage.xml
28+
&& diff-cover coverage.xml
29+
--compare-branch=origin/master
30+
--show-uncovered'
31+
language: system
32+
pass_filenames: false
33+
verbose: true
34+
files: ^(basil/|tests/|examples/).*\.py$
35+
stages: [pre-commit]

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ hw = ["pyserial", "PyVISA"]
3838

3939
test = [
4040
"coverage",
41-
"coveralls",
4241
"cocotb>=2.0.1",
4342
"cocotb-bus>=0.3.0",
4443
"cocotb-test>=0.2.6",
44+
"diff-cover",
4545
"pytest>=9.0.3",
46-
"pytest-cov",
4746
"PyVISA",
4847
"pyvisa-sim",
4948
]

0 commit comments

Comments
 (0)