Code Coverage Summary

repository·master·Indexed 42 days ago

https://github.com/irongut/codecoveragesummary

A GitHub Action that parses Cobertura XML coverage files to generate human-readable text or markdown summaries, including badges and health indicators. It supports tools such as Coverlet, gcovr, simplecov, and MATLAB, and can be configured to fail workflows if line rates fall below specified thresholds.

Tokens
1.2K
Snippets
2
Records
3
Agent score
4%

What's inside Code Coverage Summary

  1. Use Code Coverage Summary in GitHub Actions

    master

    Code Coverage Summary is a GitHub Action that processes Cobertura format code coverage files and generates a text or markdown summary. This summary can be used to post Pull Request comments or include coverage data in Release Notes.

    Requirements:

    • Must use a Linux runner (as it is a Docker-based action).
    • Input files must be in Cobertura XML format (supported tools include Coverlet, gcovr, simplecov, and MATLAB).

    Basic Usage:

    name: Code Coverage Summary Report
    uses: irongut/CodeCoverageSummary@v1.3.0
    with:
      filename: coverage.cobertura.xml
  2. Complete .NET CI Workflow Example

    master

    This example demonstrates a full .NET 6 CI pipeline: checking out code, setting up .NET, restoring, building, testing with XPlat Code Coverage, generating a markdown report with custom thresholds, and posting that report as a Pull Request comment using marocchino/sticky-pull-request-comment@v2.

    name: .Net 6 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: 6.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: Code Coverage Report
          uses: irongut/CodeCoverageSummary@v1.3.0
          with:
            filename: coverage/**/coverage.cobertura.xml
            badge: true
            fail_below_min: true
            format: markdown
            hide_branch_rate: false
            hide_complexity: true
            indicators: true
            output: both
            thresholds: '60 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
  3. Configure Code Coverage Summary inputs

    master

    The following inputs are available to customize the coverage report:

    InputDescription
    filename (Required)A comma-separated list of Cobertura XML files or glob patterns. Use quotes if paths contain spaces.
    badgeInclude a shields.io badge reporting Line Rate. true or false (default).
    fail_below_minFail the workflow if the overall Line Rate is below the lower threshold. true or false (default).
    formatOutput format: markdown or text (default).
    hide_branch_rateHide Branch Rate metrics. true or false (default).
    hide_complexityHide Complexity metrics. true or false (default).
    indicatorsInclude health indicators (e.g., ✔, ❌) in the output. true (default) or false.
    outputWhere to send the report: console (default), file, or both. file outputs to code-coverage-results.txt (text) or code-coverage-results.md (markdown).
    thresholdsLower and upper threshold percentages for badges and indicators. Separate with a space and enclose in quotes. Default: '50 75'.