badge-generator is a GitHub Action that creates dynamic, customizable badges using Shields.io. Perfect for displaying code coverage, build status, quality metrics, or any custom label and value in your repository.
Add the following step to your workflow file (e.g. .github/workflows/ci.yml):
# Example
- name: Generate coverage badge
uses: ernanej/badge-generator@main
with:
name: '98.7%'
prefix: 'coverage'
icon: 'jest'
color: 'green'
style: 'flat-square'
path: 'badges/coverage.svg'
branch: 'badge'👉 See more examples in examples/README.md
| Input | Required | Description |
|---|---|---|
name |
✅ | Right-hand side value (e.g. "98.7%") |
prefix |
❌ | Left-hand label (e.g. "coverage") |
icon |
❌ | Icon name (e.g. jest, github, codecov, etc.) |
color |
❌ | Badge color (e.g. green, #ffaa00) |
style |
❌ | Badge style (flat, flat-square, plastic, etc.) |
labelColor |
❌ | Label background color |
logoColor |
❌ | Icon/logo color |
link |
❌ | URL or comma-separated URLs the badge should link to |
cacheSeconds |
❌ | Cache duration (seconds) for badge |
path |
✅ | Local file path where badge will be saved (e.g. badges/coverage.svg) |
badge_branch |
❌ | Branch where the badge will be committed (default: badge-generator) |
main_branch |
❌ | The main branch name (default: main) |
github_token |
❌ | GitHub token (required for PR comments) |
comment_title |
❌ | Custom title for the PR comment (default: Code Coverage Result) |
When github_token is provided, the action can comment the latest coverage result on the pull request. If you use the action multiple times in the same workflow, set comment_title to make each comment clearer.
- name: Generate Vitest coverage badge
uses: ernanej/badge-generator@main
with:
name: '79.14%'
prefix: 'coverage'
path: 'badges/coverage.svg'
github_token: ${{ secrets.GITHUB_TOKEN }}
comment_title: 'Vitest Coverage Result'
- name: Generate Cypress coverage badge
uses: ernanej/badge-generator@main
with:
name: '42.66%'
prefix: 'coverage'
path: 'badges/coverage-cypress.svg'
github_token: ${{ secrets.GITHUB_TOKEN }}
comment_title: 'Cypress Coverage Result'npm install
npm run build
node local-test.js # Test the action locallyThis project uses the awesome Shields.io service to generate dynamic badge images. If you find it useful, consider supporting their open-source work.
MIT © Ernane Ferreira