Update metrics #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update metrics | |
| # Refreshes METRICS.md from PyPI + GitHub APIs. | |
| # | |
| # Signals: | |
| # - PyPI downloads (24h / 7d / 30d) via pypistats.org JSON API. | |
| # - GitHub repo metadata (stars, forks, watchers, open issues/PRs). | |
| # - GitHub traffic (clones, views, referrers, paths) — last 14 days. | |
| # | |
| # Plugin install proxy: `/plugin marketplace add raintree-technology/docpull` | |
| # is a git clone under the hood, so daily clone counts approximate | |
| # plugin installs. | |
| # | |
| # Why a workflow instead of an external dashboard: | |
| # - Single source of truth committed in-repo (no external service to babysit). | |
| # - History via `git log METRICS.md` if you ever want trend analysis. | |
| # - Free; uses pre-installed gh CLI + stdlib Python on ubuntu-latest. | |
| # | |
| # Token: traffic endpoints (clones, views, referrers, paths) require | |
| # `Administration: read` permission, which the default GITHUB_TOKEN does | |
| # NOT grant. Public metrics (stars, downloads, issues/PRs) work without | |
| # it. To populate traffic data, create a fine-grained PAT scoped to this | |
| # repo with Administration: read + Metadata: read, save as repo secret | |
| # `METRICS_TOKEN`. The workflow falls back to GITHUB_TOKEN if absent. | |
| on: | |
| schedule: | |
| # 09:12 UTC daily (off-hour to dodge top-of-hour Actions spikes). | |
| - cron: "12 9 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| # Avoid overlapping runs piling up if a previous run is still committing. | |
| concurrency: | |
| group: metrics-update | |
| cancel-in-progress: false | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Refresh METRICS.md | |
| env: | |
| # Prefer the PAT (has Administration: read for traffic endpoints). | |
| # Fall back to the default token (still works for stars / issues / | |
| # downloads — only the traffic section will be empty). | |
| GH_TOKEN: ${{ secrets.METRICS_TOKEN || secrets.GITHUB_TOKEN }} | |
| run: python .github/scripts/update_metrics.py | |
| - name: Commit if METRICS.md changed | |
| run: | | |
| # `git diff` only sees tracked files, so for the first-ever run | |
| # (METRICS.md untracked) it would falsely report no changes. Stage | |
| # first, then check the staged diff against HEAD. | |
| git add METRICS.md | |
| if git diff --cached --quiet METRICS.md; then | |
| echo "No metric changes since last run." | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git commit -m "chore(metrics): refresh $(date -u +%Y-%m-%d)" | |
| git push |