Skip to content

Update download counts #41

Update download counts

Update download counts #41

name: Update download counts
on:
schedule:
- cron: "17 */6 * * *"
workflow_dispatch:
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Sum release downloads per plugin and update repo.json
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
counts='{}'
for repo in $(jq -r '.[].RepoUrl' repo.json | sed 's#https://github.com/##'); do
internal=$(jq -r --arg url "https://github.com/$repo" '.[] | select(.RepoUrl == $url) | .InternalName' repo.json)
total=$(gh api "repos/$repo/releases?per_page=100" --jq '[.[].assets[].download_count] | add // 0')
counts=$(jq --arg k "$internal" --argjson v "$total" '. + {($k): $v}' <<< "$counts")
done
# Monotonic: the counter never decreases, even if a release disappears or the
# API hiccups. The existing value in repo.json acts as the floor.
jq --argjson c "$counts" 'map(.DownloadCount = ([($c[.InternalName] // 0), (.DownloadCount // 0)] | max))' repo.json > repo.json.new
mv repo.json.new repo.json
- name: Commit if changed
run: |
if ! git diff --quiet; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add repo.json
git commit -m "Update download counts"
git push
fi