Skip to content

Latest commit

Β 

History

History
118 lines (86 loc) Β· 4.13 KB

File metadata and controls

118 lines (86 loc) Β· 4.13 KB

Coverage Comment Action

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.

βœ… Action Structure

This is now a proper composite action with the recommended folder structure:

  1. .github/actions/coverage-comment/action.yml - Defines the action metadata, inputs, and outputs
  2. Composite action - Uses runs.using: composite to run multiple steps
  3. Step-level usage - Can be used directly as a step in any workflow
  4. Organized structure - Follows GitHub Actions best practices for action organization

Features

  • πŸ“Š 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

Usage

Basic Usage

- name: Comment Coverage Analysis
  uses: ./.github/actions/coverage-comment
  with:
    coverage_file: coverage/lcov.info
    min_coverage_threshold: 80
    github_token: ${{ secrets.GITHUB_TOKEN }}

Advanced Usage

- 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 }}

Inputs

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 -

Output

The action will:

  1. Parse the lcov.info file to extract coverage data for each file
  2. Calculate overall coverage percentage across all files
  3. 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%)
  4. Comment on the PR only if overall coverage is below the threshold
  5. Remove previous comments if coverage improves above the threshold

Example Output

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.

Integration with Existing Workflows

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.

Action Structure

The action is structured as a composite action that:

  1. Runs as a single step in any workflow
  2. Contains multiple sub-steps for parsing, commenting, and cleanup
  3. Provides outputs for overall coverage and threshold status
  4. Handles all logic internally without requiring separate jobs

Requirements

  • The coverage file must be in lcov.info format
  • The workflow must have pull-requests: write permission
  • Python 3 must be available in the runner environment (default on ubuntu-latest)

Error Handling

  • 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: true in the CI workflow to prevent blocking other steps