Skip to content

Commit 882ba26

Browse files
committed
ci(coverage): gate PRs on 100% patch coverage + 95% project floor
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 Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e67975e commit 882ba26

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 39 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: worker
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
@@ -38,3 +40,40 @@ jobs:
3840
files: worker/coverage.out
3941
flags: worker
4042
fail_ci_if_error: false
43+
44+
# ------------------------------------------------------------------
45+
# Org patch-coverage mandate: every changed line in a PR diff must be
46+
# covered by a test (100%), and the project floor stays >=95%.
47+
# Tool: diff-cover (https://github.com/Bachmann1234/diff-cover). The
48+
# "Generate coverage" step is `|| true` so it still produces
49+
# coverage.out even on a flaky test — the gate reads that file.
50+
# ------------------------------------------------------------------
51+
- uses: actions/setup-python@v5
52+
if: github.event_name == 'pull_request'
53+
with:
54+
python-version: '3.12'
55+
- name: Install diff-cover + cobertura converter
56+
if: github.event_name == 'pull_request'
57+
run: |
58+
pip install diff-cover
59+
go install github.com/boumenot/gocover-cobertura@latest
60+
- name: Convert coverage to Cobertura
61+
if: github.event_name == 'pull_request'
62+
working-directory: worker
63+
run: $(go env GOPATH)/bin/gocover-cobertura < coverage.out > coverage.xml
64+
- name: Patch coverage gate (100% of changed lines)
65+
if: github.event_name == 'pull_request'
66+
working-directory: worker
67+
run: |
68+
git fetch origin "${{ github.base_ref }}" --depth=1 || true
69+
diff-cover coverage.xml \
70+
--compare-branch="origin/${{ github.base_ref }}" \
71+
--fail-under=100
72+
- name: Project coverage floor (>=95% total)
73+
if: github.event_name == 'pull_request'
74+
working-directory: worker
75+
run: |
76+
total=$(go tool cover -func=coverage.out | tail -1 | awk '{print $3}' | tr -d '%')
77+
echo "Total project coverage: ${total}%"
78+
awk -v t="$total" 'BEGIN { exit (t+0 >= 95) ? 0 : 1 }' \
79+
|| { echo "::error::Project coverage ${total}% is below the 95% floor"; exit 1; }

0 commit comments

Comments
 (0)