GitHub Action
OpenCover Badge Generator
Simple action to generate code coverage badges from a previously created OpenCover XML file.
(Note: Ensure you get the case of the paths correct for the agent running the job.)
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/open-cover-badge-generator-action@1.0.6
with:
path-to-opencover-xml: ./test/opencover.xml
path-to-badges: ./
minimum-coverage: 75
repo-token: ${{ secrets.CI_TOKEN }}
Once generated you will get two badges called coverage-badge-line.svg
and coverage-badge-branch.svg
saved into the path you specified that you can then add to your project readme like:
[![Coverage Status](./coverage-badge-line.svg)](https://github.com/danpetitt/open-cover-badge-generator-action/)
Required Path to the open cover xml file
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 "./"
.
Required Threshold percentage at which a red badge would appear.
Required GitHub repo token so that the changed file can be committed, like ${{ secrets.CI_TOKEN }}