Create a Coverage report comment on Github PR
Permissions needed for the Github Token:
Pull requests:read
Pull requests:write
If you have given ANNOTATIONS_DATA_BRANCH
branch then Github Token also requires content write permissions.
Read more on how to use this document.
Contents:read
Contents:write
install:
pip install python-coverage-comment
run:
GITHUB_REPOSITORY=<repository_name> \
COVERAGE_PATH=<path_to_coverage_report> \
GITHUB_TOKEN=<github_token> \
GITHUB_PR_NUMBER=<pull_request_number> \
codecov
GITHUB_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 action is running. (Optional)GITHUB_REF
: The branch to run the action on. If 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.
SUBPROJECT_ID
: The ID or URL of the subproject or report.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.SKIP_COVERAGE
: Skip coverage reporting as github comment and generate only annotaions. Default is False.ANNOTATIONS_DATA_BRANCH
: The branch to store the annotations. Read more about this document.ANNOTATIONS_OUTPUT_PATH
: The path where the annotaions should be stored. Should be a path to folder.ANNOTATE_MISSING_LINES
: Whether to annotate missing lines in the coverage report. Default is False.ANNOTATION_TYPE
: The type of annotation to use for missing lines. 'notice' or 'warning' or 'error'. Default is 'warning'.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.COVERAGE_REPORT_URL
: URL of the full coverage report to mention in the comment.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 coverage percentage is calculated based on the uncovered branches in the affected files.
- If the complete project report option is enabled, the report is included as-is in the comment, without any modifications or recalculations. If you notice discrepancies between the PR coverage and the complete project coverage, this may be expected. For consistent results, it is recommended to enable branch coverage when your report includes it.
To get started, follow these steps:
-
Clone the repository:
git clone <repository_url>
-
Navigate to the cloned repository:
cd <repository_directory>
-
create
.env
:echo "PIPENV_VENV_IN_PROJECT=1" >> .env
-
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 almost copy of py-cov-action/python-coverage-comment-action, LICENSE with few modifications.