How to Create a Custom Badge from a Gist
schneegans/dynamic-badges-action writes shields endpoint JSON into a gist from CI, giving you a badge whose value you control from a workflow.
Create a gist to hold the badge JSON, generate a token with gist scope, then have schneegans/dynamic-badges-action write the label, message, and color on each run. Point the shields endpoint route at the gist raw URL.
Steps
- Create a gist and note its ID; add a
GIST_SECRETtoken with gist scope. - In CI, run
schneegans/dynamic-badges-actionwithlabel,message, andcolor. - Reference the gist via the shields endpoint route in your README.
Workflow
.github/workflows/ci.yml
- uses: schneegans/dynamic-badges-action@v1.7.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 8e3f1c0a2b4d
filename: widget-benchmark.json
label: benchmark
message: 1.8k ops/s
color: blueREADME markdown
README.md
Gotchas
- The token needs the
gistscope; a repo-scoped token cannot write the gist. - shields caches the gist; use the raw URL without a commit SHA so it always reads the latest.
Related guides
How to Create a Dynamic shields.io Endpoint BadgeBuild a dynamic shields.io badge by hosting a JSON document in the shields schema and pointing the endpoint r…
How to Build a Badge for a Custom MetricBuild a badge that reflects a custom metric such as bundle size by computing the value in CI, writing shields…
How to Troubleshoot a Stale or Wrong BadgeTroubleshoot a stale or wrong status badge by checking the source value, the wrong branch parameter, camo cac…