Add PR-affected-lines coverage gate via shipmonk/coverage-guard#5892
Draft
janedbal wants to merge 1 commit into
Draft
Add PR-affected-lines coverage gate via shipmonk/coverage-guard#5892janedbal wants to merge 1 commit into
janedbal wants to merge 1 commit into
Conversation
Draft. Adds a pull_request-only job that runs the test suite with pcov coverage (mirroring the existing paratest coverage step), computes the GitHub three-dot diff (base...head) for the PR, and runs `coverage-guard check --patch` so only lines the PR changed are gated. Co-Authored-By: Claude Code
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.event.pull_request.head.sha }} |
| ref: ${{ github.event.pull_request.head.sha }} | ||
|
|
||
| - name: "Install PHP" | ||
| uses: "shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc" # v2.37.1 |
| ini-file: development | ||
| ini-values: memory_limit=-1 | ||
|
|
||
| - uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0 |
|
|
||
| - uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0 | ||
|
|
||
| - uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0 |
Comment on lines
+40
to
+44
| - name: "Checkout" | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.event.pull_request.head.sha }} |
| - name: "Compute PR diff" | ||
| run: | | ||
| git diff \ | ||
| "${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}" \ |
| - name: "Compute PR diff" | ||
| run: | | ||
| git diff \ | ||
| "${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}" \ |
| "${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}" \ | ||
| > changes.patch | ||
| echo "----- changed files -----" | ||
| git diff --name-only "${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}" |
| "${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}" \ | ||
| > changes.patch | ||
| echo "----- changed files -----" | ||
| git diff --name-only "${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft, following up on the suggestion in #5891 (comment) — add a CI gate using shipmonk/coverage-guard that enforces coverage only on the lines a PR changes.
What it does
A new
pull_request-only job (.github/workflows/patch-coverage.yml):pull_request.head.sha),fetch-depth: 0.make infection/ themutation-testingjob), but emits clover. paratest merges per-worker coverage, so no separate merge step is needed.git diff base.sha...head.sha(three-dot) and runscoverage-guard check coverage/clover.xml --patch changes.patch.Diff generation (the important bit)
This mirrors GitLab's "merged results" approach used in our private CI, but adapted to GitHub. Rather than relying on GitHub's
refs/pull/N/mergemerge commit (which only exists when the PR is mergeable and whose line numbers can drift from head), it uses the three-dotbase...headdiff — exactly what GitHub's "Files changed" tab shows:+line numbers are in head's coordinate system, matching the coverage collected on the head checkout — so patch lines and clover lines align.Preconditions worth noting
src/coverage is captured. The only subprocess-spawning tests (execgroup) andlevelsare already excluded inphpunit.xml.beStrictAboutCoverageMetadata=true+failOnRisky=truewould break a naivephpunit --coverage-*run (few tests carry#[CoversClass]). The paratest coverage path is already green today (mutation-testing job), which is why this reuses it rather than a plain phpunit run.Open decisions
coverage-guardis installed ad-hoc in the job; if we keep this, move it torequire-dev.coverage-guard.php(EnforceCoverageForMethodsRule, 50% / 50% / 5 lines) are placeholders — needs tuning, or a custom rule.continue-on-errorfor an observation period first.Co-Authored-By: Claude Code