Skip to content

Commit 685ab57

Browse files
ci(coverage): gate PRs on 100% patch coverage + 95% project floor (#13)
Adds diff-cover patch-coverage enforcement to the coverage workflow: every changed line in a PR must be covered by a test (--fail-under=100), and total project coverage must stay >=95%. Go coverage is converted to Cobertura via gocover-cobertura so diff-cover can read it. fetch-depth: 0 lets diff-cover resolve origin/<base_ref>; gated to pull_request events. New org mandate. Co-authored-by: Claude <noreply@anthropic.com>
1 parent cc44d63 commit 685ab57

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
- uses: actions/checkout@v4
1818
with:
1919
path: cli
20+
# Full history so diff-cover can resolve origin/<base_ref>.
21+
fetch-depth: 0
2022
- uses: actions/checkout@v4
2123
with:
2224
repository: InstaNode-dev/common
@@ -39,3 +41,38 @@ jobs:
3941
files: cli/coverage.out
4042
flags: cli
4143
fail_ci_if_error: false
44+
45+
# ------------------------------------------------------------------
46+
# Org patch-coverage mandate: every changed line in a PR diff must be
47+
# covered by a test (100%), and the project floor stays >=95%.
48+
# Tool: diff-cover (https://github.com/Bachmann1234/diff-cover).
49+
# ------------------------------------------------------------------
50+
- uses: actions/setup-python@v5
51+
if: github.event_name == 'pull_request'
52+
with:
53+
python-version: '3.12'
54+
- name: Install diff-cover + cobertura converter
55+
if: github.event_name == 'pull_request'
56+
run: |
57+
pip install diff-cover
58+
go install github.com/boumenot/gocover-cobertura@latest
59+
- name: Convert coverage to Cobertura
60+
if: github.event_name == 'pull_request'
61+
working-directory: cli
62+
run: $(go env GOPATH)/bin/gocover-cobertura < coverage.out > coverage.xml
63+
- name: Patch coverage gate (100% of changed lines)
64+
if: github.event_name == 'pull_request'
65+
working-directory: cli
66+
run: |
67+
git fetch origin "${{ github.base_ref }}" --depth=1 || true
68+
diff-cover coverage.xml \
69+
--compare-branch="origin/${{ github.base_ref }}" \
70+
--fail-under=100
71+
- name: Project coverage floor (>=95% total)
72+
if: github.event_name == 'pull_request'
73+
working-directory: cli
74+
run: |
75+
total=$(go tool cover -func=coverage.out | tail -1 | awk '{print $3}' | tr -d '%')
76+
echo "Total project coverage: ${total}%"
77+
awk -v t="$total" 'BEGIN { exit (t+0 >= 95) ? 0 : 1 }' \
78+
|| { echo "::error::Project coverage ${total}% is below the 95% floor"; exit 1; }

0 commit comments

Comments
 (0)