This GitHub Action analyzes code coverage from an lcov.info file and automatically comments on pull requests with per-file coverage details when the overall coverage is below a specified threshold.
This is now a proper composite action with the recommended folder structure:
.github/actions/coverage-comment/action.yml- Defines the action metadata, inputs, and outputs- Composite action - Uses
runs.using: compositeto run multiple steps - Step-level usage - Can be used directly as a step in any workflow
- Organized structure - Follows GitHub Actions best practices for action organization
- π Parses lcov.info files to extract coverage data
- π Calculates overall and per-file coverage percentages
- π¬ Automatically comments on PRs when coverage is below threshold
- π― Only comments when overall coverage is below the specified threshold (default: 80%)
- ποΈ Shows per-file coverage breakdown in a readable table format
- π Uses sticky comments that update/remove automatically
- name: Comment Coverage Analysis
uses: ./.github/actions/coverage-comment
with:
coverage_file: coverage/lcov.info
min_coverage_threshold: 80
github_token: ${{ secrets.GITHUB_TOKEN }}- name: Comment Coverage Analysis
uses: ./.github/actions/coverage-comment
with:
coverage_file: "custom/path/to/coverage.info"
min_coverage_threshold: 85
comment_header: "custom-coverage-analysis"
github_token: ${{ secrets.GITHUB_TOKEN }}| Input | Description | Required | Default |
|---|---|---|---|
coverage_file |
Path to the lcov.info coverage file | No | coverage/lcov.info |
min_coverage_threshold |
Minimum coverage percentage threshold | No | 80 |
comment_header |
Header used for the sticky PR comment | No | coverage-analysis |
github_token |
GitHub token for PR comments | Yes | - |
The action will:
- Parse the lcov.info file to extract coverage data for each file
- Calculate overall coverage percentage across all files
- Generate a detailed comment with:
- Overall coverage percentage with status indicator
- Per-file coverage breakdown in a table
- Color-coded status indicators (π’ 80%+, π‘ 50-79%, π΄ <50%)
- Comment on the PR only if overall coverage is below the threshold
- Remove previous comments if coverage improves above the threshold
When coverage is below the threshold, the action will post a comment like:
## π Code Coverage Analysis
**Overall Coverage: 75.2%** β
The overall coverage is below the 80% threshold.
### Per-File Coverage Details
| File | Coverage | Lines Hit/Total |
|------|----------|-----------------|
| `lib/src/utils.dart` | 45.5% π΄ | 15/33 |
| `lib/src/parser.dart` | 67.8% π‘ | 45/66 |
| `lib/src/validator.dart` | 89.2% π’ | 58/65 |
### Coverage Legend
- π’ 80%+ coverage
- π‘ 50-79% coverage
- π΄ <50% coverage
**Note:** This analysis is based on line coverage from the lcov.info file.This action is designed to work alongside existing coverage reporting tools. It's already integrated into the main CI workflow and will run automatically on pull requests.
The action is structured as a composite action that:
- Runs as a single step in any workflow
- Contains multiple sub-steps for parsing, commenting, and cleanup
- Provides outputs for overall coverage and threshold status
- Handles all logic internally without requiring separate jobs
- The coverage file must be in lcov.info format
- The workflow must have
pull-requests: writepermission - Python 3 must be available in the runner environment (default on ubuntu-latest)
- If the coverage file doesn't exist, the action will skip execution
- If the coverage file is malformed, the action will fail with an error message
- The action uses
continue-on-error: truein the CI workflow to prevent blocking other steps