Socket
Book a DemoInstallSign in
Socket

github.com/alexaandru/stampli

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/alexaandru/stampli

Source
Go Modules
Version
v1.1.0
Version published
Created
Source

Stampli (aka the badge Stamper)

License Build and Test Coverage Go Report Card Go Reference Socket.dev

A lightweight, local Go test coverage badge generator that creates SVG badges similar to shields.io.

Features

  • 🚀 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:

Excellent Fair Good Poor

Installation

go install github.com/alexaandru/stampli@latest # or, even better
go get tool github.com/alexaandru/stampli@latest

Quick Start

Run with defaults (uses go test ./... -coverprofile=coverage.out):

./stampli # -h for help

This 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.4

See 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.

Coverage Levels System

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 =#...).

SVG Template Customization

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.

Integration Examples

GitHub Actions

- name: Generate coverage badge
  run: |
    ./stampli -output docs/coverage.svg
    git add docs/coverage.svg
    git commit -m "Update coverage badge" || exit 0

Make Integration

test:
	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"

Pre-commit Hook

#!/bin/sh
./stampli
git add coverage-badge.svg

License

MIT

FAQs

Package last updated on 26 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts