Simple action to generate code coverage badges from a previously created dotnet OpenCover XML file generated by tools such as coverlet.
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/)
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 "./"
.
Threshold percentage at which a red badge would appear.
Optional: When set will commit the changed badges to the repo. Default true
.
Optional: When set will checkout the given branch name before committing the changed badges. Default is the current main branch.
GitHub repo token so that the changed file can be committed, like ${{ secrets.CI_TOKEN }}