A lightweight, local Go test coverage badge generator that creates SVG badges similar to shields.io.
- 🚀 Runs entirely locally - no external API calls or Internet required
- 🧪 Automatically runs Go tests and extracts coverage data, if needed
- 📊 Generates coverage badges based on test provided coverage % if you already have it
- 🎨 Generates shields.io-style SVG badges with embedded template
- 🔧 Fully configurable test commands, thresholds, and templates
- 📦 Single binary with no dependencies - template is embedded
- 🛠️ Template/Config dumping - export the default template and config for customization
Default Color Scheme & Levels:
go install github.com/alexaandru/stampli@latest # or, even better
go get tool github.com/alexaandru/stampli@latestRun with defaults (uses go test ./... -coverprofile=coverage.out):
./stampli # -h for helpThis generates coverage-badge.svg in the current directory by running
the tests and extracting coverage data.
Alternatively, you can provide the coverage percentage directly:
./stampli -coverage 85.4See help for more options, including customizing the badge SVG template,
the command used for running tests (i.e. replace it with make test, etc.)
the levels or the default config, etc.
The Levels system allows fine-grained control over thresholds and colors,
either via cli flag or via JSON config file:
# Format: level=color,level=color,...
./stampli -levels "95=#00cc00,85=#44cc11,70=#dfb317,50=#ff8c00,=#e05d44"The levels MUST include a default level (i.e. 0=#... or =#...).
Stampli uses Go's text/template package. Your template receives:
{{ .Coverage }}- Coverage percentage as string (e.g., "85.4"){{ .Color }}- Color hex code based on coverage levels{{ .TextColor }}- Optimal text color, #ffffff or #000000 depending on the background.
- name: Generate coverage badge
run: |
./stampli -output docs/coverage.svg
git add docs/coverage.svg
git commit -m "Update coverage badge" || exit 0test:
go test ./... -coverprofile=coverage.out
badge:
./stampli -command "make test" -quiet
# Generate badge with custom levels
badge-strict:
./stampli -levels "95=#00ff00,80=#ffff00,60=#ff8000,0=#ff0000"#!/bin/sh
./stampli
git add coverage-badge.svg