Skip to content

Update npm downloads counter #39

Update npm downloads counter

Update npm downloads counter #39

name: Update npm downloads counter
on:
schedule:
- cron: "17 1 * * *"
workflow_dispatch:
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
steps:
# 刻意留在 v4:与 repo-guard.yml 的 checkout 保持同版本,按 #440 item 2
# 一起动。本 job 跑在托管 runner,不存在那边的 node24 阻塞;`git push` 依赖的
# `persist-credentials` 默认值在 v4.4.0 与 v6.1.0 上也已核对为一致(都是 true)。
# 也就是说这一处本身可以升,只是没有理由单独升。
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- name: Fetch cumulative downloads and patch README
run: |
END=$(date -u -d yesterday +%F)
N=$(curl -sf "https://api.npmjs.org/downloads/point/2026-01-14:${END}/frontagent" | jq -r '.downloads')
if [ -z "$N" ] || [ "$N" = "null" ]; then
echo "npm API unavailable, skip"; exit 0
fi
perl -0pi -e "s/<!-- npm-downloads:start -->.*?<!-- npm-downloads:end -->/<!-- npm-downloads:start -->\n**Cumulative npm downloads since 2026-01-14: ${N}** (updated ${END}, via GitHub Action)\n<!-- npm-downloads:end -->/s" README.md
- name: Commit if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add README.md
git diff --cached --quiet || (git commit -m "chore(readme): refresh npm downloads counter" && git push)