Skip to content

ErnaneJ/badge-generator

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

📛 badge-generator

Latest Release Stars Forks Coverage

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.

🚀 Quick Usage

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)

PR comment customization

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'

🛠️ Local Development

npm install
npm run build
node local-test.js   # Test the action locally

🙏 Acknowledgements

This project uses the awesome Shields.io service to generate dynamic badge images. If you find it useful, consider supporting their open-source work.

📄 License

MIT © Ernane Ferreira

About

Is a GitHub Action that creates dynamic, customizable badges using Shields.io. It's perfect for displaying code coverage, build status, code quality, and other metrics directly in your repository.

Resources

License

Stars

Watchers

Forks

Contributors