Skip to content

ci(badge): sum the Gallery's per-version downloads into a README badge - #49

Merged
fadwen merged 1 commit into
mainfrom
ci/gallery-downloads-badge
Oct 19, 2026
Merged

fadwen merged 1 commit into
mainfrom
ci/gallery-downloads-badge

Conversation

@fadwen

@fadwen fadwen commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Summary

The PowerShell Gallery's per-package download total is broken and has been for months: PowerShell/PowerShellGallery#347 (version counts not updating, May 2026) and #350 (total disagrees with the version history, July 2026, "working on fixing" as of 14 October). For this module the v2 feed returns DownloadCount = 0 on all 10 versions, which is what the Gallery page and the shields.io powershellgallery/dt badge read, so that badge says "downloads: 0" in red. The per-version VersionDownloadCount values are live and sum to 82.

This adds a daily workflow that does the sum and publishes it as a shields.io endpoint badge, and a README badge that reads it.

Changes

  • .github/workflows/gallery-downloads.yml: on a daily schedule, on manual dispatch, or when called from another repository, reads every page of FindPackagesById() for the package (default: the repository name), sums VersionDownloadCount, writes downloads.json in the shields endpoint schema, and commits it to an orphan badges branch only when the number changed. GITHUB_TOKEN with contents: write is enough; no gist, no extra secret.
  • README.md: a "Gallery downloads" badge next to the version badge, through img.shields.io/endpoint pointing at the raw downloads.json on the badges branch.
  • CHANGELOG.md: Added entry under Unreleased.

Verification

  • The summing logic run locally against the live feed: 10 versions, 82 downloads, every DownloadCount 0.
  • The workflow cannot be dispatched from a branch (GitHub requires it on the default branch), so the first run and the badges branch come after merge; until then the badge renders as "invalid" or "resource not found".
  • No module code changed; the quality gates run on this pull request as usual.

Notes

  • After merge: gh workflow run gallery-downloads.yml once to create the badges branch, then daily at 06:17 UTC.

  • Another module's repository gets the same badge with this caller, replacing the package name and adding the matching README badge URL for its own owner and name:

    name: Gallery downloads badge
    on:
      schedule:
        - cron: '17 6 * * *'
      workflow_dispatch:
    permissions:
      contents: write
    jobs:
      badge:
        uses: fadwen/IntuneScriptLab/.github/workflows/gallery-downloads.yml@main
        with:
          package: OtherModuleName
  • When the Gallery fixes its total the badge keeps working; nothing to undo. If the per-version counts stall again (#347), the badge stalls with them: it is never more wrong than the Gallery's own version history.

The Gallery's per-package total is broken (PowerShell/PowerShellGallery
#347 and #350): 0 for this module, stuck or wrong for others, and it is
what the page and the shields.io powershellgallery/dt badge read. The
per-version counts still move. A daily workflow reads every version from
the v2 feed, sums VersionDownloadCount and publishes a shields.io
endpoint file on the badges branch when the number changes; the README
badge reads that file. Other module repositories can call the workflow
with their package name.

@fadwen fadwen left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes on the lines whose reason the diff does not show.

label = $env:LABEL
message = $total.ToString('N0', [cultureinfo]::InvariantCulture)
color = 'blue'
cacheSeconds = 3600

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An hour of shields.io caching, because the number changes once a day at most and the raw.githubusercontent.com URL behind it is itself cached for a few minutes; without this shields re-fetches on every README view.

run: |
set -euo pipefail
mkdir badges && cd badges
git init -q -b badges

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fresh repository in a scratch folder rather than a checkout of main: the badges branch is an orphan with no history in common with main, and this keeps the badge commits out of the module's history and the module's files out of the badge branch. The fetch below picks up the existing branch when there is one, so the first run creates it and every later run appends.

if git fetch -q origin badges 2>/dev/null; then
git reset -q --hard origin/badges
fi
if [ -f downloads.json ] && cmp -s downloads.json ../downloads.json; then

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Byte comparison of the JSON rather than of the number, so a change to the label or colour also publishes, and a run that moved nothing leaves the branch alone. Over a quiet month that is the difference between no commits and thirty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant