Skip to content

Commit 8a2699b

Browse files
ci(coverage): gate PRs on 100% patch coverage (#134)
Adds diff-cover patch-coverage enforcement: every changed line in a PR must be covered by a test (--fail-under=100 vs origin/main). vitest's v8 coverage provider emits lcov with src/*.ts(x) paths + source-mapped line numbers, so it lines up directly with the PR diff. @vitest/coverage-v8 is already a devDependency on main (#132), so this PR only adds the workflow gate. `npm run gate` untouched. New org mandate. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8abb105 commit 8a2699b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
timeout-minutes: 10
1616
steps:
1717
- uses: actions/checkout@v4
18+
with:
19+
# Full history so diff-cover can resolve origin/<base_ref>.
20+
fetch-depth: 0
1821
- uses: actions/setup-node@v4
1922
with:
2023
node-version: 20
@@ -25,3 +28,28 @@ jobs:
2528
if: always()
2629
with:
2730
fail_ci_if_error: false
31+
32+
# ------------------------------------------------------------------
33+
# Org patch-coverage mandate: every changed line in a PR diff must be
34+
# covered by a test (100%). Tool: diff-cover
35+
# (https://github.com/Bachmann1234/diff-cover). vitest's v8 provider
36+
# emits lcov with src/*.ts(x) paths + source-mapped line numbers, so it
37+
# lines up directly with the PR diff. `npm run gate` is untouched.
38+
# ------------------------------------------------------------------
39+
- name: Generate lcov coverage
40+
if: github.event_name == 'pull_request'
41+
run: npx vitest run --coverage --coverage.provider=v8 --coverage.reporter=lcov --coverage.reportsDirectory=coverage
42+
- uses: actions/setup-python@v5
43+
if: github.event_name == 'pull_request'
44+
with:
45+
python-version: '3.12'
46+
- name: Install diff-cover
47+
if: github.event_name == 'pull_request'
48+
run: pip install diff-cover
49+
- name: Patch coverage gate (100% of changed lines)
50+
if: github.event_name == 'pull_request'
51+
run: |
52+
git fetch origin "${{ github.base_ref }}" --depth=1 || true
53+
diff-cover coverage/lcov.info \
54+
--compare-branch="origin/${{ github.base_ref }}" \
55+
--fail-under=100

0 commit comments

Comments
 (0)