Skip to main content

python-coverage-comment

Create a Coverage report comment on Github PR

To generate the pytest coverage report

pipenv run pytest tests  --cov-branch --cov=codecov --cov-report=json:/tmp/report.json

Permissions needed for the Github Token:

Contents:read 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 here.

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

Setting up Local Environment using Pipenv

To get started, follow these steps:

  1. Clone the repository:

    git clone <repository_url>
    
  2. Navigate to the cloned repository:

    cd <repository_directory>
    
  3. Build the project:

    make all
    
  4. 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>
    
  5. Run the action:

    make run
    

Required Environment Variables

  • 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.

Optional Environment Variables

  • GITHUB_BASE_REF: The base branch for the pull request. Default is main.
  • 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 here.
  • ANNOTATIONS_OUTPUT_PATH: The path where the annotaions should be stored. Should be a .json file.
  • 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. Default is 'warning'.
  • MAX_FILES_IN_COMMENT: The maximum number of files to include in the coverage report comment. Default is 25.
  • 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.

That's it! You have successfully cloned the repository and built the project.

Custom Installation

  1. Install Python: Make sure you have Python installed on your system. You can download and install Python from the official Python website.

  2. Install Pipenv: Pipenv is a package manager that combines pip and virtualenv. You can install Pipenv using pip, the Python package installer. Open your terminal or command prompt and run the following command:

    pip install pipenv
    
  3. Install project dependencies: To install the project dependencies specified in the Pipfile, run the following command:

    pipenv install --dev
    
  4. Activate the virtual environment: To activate the virtual environment created by Pipenv, run the following command:

    pipenv shell
    
  5. Run your project: You can now run your project using the activated virtual environment. For example, if your project has a run.py file, you can run it using the following command:

    python run.py
    
  6. Install pre-commit hooks: To set up pre-commit hooks for your project, run the following command:

    pipenv run pre-commit install
    

    This will install and configure pre-commit hooks that will run before each commit to enforce code quality and style standards.

That's it! You have successfully set up your local environment using Pipenv.

This project is almost copy of [py-cov-action/python-coverage-comment-action] (https://github.com/py-cov-action/python-coverage-comment-action.git) with few modifications.

Metadata

Release files for python-coverage-comment 2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-coverage-comment 2.1
File Size Uploaded Provenance
python_coverage_comment-2.1.tar.gz 33.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for python-coverage-comment 2.1
File Interpreter ABI Platform
python_coverage_comment-2.1-py3-none-any.whl Python 3 none any Details

Total release size: 58.4 kB

Release files / python_coverage_comment-2.1.tar.gz

Download URL python_coverage_comment-2.1.tar.gz
Size 33.1 kB
Tags Source
SHA-256 checksum
How to use checksums
09390506f134b7438bbffd49a26aa03a188fa217f5a77976e54f9e10f070dbe1
BLAKE2b-256 checksum
How to use checksums
8071cbdcd02e31ee056736cd47f7911b306554e2d3014fe11213819a236b7ef7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release files / python_coverage_comment-2.1-py3-none-any.whl

Download URL python_coverage_comment-2.1-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
439a06a4cf9e6567e74adab2c24bf45db94ddf8bc4576174af59c10d0bad5f8e
BLAKE2b-256 checksum
How to use checksums
1209a8de2fb20fe97f87fa96d5f204f3fad70082613bc494003cd124eb36e693
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Security for python-coverage-comment 2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page