Skip to content

Commit 67d37fe

Browse files
authored
Coverage: Implement fail_under (#654)
1 parent e9ae26f commit 67d37fe

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,26 @@ jobs:
178178
ls -aR .coverage*
179179
coverage combine .coverage*
180180
echo "Creating coverage report..."
181-
# Create a coverage report (console)
182-
coverage report
183-
# Create xml file for further processing
184-
coverage xml
181+
# Create xml file for further processing; Create even if below minimum
182+
coverage xml --fail-under=0
185183
186184
# For future use in case we want to add a PR comment for 3rd party PRs which requires
187185
# a workflow with elevated PR write permissions. Move below steps into a separate job.
188186
- name: Archive code coverage report
187+
id: cov_xml_upload
189188
uses: actions/upload-artifact@v4
190189
with:
191190
name: coverage
192191
path: coverage.xml
192+
- name: Code Coverage Report (console)
193+
run: |
194+
# Create a coverage report (console), respects fail_under in pyproject.toml
195+
coverage report
193196
194197
- name: Code Coverage Report
195198
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
199+
# Create markdown file even if coverage report fails due to fail_under
200+
if: ${{ always() && steps.cov_xml_upload.outputs.artifact-id != '' }}
196201
with:
197202
filename: coverage.xml
198203
badge: true
@@ -202,15 +207,20 @@ jobs:
202207
hide_complexity: true
203208
indicators: true
204209
output: both # console, file or both
205-
thresholds: '90 95'
210+
# Note: it appears fail below min is one off, use fail_under -1 here
211+
thresholds: '95 98'
206212

207213
- name: Add Coverage PR Comment
208214
uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.3
209215
# Create PR comment when the branch is on the repo, otherwise we lack PR write permissions
210216
# -> need another workflow with access to secret token
211217
if: >-
212-
github.event_name == 'pull_request'
213-
&& github.event.pull_request.head.repo.full_name == github.repository
218+
${{
219+
always()
220+
&& github.event_name == 'pull_request'
221+
&& github.event.pull_request.head.repo.full_name == github.repository
222+
&& steps.cov_xml_upload.outputs.artifact-id != ''
223+
}}
214224
with:
215225
hide_and_recreate: true
216226
path: code-coverage-results.md

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ extra-standard-library = ["tomllib"]
122122
known-first-party = ["typing_extensions", "_typed_dict_test_helper"]
123123

124124
[tool.coverage.report]
125+
fail_under = 96
125126
show_missing = true
126127
# Omit files that are created in temporary directories during tests.
127128
# If not explicitly omitted they will result in warnings in the report.

0 commit comments

Comments
 (0)