Skip to content

GitHub Action to read an open cover xml file in the project folder and generate a badge to use in readme file

License

Notifications You must be signed in to change notification settings

danpetitt/open-cover-badge-generator-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 }}