Home

Awesome

GOBadge

Coverage

👆 Easily create and insert coverage badge (or any other badge) in your readme with go

Using https://shields.io, the executable will generate a coverage badge based on the coverage output. The badge will be inserted on the second line of the readme if it doesn't exist, and will be updated if already present.

How to use

Install the executable

go install github.com/AlexBeauchemin/gobadge@latest

Make sure you generate a coverage file with your total coverage, something like

go test ./... -covermode=count -coverprofile=coverage.out fmt
go tool cover -func=coverage.out -o=coverage.out

Your output should looks like this, with the total as the last line

...
github.com/AlexBeauchemin/go-coverage-badge/gobadge.go:36:	retrieveTotalCoverage	87.5%
github.com/AlexBeauchemin/go-coverage-badge/gobadge.go:53:	updateReadme		80.0%
total:								(statements)		67.4%

Then run the executable

gobadge -filename=coverage.out

Flags

FlagDefaultDescription
filenameoutput.outFile to scan for the coverage total
labelCoverageLeft-side content of the badge
valueRight-side content of the badge
yellow30At what percentage the badge will become yellow instead of red
green70At what percentage the badge becomes green instead of yellow
colorForce a color for the badge
targetREADME.mdWhere to insert the badge
linkOptional URL when you click the badge

Examples

gobadge -filename=coverage.out
gobadge -label="Go Coverage" -value=55.6% -color=blue -target=OTHER_README.md
gobadge -yellow=60 -green=80
gobadge -color=ff69b4
gobadge -link=https://github.com/project/repo/actions/workflows/test.yml

TODO