github-metrics

module
v1.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: MIT

README

github-metrics

CI Release Go version License

Generate SVG / PNG / JPEG / JSON metrics for your GitHub profile or a single repository — as a GitHub Action, a standalone CLI, or a Docker container. Single Go binary, no Node runtime required.

This project is a Go reimplementation of a curated subset of lowlighter/metrics. Adopted inputs are drop-in compatible: existing upstream workflows continue to run by swapping one uses: line. See docs/migration-to-go.md for the full migration guide and unported-feature list.


Highlights

  • Drop-in Action upgrade — uses: mjun0812/github-metrics@v1 reads the same with: inputs as lowlighter/metrics@v3 for every adopted feature. Unported feature gates (plugin_anilist: yes etc.) are silently no-op'd so workflow files migrate without edits.
  • 21 plugins across two templates — see Plugins below.
  • 4 output formats — SVG, PNG, JPEG, JSON (upstream byte-compatible).
  • Multi-arch container — linux/amd64 + linux/arm64 on ghcr.io/mjun0812/github-metrics, signed with Sigstore cosign keyless OIDC (transparency log).
  • Cross-compiled binaries — Linux / macOS × amd64 / arm64 attached to every release with SHA256SUMS and per-artifact cosign sign-blob bundles.
  • Hardened runtime — non-root user (uid 10001), chromium + Noto fonts bundled, no Node toolchain.

Quick start

GitHub Action
# .github/workflows/metrics.yml
name: Metrics
on:
  schedule: [{cron: '0 0 * * *'}]
  workflow_dispatch:

jobs:
  github-metrics:
    runs-on: ubuntu-latest
    steps:
      - uses: mjun0812/github-metrics@v1
        with:
          user: octocat
          token: ${{ secrets.METRICS_TOKEN }}
          template: classic
          plugin_languages: 'yes'
          plugin_languages_limit: '5'
          committer_branch: main
          output_action: commit
          output_condition: data-changed

@v1 is the recommended pin — it resolves to the latest v1.x.y release so consumers automatically receive bug-fix and feature patches without edits. For immutable bytes pin to @v1.0.0 (or any exact vX.Y.Z form). @latest is also published for convenience but is not recommended for production workflows.

Repository template

template: repository re-centers the rendered SVG on a single repository instead of a user profile:

- uses: mjun0812/github-metrics@v1
  with:
    user: ${{ github.repository_owner }}
    repo: ${{ github.event.repository.name }}
    template: repository
    token: ${{ secrets.METRICS_TOKEN }}

The JSON output adds a data.repo field next to the existing data.user; the SVG features the repo's avatar, description, community health and recent activity.

CLI
# Install from a GitHub Release (linux/darwin × amd64/arm64).
# Replace `linux_amd64` with your platform tag.
curl -L -o metrics-cli \
  https://github.com/mjun0812/github-metrics/releases/download/v1.0.0/metrics-cli_v1.0.0_linux_amd64
chmod +x metrics-cli

# …or via go install (requires Go 1.26+):
go install github.com/mjun0812/github-metrics/cmd/metrics-cli@v1.0.0

# Render an SVG to stdout. GITHUB_TOKEN must be set in your shell.
metrics-cli --user octocat --token-env GITHUB_TOKEN \
  --output svg --dryrun --filename -
Docker
docker run --rm \
  -v "$PWD/out:/renders" \
  -w /renders \
  -e GITHUB_TOKEN \
  ghcr.io/mjun0812/github-metrics:v1.0.0 \
  --user octocat --token-env GITHUB_TOKEN --template classic \
  --output svg --filename github-metrics.svg

The image is multi-arch — docker pull automatically resolves to your host architecture.

Authentication

Every invocation needs a GitHub token:

  • Action mode: pass via with.token — typically ${{ secrets.METRICS_TOKEN }} (a Personal Access Token) for full metrics, or ${{ github.token }} for public-only data.
  • CLI / Docker mode: set GITHUB_TOKEN in the environment and use --token-env GITHUB_TOKEN.

The token needs at minimum public_repo (classic PAT) or the read scopes for each enabled plugin's data (issues, pulls, projects, etc.) for fine-grained tokens. The base / core plugins always fetch the target user's profile, so a missing token fails immediately.

Plugins

achievements activity calendar
achievements activity calendar
contributors habits isocalendar
contributors habits isocalendar
languages notable people
languages notable people
projects reactions repositories
projects reactions repositories
sponsors sponsorships stargazers
sponsors sponsorships stargazers
starlists stars topics
starlists stars topics
traffic
traffic

The 19 user-facing plugins above are always available; enable each via plugin_<slug>: yes and click a tile for the full per-plugin doc page. Two additional internal plugins (base, core) power the metadata pipeline and run automatically.

The languages plugin ships recent and indepth sub-modes via plugin_languages_sections. topics and starlists require the Action / Docker runtime (Chromium is bundled there) — the standalone Go binary skips them with a warning.

Every input is documented in action.yml and is identical to the corresponding upstream input. Inputs gating unported plugins (e.g., plugin_anilist, plugin_leetcode) are accepted and silently ignored — no migration of existing workflows is required.

Output formats

Format MIME Rendering pipeline
svg image/svg+xml Go templates → chromedp Resize
png / jpeg image/png/jpeg + chromedp CaptureScreenshot
json application/json Upstream byte-compatible envelope

JSON output is byte-compatible with upstream lowlighter/metrics for the adopted plugins; downstream tools that consume the JSON envelope work unchanged. SVG output is DOM-structurally equivalent — element / attribute / class structure matches upstream, but dynamic strings (version footer, generated timestamp) differ.

Migrating from lowlighter/metrics

  1. Swap the uses: line:

    - uses: lowlighter/metrics@v3.34
    + uses: mjun0812/github-metrics@v1
    

    @v1 automatically resolves to the latest v1.x.y release; use @v1.0.0 (or any exact vX.Y.Z) if you prefer to pin immutable bytes.

  2. Re-run the workflow. Unported plugin gates remain in your with: block silently; remove them at your leisure.

  3. Compare output: JSON should diff cleanly; SVG should match structurally (xmllint --format before diffing).

docs/migration-to-go.md walks through the full matrix — adopted vs unported plugins, templates, output formats, and the one-line rollback procedure.

Release verification

Every release is signed with cosign keyless OIDC against the GitHub Actions issuer. To verify the image manifest:

cosign verify ghcr.io/mjun0812/github-metrics:v1.0.0 \
  --certificate-identity-regexp \
    'https://github.com/mjun0812/github-metrics/.github/workflows/release.yml@refs/tags/v.*' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com

Binaries on the GitHub Release ship with a SHA256SUMS file plus per-artifact .sig, .cert, and .cosign.bundle files. Verify a binary with cosign verify-blob:

cosign verify-blob metrics-cli_v1.0.0_linux_amd64 \
  --bundle metrics-cli_v1.0.0_linux_amd64.cosign.bundle \
  --certificate-identity-regexp \
    'https://github.com/mjun0812/github-metrics/.github/workflows/release.yml@refs/tags/v.*' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com

The helper scripts/release-verify.sh wraps the manifest, checksum, signature, and action.yml reference checks into a single command for maintainer post-release validation.

Contributing

Bug reports and pull requests welcome. Before opening a PR, please read CONTRIBUTING.md for the development workflow (toolchain, hooks, test categories) and the project's scope discipline. The unported-feature list lives in docs/migration-to-go.md §3 — proposals that extend that scope are welcome via a discussion issue first.

License

MIT. This project is a Go reimplementation derived from lowlighter/metrics (MIT-licensed); upstream attribution is preserved per the MIT license terms.

GitHub Octicons assets (under assets/octicons/) are MIT-licensed by GitHub, Inc. and embedded via //go:embed.

Directories

Path Synopsis
Package assets bundles plugin/template metadata, GraphQL queries, and other static files into the binary via go:embed.
Package assets bundles plugin/template metadata, GraphQL queries, and other static files into the binary via go:embed.
cmd
metrics-cli command
Package main provides the metrics-cli binary entrypoint.
Package main provides the metrics-cli binary entrypoint.
internal
action
Package action implements the GitHub Action / CLI entry-point logic for the metrics-cli binary.
Package action implements the GitHub Action / CLI entry-point logic for the metrics-cli binary.
config
Package config holds settings, metadata, and inputs loaders for github-metrics.
Package config holds settings, metadata, and inputs loaders for github-metrics.
ctxutil
Package ctxutil provides typed accessors for request-scoped values (currently: the GitHub login the engine is operating on) so that log records and downstream code can correlate work to a single user or organization.
Package ctxutil provides typed accessors for request-scoped values (currently: the GitHub login the engine is operating on) so that log records and downstream code can correlate work to a single user or organization.
engine
Package engine wires together the base plugin, the core plugin runner, and the active template into a single Compute call.
Package engine wires together the base plugin, the core plugin runner, and the active template into a single Compute call.
errors
Package errors defines the typed error model for the github-metrics project.
Package errors defines the typed error model for the github-metrics project.
format
Package format provides display helpers for rendering numbers, byte counts, percentages, timestamps and error messages.
Package format provides display helpers for rendering numbers, byte counts, percentages, timestamps and error messages.
githubapi
Package githubapi wraps GitHub REST and GraphQL access, the rate tracker, and the MOCKED_TOKEN safety guard.
Package githubapi wraps GitHub REST and GraphQL access, the rate tracker, and the MOCKED_TOKEN safety guard.
httpx
Package httpx wraps net/http with retry, structured logging, and the User-Agent string the project uses for every outbound request.
Package httpx wraps net/http with retry, structured logging, and the User-Agent string the project uses for every outbound request.
logger
Package logger configures a slog logger for the github-metrics project.
Package logger configures a slog logger for the github-metrics project.
plugins
Package plugins defines the plugin contract that every github-metrics data source implements, together with the in-memory Data structure the engine builds up as it executes plugins.
Package plugins defines the plugin contract that every github-metrics data source implements, together with the in-memory Data structure the engine builds up as it executes plugins.
plugins/achievements
Package achievements owns the M4 "achievements" plugin.
Package achievements owns the M4 "achievements" plugin.
plugins/activity
Package activity owns the M4 "activity" plugin.
Package activity owns the M4 "activity" plugin.
plugins/base
Package base owns the special "base" plugin: it runs before every other plugin and populates the shared Data.User / Data.Organization / Data.Computed fields that downstream plugins depend on.
Package base owns the special "base" plugin: it runs before every other plugin and populates the shared Data.User / Data.Organization / Data.Computed fields that downstream plugins depend on.
plugins/calendar
Package calendar owns the M4 "calendar" plugin.
Package calendar owns the M4 "calendar" plugin.
plugins/contributors
Package contributors owns the M4 "contributors" plugin.
Package contributors owns the M4 "contributors" plugin.
plugins/core
Package core hosts the special "core" plugin.
Package core hosts the special "core" plugin.
plugins/habits
Package habits owns the M4 "habits" plugin.
Package habits owns the M4 "habits" plugin.
plugins/isocalendar
Package isocalendar owns the M4 "isocalendar" plugin.
Package isocalendar owns the M4 "isocalendar" plugin.
plugins/languages
Package languages — indepth.go implements the "languages.indepth" sub-mode of the M4 languages plugin.
Package languages — indepth.go implements the "languages.indepth" sub-mode of the M4 languages plugin.
plugins/notable
Package notable owns the M4 "notable" plugin.
Package notable owns the M4 "notable" plugin.
plugins/people
Package people owns the M4 "people" plugin.
Package people owns the M4 "people" plugin.
plugins/projects
Package projects owns the M4 "projects" plugin.
Package projects owns the M4 "projects" plugin.
plugins/reactions
Package reactions owns the M4 "reactions" plugin.
Package reactions owns the M4 "reactions" plugin.
plugins/repositories
Package repositories owns the M4 "repositories" plugin.
Package repositories owns the M4 "repositories" plugin.
plugins/sponsors
Package sponsors owns the M4 "sponsors" plugin.
Package sponsors owns the M4 "sponsors" plugin.
plugins/sponsorships
Package sponsorships owns the M4 "sponsorships" plugin.
Package sponsorships owns the M4 "sponsorships" plugin.
plugins/stargazers
Package stargazers owns the M4 "stargazers" plugin.
Package stargazers owns the M4 "stargazers" plugin.
plugins/starlists
Package starlists owns the M4 "starlists" plugin.
Package starlists owns the M4 "starlists" plugin.
plugins/stars
Package stars owns the M4 "stars" plugin.
Package stars owns the M4 "stars" plugin.
plugins/topics
Package topics owns the M4 "topics" plugin.
Package topics owns the M4 "topics" plugin.
plugins/traffic
Package traffic owns the M4 "traffic" plugin.
Package traffic owns the M4 "traffic" plugin.
render
Package render implements the chromedp-backed SVG resize, the pure-Go svg.Hash, the SVG decoration pipeline (octicon / CSS purge / XML format), and the small Renderer interface that engine.Compute consumes.
Package render implements the chromedp-backed SVG resize, the pure-Go svg.Hash, the SVG decoration pipeline (octicon / CSS purge / XML format), and the small Renderer interface that engine.Compute consumes.
templates
Package templates defines the Template contract used by the engine to render a request into one of the supported output formats.
Package templates defines the Template contract used by the engine to render a request into one of the supported output formats.
templates/classic
Package classic implements the M2 "classic" template — the default upstream GitHub-visual-identity SVG layout.
Package classic implements the M2 "classic" template — the default upstream GitHub-visual-identity SVG layout.
templates/classic/partials
Package partials hosts the partial functions assembled by the classic template.
Package partials hosts the partial functions assembled by the classic template.
templates/repository
Package repository implements the M7 "repository" template — the upstream-equivalent SVG layout focused on a single repository instead of a user profile.
Package repository implements the M7 "repository" template — the upstream-equivalent SVG layout focused on a single repository instead of a user profile.
templates/repository/partials
Package partials hosts the repository-template-specific partials the M7 layout needs.
Package partials hosts the repository-template-specific partials the M7 layout needs.
testutil
Package testutil hosts the shared test infrastructure landed in M9.
Package testutil hosts the shared test infrastructure landed in M9.
testutil/golden
Package golden hosts the M9 unified golden-file workflow: Compare / CompareSVG / CompareJSON sharing the `-update` flag declared in tests/integration/output_json_test.go.
Package golden hosts the M9 unified golden-file workflow: Compare / CompareSVG / CompareJSON sharing the `-update` flag declared in tests/integration/output_json_test.go.
testutil/mocks
Package mocks hosts the M9 shared mock RoundTrippers + PluginContext builder consumed by `*_test.go` files across the project.
Package mocks hosts the M9 shared mock RoundTrippers + PluginContext builder consumed by `*_test.go` files across the project.
testutil/svgcontent
Package svgcontent extracts the *semantic* (visible / structural) content of a rendered metrics SVG so tests can assert on what a viewer actually sees — not on byte equality or pixel height.
Package svgcontent extracts the *semantic* (visible / structural) content of a rendered metrics SVG so tests can assert on what a viewer actually sees — not on byte equality or pixel height.
tools/check-compat command
Command check-compat diffs the input-key sets between the upstream lowlighter/metrics checkout (./org_repo) and the vendored copy under assets/.
Command check-compat diffs the input-key sets between the upstream lowlighter/metrics checkout (./org_repo) and the vendored copy under assets/.
tools/gen-action-yml command
Command gen-action-yml generates the project's action.yml from the embedded plugin / template metadata.yml files + core input definitions.
Command gen-action-yml generates the project's action.yml from the embedded plugin / template metadata.yml files + core input definitions.
tools/gen-graphql command
Command gen-graphql wraps genqlient's code generator so it picks up the project's pinned dependency versions (notably the modern golang.org/x/tools required by Go 1.26+) instead of whatever transient versions `go run github.com/Khan/genqlient` would resolve to.
Command gen-graphql wraps genqlient's code generator so it picks up the project's pinned dependency versions (notably the modern golang.org/x/tools required by Go 1.26+) instead of whatever transient versions `go run github.com/Khan/genqlient` would resolve to.
tools/gen-octicons command
Command gen-octicons reads the @primer/octicons build/data.json shipped by the npm package and writes a trimmed, embed-friendly assets/octicons/data.json that internal/render.ReplaceOcticons consumes at runtime.
Command gen-octicons reads the @primer/octicons build/data.json shipped by the npm package and writes a trimmed, embed-friendly assets/octicons/data.json that internal/render.ReplaceOcticons consumes at runtime.
tools/gen-plugin-docs command
Command gen-plugin-docs emits per-plugin markdown pages under docs/plugins/ and refreshes the plugins-gallery AUTOGEN block inside README.md.
Command gen-plugin-docs emits per-plugin markdown pages under docs/plugins/ and refreshes the plugins-gallery AUTOGEN block inside README.md.
tools/normalize-svg-stream command
Package main implements normalize-svg-stream: a thin stdin→stdout masker that replaces the two dynamic footer fragments in an SVG so committed samples under docs/examples/ stay byte-stable across re-runs (FR-008 idempotency).
Package main implements normalize-svg-stream: a thin stdin→stdout masker that replaces the two dynamic footer fragments in an SVG so committed samples under docs/examples/ stay byte-stable across re-runs (FR-008 idempotency).
tools/record-fixtures command
Command record-fixtures captures real GitHub GraphQL responses for a fixed set of accounts/repos and vendors them under tests/fixtures/ as replay fixtures for the layer-2 data tests.
Command record-fixtures captures real GitHub GraphQL responses for a fixed set of accounts/repos and vendors them under tests/fixtures/ as replay fixtures for the layer-2 data tests.
tools/svg2png command
Command svg2png rasterizes one or more standalone metrics SVG files to PNG using the same chromedp-based renderer the production pipeline uses (internal/render.Browser + Resize).
Command svg2png rasterizes one or more standalone metrics SVG files to PNG using the same chromedp-based renderer the production pipeline uses (internal/render.Browser + Resize).
tools/sync-fixtures command
Command sync-fixtures captures the upstream lowlighter/metrics output for a given test case (e.g.
Command sync-fixtures captures the upstream lowlighter/metrics output for a given test case (e.g.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL