Skip to content

Latest commit

 

History

History
65 lines (43 loc) · 2.45 KB

File metadata and controls

65 lines (43 loc) · 2.45 KB

Github Action OpenCover Badge Generator

Simple action to generate code coverage badges from a previously created dotnet OpenCover XML file generated by tools such as coverlet.

Usage

First ensure you have a valid opencover.xml code coverage file generated by something like coverlet. For example, using the dotnet core command dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover.

Then, generate an access token and save as a GitHub Secret which you can then reference in your Project Workflow yaml as follows:

on:
  pull_request:
    types: [opened]
    branches:
      - master
jobs:
  coverage:
    runs-on: ubuntu-latest
    steps:
      - name: OpenCover Badge Generator
        uses: danpetitt/[email protected]
        with:
          path-to-opencover-xml: ./test/opencover.xml
          path-to-badges: ./
          minimum-coverage: 75
          commit-badges: false
          repo-token: ${{ secrets.CI_TOKEN }}

(Note: Ensure you get the case of the paths correct for the agent running the job.)

Once generated you will get two badges called coverage-badge-line.svg and coverage-badge-branch.svg saved into the path you specified which you can then add to your project readme like:

[![Line Coverage Status](./coverage-badge-line.svg)](https://github.com/danpetitt/open-cover-badge-generator-action/)

[![Branch Coverage Status](./coverage-badge-branch.svg)](https://github.com/danpetitt/open-cover-badge-generator-action/)

Inputs

path-to-opencover-xml (Required)

Path to the open cover xml file

path-to-badges (Optional)

Optional: Path where the line and branch coverage svgs would be saved; these will be saved with the names coverage-badge-line.svg and coverage-badge-branch.svg; if not specified the files will be saved into the project root. Default "./".

minimum-coverage (Required)

Threshold percentage at which a red badge would appear.

commit-badges (Optional)

Optional: When set will commit the changed badges to the repo. Default true.

commit-branch-name (Optional)

Optional: When set will checkout the given branch name before committing the changed badges. Default is the current main branch.

repo-token (Required)

GitHub repo token so that the changed file can be committed, like ${{ secrets.CI_TOKEN }}