Commit 054ffcc
fix(ci): Fix coverage percentage extraction in GitHub Actions workflow
The "Extract coverage percentage" step in the Code Coverage workflow was
failing due to attempting to parse a non-existent JSON structure in
tarpaulin's output.
## Problem
- Step: "Extract coverage percentage"
- Error: `jq: error (at coverage/tarpaulin-report.json:0): number (0) and
number (0) cannot be divided because the divisor is zero`
- Cause: Workflow attempted to parse `.files` array with `.covered` and
`.coverable` fields that don't exist in tarpaulin's JSON output
- Actual structure: tarpaulin JSON contains `traces` and `functions` keys,
not a `.files` array
## Solution
**Parse tarpaulin stdout instead of JSON:**
- Capture tarpaulin's stdout output during test run
- Extract coverage percentage using regex pattern matching
- Format: "XX.XX% coverage, N/M lines covered"
- More reliable: Uses tarpaulin's own calculated percentage
**Technical Details:**
- Combined `tee /dev/tty` to display output while capturing
- Used `grep -oP '\d+\.\d+(?=% coverage)'` for extraction
- Added validation: Exit if coverage extraction fails
- Store in GitHub Actions output for downstream steps
## Changes
- .github/workflows/coverage.yml:
- Added `id: tarpaulin` to "Generate coverage report" step
- Capture tarpaulin stdout with `2>&1 | tee /dev/tty`
- Extract coverage with regex: `\d+\.\d+(?=% coverage)`
- Store in step outputs: `echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT`
- "Extract coverage percentage" step now reads from tarpaulin outputs
- Added error handling for failed extraction
- CHANGELOG.md:
- Documented fix in [Unreleased] section
- Explained root cause and solution
- Related to v0.4.6 release workflow failures
## Verification
- YAML syntax validated with Python yaml.safe_load()
- Regex pattern tested against actual tarpaulin output: "54.85% coverage"
- Solution follows GitHub Actions best practices for step outputs
## Why This Solution?
Three options considered:
1. ✅ **Parse tarpaulin stdout (chosen):** Most reliable, uses tarpaulin's
own calculation, simple regex, works across all versions
2. ❌ Parse LCOV file: More complex (LF/LH counting), potential precision issues
3. ❌ Use Codecov API: Requires additional API calls, async delay issues
## Impact
- ✅ Coverage reporting workflow will now pass
- ✅ Automated threshold checks (50%) will function correctly
- ✅ PR comments will show accurate coverage percentages
- ✅ Codecov integration remains unchanged (uses LCOV file)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent e2ccef1 commit 054ffcc
2 files changed
+24
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | | - | |
| 57 | + | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
60 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
61 | 74 | | |
62 | 75 | | |
63 | 76 | | |
| |||
78 | 91 | | |
79 | 92 | | |
80 | 93 | | |
81 | | - | |
| 94 | + | |
| 95 | + | |
82 | 96 | | |
83 | 97 | | |
84 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
10 | 17 | | |
11 | 18 | | |
12 | 19 | | |
| |||
0 commit comments