ci(coverage): harden diff-cover step and handle non-Java PRs#25
ci(coverage): harden diff-cover step and handle non-Java PRs#25
Conversation
- Drop the unreachable PR_XMLS empty-check; collect-xml already exits 1 when jacoco reports are missing, and the previous `exit 0` would have left changed_line_coverage unset and triggered a misleading "Failed to parse changed-line coverage" in the enforcement step. - Parse total_num_lines from diff-cover.json: when a PR has no changed Java source lines (workflow-only, docs-only, proto-only), emit the sentinel NA and treat it as SKIPPED in the enforcement step so the gate does not wrongly fail. - Display NA without a trailing %% in the step summary and logs. Addresses review comments from CodeRabbit and cubic on PR #23.
📝 WalkthroughWalkthroughThe pr-build.yml workflow now handles cases where no Java source lines are changed. When diff-cover.json reports zero total lines, the workflow sets changed-line coverage to "NA", skips the threshold check, and marks the gate as passed-irrelevant. The diff-cover step no longer exits early on missing PR Jacoco reports. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
🧹 Nitpick comments (1)
.github/workflows/pr-build.yml (1)
300-323: Optional: clearer diagnostic whendiff-cover.jsonis absent.
set +ewraps thediff-coverinvocation andDIFF_RCis captured but only logged later (line 335). Ifdiff-coverfails catastrophically and never writesdiff-cover.json, the subsequentjqcall will fail with a generic file-not-found error instead of a message that points at the real cause. Consider asserting the file exists before parsing so the failure surfaces clearly.♻️ Suggested refinement
DIFF_RC=$? set -e + if [ ! -s diff-cover.json ]; then + echo "diff-cover did not produce diff-cover.json (exit code: ${DIFF_RC})." + exit 1 + fi + TOTAL_NUM_LINES=$(jq -r '.total_num_lines // 0' diff-cover.json)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/pr-build.yml around lines 300 - 323, Check for diff-cover.json after running diff-cover and before jq usage: if DIFF_RC is non-zero or diff-cover.json does not exist/has zero size, print a clear diagnostic including DIFF_RC and the diff-cover stderr/stdout (or a note that diff-cover failed) and fail fast; otherwise continue to parse TOTAL_NUM_LINES and CHANGED_LINE_COVERAGE as before. Specifically update the section around the diff-cover invocation and checks for DIFF_RC/diff-cover.json so the script verifies file existence (e.g., test -s "diff-cover.json") and logs "diff-cover failed (exit $DIFF_RC)" with context before running jq, referencing DIFF_RC, diff-cover.json, TOTAL_NUM_LINES and CHANGED_LINE_COVERAGE in the message.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.github/workflows/pr-build.yml:
- Around line 300-323: Check for diff-cover.json after running diff-cover and
before jq usage: if DIFF_RC is non-zero or diff-cover.json does not exist/has
zero size, print a clear diagnostic including DIFF_RC and the diff-cover
stderr/stdout (or a note that diff-cover failed) and fail fast; otherwise
continue to parse TOTAL_NUM_LINES and CHANGED_LINE_COVERAGE as before.
Specifically update the section around the diff-cover invocation and checks for
DIFF_RC/diff-cover.json so the script verifies file existence (e.g., test -s
"diff-cover.json") and logs "diff-cover failed (exit $DIFF_RC)" with context
before running jq, referencing DIFF_RC, diff-cover.json, TOTAL_NUM_LINES and
CHANGED_LINE_COVERAGE in the message.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6d239511-590b-4046-9bd6-165275e3c9a0
📒 Files selected for processing (1)
.github/workflows/pr-build.yml
Summary
Follow-up to PR #23 addressing two review comments from CodeRabbit and cubic.
Fix A — Drop the unreachable
exit 0branch incoverage-gateThe
PR_XMLSempty check (removed here) was already unreachable: the earliercollect-xmlstepexit 1s when JaCoCo reports are missing. Worse, if it had ever fired,exit 0would have bypassed thechanged_line_coverageoutput, and the downstream enforcement step would have failed with a misleading "Failed to parse changed-line coverage" message instead of a skip.Fix B — Handle PRs with no changed Java source lines
When a PR touches only non-Java files (workflow, docs,
.proto,.md, config),diff-coverproduces a JSON report withtotal_num_lines: 0andtotal_percent_covered: null. The previous parse with// emptywould thenexit 1, wrongly failing legitimate non-Java PRs.This PR:
total_num_linesfromdiff-cover.json. When0, emits the sentinelchanged_line_coverage=NA.NAasSKIPPED(passes the changed-line gate).NAwithout a trailing%in the step summary.The overall-delta gate (
MAX_DROP=-0.1%) is unchanged.Test plan
NA/ SKIPPED branch in the fresh workflow once merged.Changed-line Coverage: NAandChanged-line Gate: SKIPPED (no changed Java source lines).> -0.1%.Summary by cubic
Hardens the PR coverage gate to avoid false failures and clearer output. Skips changed-line enforcement when there are no changed Java lines, and removes a dead path that caused misleading errors.
PR_XMLScheck that could unsetchanged_line_coverageand trigger a parse error.total_num_linesfromdiff-cover.json; when 0, setchanged_line_coverage=NAand mark the gate as SKIPPED.NAwithout a trailing%in logs and the step summary. Overall-delta gate remains unchanged.Written for commit ece6e09. Summary will update on new commits.
Summary by CodeRabbit