Skip to content

Using Code Coverage Summary

irongut edited this page Nov 15, 2021 · 9 revisions

Inputs

filename

Required

Code coverage file to analyse.

Note: Coverlet creates the coverage file in a random named directory (guid) so you need to copy it to a predictable path before running this Action, see the .Net 5 Workflow Example below.

badge

Include a badge reporting the Line Rate coverage in the output using shields.io - true or false (default).

Line Rate Badge
less than lower threshold (50%) Code Coverage
between thresholds (50% - 74%) Code Coverage
equal or greater than upper threshold (75%) Code Coverage

See thresholds to change these values.

fail_below_min

Fail the workflow if the overall Line Rate is below lower threshold - true or false (default). The default lower threshold is 50%, see thresholds.

format

Output Format - markdown or text (default).

indicators

Include health indicators in the output - true (default) or false.

Line Rate Indicator
less than lower threshold (50%)
between thresholds (50% - 74%)
equal or greater than upper threshold (75%)

See thresholds to change these values.

output

Output Type - console (default), file or both.

console will output the coverage summary to the GitHub Action log.

file will output the coverage summary to code-coverage-results.txt for text or code-coverage-results.md for markdown format in the workflow's working directory.

both will output the coverage summary to the Action log and a file as above.

thresholds

Lower and upper threshold percentages for badge and health indicators, lower threshold can also be used to fail the action. Separate the values with a space and enclose them in quotes; default '50 75'.

Outputs

Text Example

https://img.shields.io/badge/Code%20Coverage-83%25-success?style=flat

Company.Example: Line Rate = 83%, Branch Rate = 69%, Complexity = 671, ✔
Company.Example.Library: Line Rate = 27%, Branch Rate = 100%, Complexity = 11, ❌
Summary: Line Rate = 83% (1212 / 1460), Branch Rate = 69% (262 / 378), Complexity = 682, ✔
Minimum allowed line rate is 50%

Markdown Example

image

Usage

name: Code Coverage Summary Report
uses: irongut/[email protected]
with:
  filename: coverage/coverage.cobertura.xml

.Net 5 Workflow Example

name: .Net 5 CI Build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    name: CI Build
    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x

    - name: Restore Dependencies
      run: dotnet restore src/Example.sln

    - name: Build
      run: dotnet build src/Example.sln --configuration Release --no-restore

    - name: Test
      run: dotnet test src/Example.sln --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage

    - name: Copy Coverage To Predictable Location
      run: cp coverage/**/coverage.cobertura.xml coverage/coverage.cobertura.xml

    - name: Code Coverage Summary Report
      uses: irongut/[email protected]
      with:
        filename: coverage/coverage.cobertura.xml
        badge: true
        fail_below_min: true
        format: 'markdown'
        output: 'both'
        thresholds: '70 80'

    - name: Add Coverage PR Comment
      uses: marocchino/sticky-pull-request-comment@v2
      if: github.event_name == 'pull_request'
      with:
        recreate: true
        path: code-coverage-results.md
Clone this wiki locally