Added PHPUnit code coverage reporting to CI with threshold enforcement.#330
Added PHPUnit code coverage reporting to CI with threshold enforcement.#330AlexSkrypnyk merged 5 commits intomasterfrom
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 27 minutes and 31 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR introduces comprehensive code coverage instrumentation to the CI pipeline. It configures PHPUnit to generate coverage reports with minimum thresholds, modifies the workflow to extract metrics and post coverage summaries as PR comments, and ensures builds fail below coverage requirements. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/ci.yml:
- Around line 127-134: The "Upload test artifacts" step currently is skipped
when the coverage threshold check exits non-zero; update the step's conditional
to run regardless of job outcome by changing its if expression to use always()
(e.g., if: ${{ always() && matrix.coverage }} or equivalent) so artifacts are
uploaded even on failures; apply the same change to the "Post coverage summary
as PR comment" step (referencing that step name) so the PR is updated when the
threshold check fails.
- Around line 119-125: The threshold check step ("Check coverage threshold")
fails for non-integer CI_COVERAGE_THRESHOLD because the bash arithmetic
$((CI_COVERAGE_THRESHOLD*100)) rejects floats; change the comparison to a
float-safe one by using a tool that supports decimals (e.g., awk or bc or
python) to multiply/compare TOTAL_COVERAGE_PERCENT and CI_COVERAGE_THRESHOLD (or
normalize both to the same scale) and return non-zero/zero for the exit status;
update the step to use that float-safe comparison so TOTAL_COVERAGE_PERCENT (a
%.2f float) is correctly compared against CI_COVERAGE_THRESHOLD (which may be a
decimal).
- Around line 82-98: The script that extracts coverage is brittle: ensure
.logs/coverage/cobertura.xml exists and contains a valid line-rate before
computing RATE/PERCENT (fail early with a clear error message if missing/empty),
replace the grep/tr/tr brittle pipeline with a small Python parse (reuse the
existing python3 block to compute RATE→PERCENT and export
TOTAL_COVERAGE_PERCENT), add safety checks before cat-ing
.logs/coverage/coverage-summary.txt (e.g., test -f before appending
COVERAGE_SUMMARY to GITHUB_ENV) and wrap the shell block with strict options
(set -euo pipefail) or explicit guards so empty RATE won't produce a broken awk
invocation; also only write COVERAGE_DETAILS/COVERAGE_SUMMARY env blocks when
their contents are present.
- Around line 100-117: The workflow step using
marocchino/sticky-pull-request-comment will fail for forked-repo pull_request
events because GITHUB_TOKEN is read-only for forks; update the step to either
(A) move this comment-posting logic into a separate pull_request_target workflow
(and handle untrusted code safely) so it can run with write permissions, or (B)
make the step non-blocking by adding continue-on-error: true so fork PRs don't
fail CI; also remove hide_and_recreate: true (or change to the default
header/recreate behavior) to avoid accumulating hidden comments—refer to the
action usage block and the hide_and_recreate/header fields when making these
changes.
- Around line 74-76: The workflow step "Test with coverage" sets
pcov.directory=., which instruments the entire repo (including vendor/) — change
the pcov.directory value to the actual source directory used by PHPUnit (the
same path configured in phpunit.xml.dist, e.g., "src" or the <source> path) so
pcov only instruments your source tree; update the run command in the "Test with
coverage" step (the docker compose exec -T php ... php -d pcov.directory=...
vendor/bin/phpunit ...) to use that specific directory instead of "." to avoid
instrumenting vendor/.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7317d9d1-2211-4a55-a1d0-f0f0cc88fdfd
📒 Files selected for processing (3)
.github/workflows/ci.yml.gitignorephpunit.xml.dist
|
Code coverage (threshold: 10%) Per-class coverage |
Summary
pcov.cobertura.xml, an HTML report, and a text summary; all artifacts are uploaded for inspection.marocchino/sticky-pull-request-comment) containing the coverage summary and a collapsible per-class breakdown parsed from the Cobertura XML.Changes
.github/workflows/ci.ymlCI_COVERAGE_THRESHOLDenv var (default10).pull-requests: writepermission so the workflow can post PR comments.coverage: trueflag to the PHP 8.4 / Drupal 11 matrix entry.Teststep into two conditional steps: one that runs withpcovcoverage instrumentation (if: matrix.coverage) and one that runs the standardcomposer testcommand for all other matrix entries.Extract total coveragestep that readscobertura.xml, calculates the percentage, writes it to$GITHUB_STEP_SUMMARY, and exports per-class details via env vars.Post coverage summary as PR commentstep that posts (and updates) a sticky comment on pull requests.Check coverage thresholdstep that exits non-zero when coverage is below the threshold.Upload test artifactsstep that uploads the.logsdirectory as a workflow artifact.phpunit.xml.dist<source>element (replacing the deprecated<coverage><include>form).cacheDirectory,executionOrder,failOnWarning, andbeStrictAboutCoverageMetadatafor improved test hygiene..gitignore/.logsto exclude generated coverage and log output from version control.Test plan
Test with coveragestep runs only on the PHP 8.4 / Drupal 11 matrix entry.coverage-reportartifact is uploaded after a successful run.masterand confirm a sticky comment is posted with the coverage summary and collapsible per-class details.CI_COVERAGE_THRESHOLDto a value above the actual coverage and confirm the build fails with the expected message.composer testwithout coverage overhead.Summary by CodeRabbit
Release Notes