Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
umbrella

GitHub Action

Coverage Comment

v1.0.2

Coverage Comment

umbrella

Coverage Comment

Publish diff coverage report as PR comment, and create a coverage badge to display on the readme.

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Coverage Comment

uses: ewjoachim/[email protected]

Learn more about this action in ewjoachim/coverage-comment-action

Choose a version

GitHub Action: Coverage Comment

Publish diff coverage report as PR comment, and create a coverage badge to display on the readme.

See example at: https://github.com/ewjoachim/coverage-comment-action-example

What does it do?

This action operates on an already generated coverage.xml (Cobertura) file as generated by most tools, accross languages.

It has two main modes of operation:

PR mode

If acting on a PR, it will analyze the XML file, and produce a comment that will be posted to the PR. If a comment had already previously be written, it will be updated. The comment contains information on the evolution of coverage rate attributed to this PR, as well as the rate of coverage for lines that this PR introduces. There's also a small analysis for each file in a collapsed block.

See: ewjoachim/coverage-comment-action-example#3 (comment)

Default branch mode

If acting on the repository's default branch, it will extract the coverage rate and create a small JSON file that will be stored on the repository's wiki. This file will then have a stable URL, which means you can create a shields.io badge from it.

See: https://github.com/ewjoachim/coverage-comment-action-example

Usage

Setup

Please ensure that the repository wiki has been initialized with at least a single page created. Once it's done, you can disable the wiki for the repository.

Minimal usage

- name: Display coverage
  uses: ewjoachim/[email protected]
  with:
    GITHUB_TOKEN: ${{ github.token }}

Maximal usage

- name: Display coverage
  uses: ewjoachim/[email protected]
  with:
    GITHUB_TOKEN: ${{ github.token }}

    # Path and filename of the coverage XML file to analyze.
    COVERAGE_FILE: "coverage.xml"

    # Whether or not a badge will be generated and stored.
    BADGE_ENABLED: "true"

    # Name of the json file containing badge informations stored in the repo wiki.
    BADGE_FILENAME: coverage-comment-badge.json

    # If the coverage percentage is above or equal to this value, the badge will be green.
    MINIMUM_GREEN: 100

    # Same with orange. Below is red.
    MINIMUM_ORANGE: 70

    # [Advanced] Specify a different template for the comments that will be written on the PR.
    COMMENT_TEMPLATE: ""

    # [Advanced] Additional args to pass to diff cover (one per line)
    DIFF_COVER_ARGS: ""

Note on the state of this action

There is no automated test and the dependencies are not frozen, so it's possible that it fails at some point if a dependency breaks compatibility. If this happens, we'll fix it and put better checks in place.

It's probably usable as-is, but you're welcome to offer feedback and, if you want, contributions.

Note on advanced options

COMMENT_TEMPLATE and DIFF_COVER_ARGS are somewhat experimental. They haven't been thouroughly tested.