Create a Coverage report comment on Github PR
Permissions needed for the Github Token:
Pull requests:read
Pull requests:write
install:
pip install python-coverage-commentrun:
GITHUB_REPOSITORY=<repository_name> \
COVERAGE_PATH=<path_to_coverage_report> \
GITHUB_TOKEN=<github_token> \
GITHUB_PR_NUMBER=<pull_request_number> \
codecovGITHUB_REPOSITORY: The name of the GitHub repository where the action is running.COVERAGE_PATH: The path to the coverage report file. (JSON format)GITHUB_TOKEN: The GitHub token used for authentication.GITHUB_PR_NUMBER: The number of the pull request where the coverage report comment to be generated. (Optional)GITHUB_REF: The branch name if pr number is not provided, it will be used to get the PR number. (Optional)
Note: Either GITHUB_PR_NUMBER or GITHUB_REF is required. GITHUB_PR_NUMBER takes precedence if both mentioned.
MINIMUM_GREEN: The minimum coverage percentage for green status. Default is 100.MINIMUM_ORANGE: The minimum coverage percentage for orange status. Default is 70.BRANCH_COVERAGE: Show branch coverage in the report. Default is False.MAX_FILES_IN_COMMENT: The maximum number of files to include in the coverage report comment. Default is 25.SKIP_COVERED_FILES_IN_REPORT: Skip the files with coverage 100% from the report. Default is True.COMPLETE_PROJECT_REPORT: Whether to include the complete project coverage report in the comment. Default is False.LABEL: Optional text rendered in the comment footer. Default is unset (no footer).DEBUG: Whether to enable debug mode. Default is False.
- The coverage report displays only files that have missing coverage. If all files are fully covered, the report will be empty.
- When branch coverage is enabled, the pull request coverage percentage counts branch arcs whose source
line is among the added lines in the diff (alongside the added statements). The
Missing branchescolumn lists those arcs assource -> destination. An arc that leaves its enclosing scope is shown assource -> exit. - In the pull request table, the
Branches/Missingbadges are whole-file totals from the coverage report, while theMissing brancheslinks list only arcs on added lines. A Missing count can therefore be larger than the number of links shown for that file. The same pattern already applies toStatements/Missing stmts. - Pull request coverage is recalculated from the statement and branch arc lists. The report's overall
coverage percentage comes from coverage.py's summary counts, which can still credit
# pragma: no brancharcs. So, the two percentages can differ slightly even when the PR adds an entire file. EnableBRANCH_COVERAGEwhen your report includes branch data so both sides include branches. - If the complete project report option is enabled, file totals and the project coverage percentage are taken from the report as-is. Differences versus pull request coverage are expected when the scopes or formulas differ as above.
To get started, follow these steps:
-
Clone the repository:
git clone <repository_url>
-
Navigate to the cloned repository:
cd <repository_directory>
-
Install uv if you do not have it yet.
-
Build the project:
make all
-
Export the required environment variables:
export GITHUB_REPOSITORY=<repository_name> export COVERAGE_PATH=<path_to_coverage_report> export GITHUB_TOKEN=<github_token> export GITHUB_PR_NUMBER=<pull_request_number>
-
Run the action:
make run
NOTE: This project is inspired from py-cov-action/python-coverage-comment-action, LICENSE with few modifications.