Skip to content

Commit d212a47

Browse files
Enforce coverage in gha (#213)
* Enforce coverage in gha Create a new file `.required-coverage` to hold the required coverage value. Fail the GHA if coverage requirement is not met after compile. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 89b2b1b commit d212a47

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.github/workflows/python-tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777

7878
coverage-compile:
7979
name: "coverage compile"
80-
needs: "run-tests-and-coverage"
80+
needs: ["settings", "run-tests-and-coverage"]
8181
runs-on: "ubuntu-latest"
8282
steps:
8383
- name: "Repo checkout"
@@ -104,11 +104,16 @@ jobs:
104104
- name: "Compile coverage data"
105105
run: "uvx nox --session combine"
106106

107-
- name: "Post summary to step summary."
107+
- name: "Post summary to step summary"
108108
run: |
109+
export COVERAGE_REQUIRED=$(<.required-coverage)
109110
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
110111
echo "TOTAL=$TOTAL" >> $GITHUB_ENV
112+
echo "### Minimum coverage required: ${COVERAGE_REQUIRED}%" >> $GITHUB_STEP_SUMMARY
111113
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
114+
if [ ${COVERAGE_REQUIRED} -gt $TOTAL ]; then
115+
exit 1
116+
fi
112117
113118
linters-and-formatters:
114119
name: "linters and formatters"

.required-coverage

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
100

0 commit comments

Comments
 (0)