publish: each project's download count, refreshed every hour

publish.yml runs every hour as well as on merges. It sums GitHub's
download_count of each version's release asset into the project's
`downloads` field of index.json, which the launcher and playhorizon.dev/mods
show.

publish and check keep `files/` in the Actions cache, so CI doesn't fetch
every release asset again on each run (each fetch counts as a download).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Ludovic MarieandClaude Opus 5.5 committed 2026-10-26 14:21:16 +01:00
1 parent 98f8ab5da3
commit 2181eec3ce
2 files changed
+31

No files matched your search

+7
View File
@@ -60,6 +60,13 @@ jobs:
| tee -a "$GITHUB_STEP_SUMMARY" || status=1
echo '```' >> "$GITHUB_STEP_SUMMARY"
exit $status
# main's files, kept by publish: each download from a release counts as a
# player's.
- uses: actions/cache/restore@v4
with:
path: files
key: files-${{ hashFiles('head/mods/*.toml') }}
restore-keys: files-
- name: Download its files
run: base/scripts/fetch.sh head
- name: Check each new file
+24
View File
@@ -2,10 +2,14 @@
# (<id>-<version>/<file>), then index.json and the icons go to GitHub Pages
# (https://ludovic111.github.io/horizon-mods/index.json), which the launcher and
# playhorizon.dev/mods read. Nothing is published if any entry fails its checks.
# Every hour it runs again to refresh each project's `downloads`: GitHub's
# download counts of its release assets.
name: publish
on:
push:
branches: [main]
schedule:
- cron: "23 * * * *"
workflow_dispatch:
permissions:
contents: write
@@ -34,6 +38,13 @@ jobs:
~/.cargo/horizon-rev
key: cargo-horizon-mod-${{ env.HORIZON_REV }}
- run: scripts/install-tool.sh
# Files kept from the last run: GitHub counts every download of a release
# asset, so fetching them all again each hour would count as players.
- uses: actions/cache@v4
with:
path: files
key: files-${{ hashFiles('mods/*.toml') }}
restore-keys: files-
- run: scripts/fetch.sh .
- name: Build the index
run: |
@@ -49,6 +60,19 @@ jobs:
gh release create "$tag" "$dir/$file" --title "$id $version" --latest=false \
--notes "Reviewed in the registry: mods/$id.toml. SHA-256 $sha."
done
- name: Download counts
run: |
# Each version's file is the asset at its URL: a project's downloads
# are its files' counts, every version together.
gh api --paginate "repos/$GH_REPO/releases?per_page=100" \
--jq '.[].assets[] | {key: .browser_download_url, value: .download_count}' \
| jq -s from_entries > counts.json
jq --slurpfile counts counts.json '
.projects |= map(
([.versions[].file.url | $counts[0][.] // 0] | add) as $n
| if $n > 0 then .downloads = $n else . end)' site/index.json > index.counted.json
mv index.counted.json site/index.json
jq -r '.projects[] | "\(.id) \(.downloads // 0)"' site/index.json
- name: The site
run: |
cp -R icons site/icons