How to Enforce Coverage on the Diff Only in CI
Codecov patch status measures coverage of only the lines a PR changed, so new code must be tested.
Set coverage.status.patch in codecov.yml. The patch check passes only when the changed lines meet the target, independent of the whole-project number.
Steps
- Enable
coverage.status.patchincodecov.yml. - Set a
targetfor the changed lines (e.g. 80%). - Add the patch status to required checks to block undertested PRs.
codecov.yml
codecov.yml
coverage:
status:
patch:
default:
target: 80%
threshold: 0%
only_pulls: trueGotchas
- Patch coverage needs the base commit report; make sure the base branch also uploads coverage.
- Tools like
diff-coveroffer a CI-only alternative that reads the git diff plus an XML report.
Related guides
How to Add Codecov PR Comments and Status Checks in CIConfigure Codecov to post a PR comment and project and patch status checks via codecov.yml, so coverage chang…
How to Ratchet Coverage Upward in CIPrevent coverage from slipping in CI by using a ratchet, where the gate compares against the current level so…
How to Make Coverage a Required Check in CIBlock merges on coverage in CI by adding the Codecov status context to branch protection required checks, so…