88 branches :
99 - master
1010
11+ permissions :
12+ contents : read
13+
1114jobs :
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
4250
4351 - sim : icarus
4452 python-version : ' 3.13'
53+ coverage : true
4554
4655 - sim : verilator
4756 sim-version : 5.044
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
0 commit comments