A Github Action to report the test coverage of changed files in a pull request. All it needs is an lcov.info file. It provides a summary of the coverage for all files and changed files separately, and a detailed table with coverage metrics per changed file.
- π Generates comprehensive coverage reports from LCOV files
- π¬ Posts coverage summaries as PR comments
- π Updates existing comments or creates new ones
- π Shows coverage for all files and changed files separately
- π Detailed table with coverage metrics per changed file
β οΈ Configurable coverage thresholds with action failure- π¦ Optional artifact upload for coverage reports
- π― Supports custom working directories
name: Test Coverage
on:
pull_request:
branches: [ main ]
jobs:
coverage:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Run tests and generate coverage
run: |
# Your test commands here that generate LCOV report
npm test -- --coverage
- name: PR Test Coverage
uses: jbaczuk/pr-test-coverage@v1
with:
lcov-file: coverage/lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}- name: PR Test Coverage
uses: jbaczuk/pr-test-coverage@v1
with:
# Required: Path to LCOV file
lcov-file: coverage/lcov.info
# Required: GitHub token for API access
github-token: ${{ secrets.GITHUB_TOKEN }}
# Optional: Working directory (default: repository root)
working-directory: ./my-app
# Optional: Minimum coverage for all files (default: 0)
all-files-minimum-coverage: 80
# Optional: Minimum coverage for changed files (default: 0)
changed-files-minimum-coverage: 90
# Optional: Upload coverage as artifact (default: empty/disabled)
artifact-name: coverage-report
# Optional: Update existing comment vs create new (default: true)
update-comment: true| Input | Description | Required | Default |
|---|---|---|---|
lcov-file |
Path to the LCOV file (e.g., coverage/lcov.info) |
β | - |
github-token |
GitHub token for API access and posting comments | β | ${{ github.token }} |
working-directory |
Working directory to run the action from | β | '' (repository root) |
all-files-minimum-coverage |
Minimum coverage percentage for all files (0-100) | β | 0 |
changed-files-minimum-coverage |
Minimum coverage percentage for changed files (0-100) | β | 0 |
artifact-name |
Name for coverage artifact upload (empty to skip) | β | '' |
update-comment |
Whether to update existing comment or create new one | β | true |
The action requires the following permissions in your workflow:
permissions:
contents: read # To access repository files
pull-requests: write # To post and update PR commentsThe action will post a comment on your pull request that looks like this:
- Lines: 847/1205 (70.3%)
β οΈ - Functions: 156/198 (78.8%)
- Branches: 234/298 (78.5%)
- Lines: 142/165 (86.1%) β
- Functions: 28/32 (87.5%)
- Branches: 45/52 (86.5%)
Files changed:
File Lines Line % Functions Function % Branches Branch % π src 142/165 86.1% 28/32 87.5% 45/52 86.5% β π components 69/80 86.3% 12/14 85.7% 20/25 80.0% ββΒ π Button 24/28 85.7% 4/5 80.0% 8/10 80.0% βββΒ Β π Button.tsx 24/28 85.7% 4/5 80.0% 8/10 80.0% ββΒ π Modal 45/52 86.5% 8/9 88.9% 12/15 80.0% βββΒ Β π Modal.tsx 45/52 86.5% 8/9 88.9% 12/15 80.0% β π hooks 32/35 91.4% 6/7 85.7% 10/12 83.3% ββΒ π useAuth.ts 32/35 91.4% 6/7 85.7% 10/12 83.3% β π services 28/32 87.5% 7/8 87.5% 11/13 84.6% ββΒ π api 28/32 87.5% 7/8 87.5% 11/13 84.6% βββΒ Β π userService.ts 28/32 87.5% 7/8 87.5% 11/13 84.6% β π utils 13/18 72.2% 3/3 100.0% 4/2 66.7% ββΒ π validation.ts 13/18 72.2% 3/3 100.0% 4/2 66.7%
The action uses visual indicators to quickly show coverage status:
- β Good coverage (β₯80%)
β οΈ Moderate coverage (60-79%)- β Low coverage (<60%)
The action will fail if:
- LCOV file not found - The specified LCOV file doesn't exist
- Not a pull request - The action is not running in a PR context
- Coverage below threshold - When coverage falls below specified minimums:
- All files coverage below
all-files-minimum-coverage - Changed files coverage below
changed-files-minimum-coverage
- All files coverage below
The action supports standard LCOV format with the following metrics:
- Lines:
LF(lines found) andLH(lines hit) - Functions:
FNF(functions found) andFNH(functions hit) - Branches:
BRF(branches found) andBRH(branches hit)
- name: Install dependencies
run: npm ci
- name: Run tests with coverage
run: npm test -- --coverage --coverageReporters=lcov
- name: PR Test Coverage
uses: jbaczuk/pr-test-coverage@v1
with:
lcov-file: coverage/lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}- name: Install dependencies
run: |
pip install pytest pytest-cov
- name: Run tests with coverage
run: pytest --cov=. --cov-report=lcov
- name: PR Test Coverage
uses: jbaczuk/pr-test-coverage@v1
with:
lcov-file: coverage.lcov
github-token: ${{ secrets.GITHUB_TOKEN }}- name: Run tests with coverage
run: |
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out -o=coverage.lcov
- name: PR Test Coverage
uses: jbaczuk/pr-test-coverage@v1
with:
lcov-file: coverage.lcov
github-token: ${{ secrets.GITHUB_TOKEN }}Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.