Skip to content
Fallow home
All docs pages

Docs home

Health badge

Write an SVG badge with the health score of your project, and show it in the README, also for a private repository.

The README is the first page that a new contributor reads. A badge there shows the health score of the project as a grade and a number, and its color changes when the score drops. These are the badges of four public projects:

zod: B (71)preact: B (76)svelte: B (73)vite: C (65)

You write the badge as an SVG file in the repository, so it works for a private repository too, and no outside service reads your code.

Before you start

  • Install the dependencies of the project. The score depends on the findings, and fallow reads the packages in node_modules. Without them, the score drops for findings that are not real.

Steps

  1. Write the badge:

    mkdir -p .github/badges
    npx fallow health --format badge > .github/badges/health.svg
  2. Add the badge to the README with a relative link:

    ![fallow health](.github/badges/health.svg)
  3. Commit both files.

--format badge computes the score, so you do not need --score. The SVG contains everything that it needs and loads nothing from another host. Each badge has its own element ids, so a page can show more than one badge.

A reader sees the color before the number, so the color follows the grade:

GradeColor
ABright green
BGreen
CYellow
DOrange
FRed

Health score gives the score range of each grade.

Check the result

Open the file in a browser, or read its first lines. They name the grade and the score. For the demo project, the badge shows C (60):

<svg xmlns="http://www.w3.org/2000/svg" width="88" height="20" role="img" aria-label="fallow: C (60)">
<title>fallow: C (60)</title>

Update the badge from CI

A badge that you commit changes only when you write it again, so after some weeks it shows an old score. To update it on each push to the default branch, let a CI job write it and commit it:

# .github/workflows/badge.yml
name: Health badge

on:
  push:
    branches: [main]

permissions:
  contents: write

jobs:
  badge:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: |
          mkdir -p .github/badges
          npx fallow health --format badge > .github/badges/health.svg
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git add .github/badges/health.svg
          git diff --quiet --cached || git commit -m "chore: update health badge [skip ci]"
          git push

This works for a private repository too. GitHub shows a relative image link to each reader who can read the repository. [skip ci] in the commit message tells GitHub not to start a workflow for the commit of the badge.

A badge for each workspace

In a monorepo, one score for the whole repository hides which package needs work. Scope the score to one workspace with --workspace, and write one badge for each package README:

npx fallow health --format badge --workspace @acme/web > .github/badges/web.svg

A badge from shields.io

When the other badges of your README come from shields.io, a fallow badge in the same style fits better. Write a JSON endpoint file from the score:

npx fallow health --format json --score --quiet \
  | jq '{schemaVersion: 1, label: "fallow", message: "\(.health_score.grade) (\(.health_score.score | floor))", color: (if .health_score.score >= 85 then "brightgreen" elif .health_score.score >= 70 then "green" elif .health_score.score >= 55 then "yellow" elif .health_score.score >= 40 then "orange" else "red" end)}' \
  > health-badge.json

For the demo project, the file holds:

{
  "schemaVersion": 1,
  "label": "fallow",
  "message": "C (60)",
  "color": "yellow"
}

Publish the file at a public URL, and use the endpoint badge of shields.io:

![fallow health](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/your-org/your-repo/main/health-badge.json)

shields.io reads the file from a public URL, so this works only for a public repository. Do not put a token in the URL.

If it fails

  • The badge shows a broken image. The README links to a file that the branch does not have, or to a private repository from an outside host. Use a relative link to a file in the same branch.
  • The score is lower than expected. The job did not install the dependencies, so fallow reported used packages as unused. Run the install step before fallow.