mirror of
https://github.com/horizon-rust/horizon-mods.git
synced 2026-11-07 02:56:08 -10:00
- `stars`: each project's source repository's GitHub stars (owner/repo of a https://github.com/ source), asked once per repository every hour, as `downloads` is; a repository that can't be read is left out. The index field is horizon-rust/horizon's `projects[].stars`; the launcher shows it on a project's page with a "Star on GitHub" button. - `screenshots/` goes to GitHub Pages beside `icons/`: the index lists screenshots at <site>screenshots/<id>/<name>, and only the icons were copied, so the first gallery to be merged would show only 404s. Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Horizon agent <[email protected]>
129 lines
6.0 KiB
YAML
129 lines
6.0 KiB
YAML
# Merging publishes: each new version's file becomes a release asset
|
|
# (<id>-<version>/<file>), then index.json, the icons and the screenshots go to GitHub
|
|
# Pages (https://horizon-rust.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) and `stars` (its source repository's GitHub stars).
|
|
name: publish
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
schedule:
|
|
- cron: "23 * * * *"
|
|
workflow_dispatch:
|
|
permissions:
|
|
contents: write
|
|
pages: write
|
|
id-token: write
|
|
concurrency:
|
|
group: publish
|
|
cancel-in-progress: false
|
|
jobs:
|
|
publish:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
environment:
|
|
name: github-pages
|
|
url: ${{ steps.pages.outputs.page_url }}
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
GH_REPO: ${{ github.repository }}
|
|
HORIZON_REV: ${{ vars.HORIZON_REV || 'main' }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.cargo/bin
|
|
~/.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: |
|
|
mkdir -p site
|
|
cargo horizon-mod registry build . --files files --out site/index.json --site https://horizon-rust.github.io/horizon-mods/ --generated "$(date -u +%FT%TZ)"
|
|
- name: Publish new files as releases
|
|
run: |
|
|
cargo horizon-mod registry list . | while read -r sha id version file; do
|
|
tag="$id-$version"
|
|
gh release view "$tag" >/dev/null 2>&1 && continue
|
|
dir="$(mktemp -d)"
|
|
cp "files/$sha" "$dir/$file"
|
|
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: GitHub stars
|
|
run: |
|
|
# A project's stars are its source repository's (owner/repo of a
|
|
# https://github.com/ source, a folder of it or .git included), asked
|
|
# once per repository. One that can't be read is left out, not zero.
|
|
jq -r '.projects[].source // empty' site/index.json \
|
|
| sed -nE 's#^https://github\.com/([A-Za-z0-9-]+)/([A-Za-z0-9._-]+).*#\1/\2#p' \
|
|
| sed -E 's/\.git$//' | tr 'A-Z' 'a-z' | sort -u \
|
|
| while read -r repo; do
|
|
n="$(gh api "repos/$repo" --jq .stargazers_count 2>/dev/null)" || continue
|
|
echo "{\"key\": \"$repo\", \"value\": $n}"
|
|
done | jq -s from_entries > stars.json
|
|
jq --slurpfile stars stars.json '
|
|
.projects |= map(
|
|
(first((.source // "") | ascii_downcase
|
|
| capture("^https://github[.]com/(?<r>[a-z0-9-]+/[a-z0-9._-]+)").r
|
|
| sub("[.]git$"; "")) // "") as $r
|
|
| ($stars[0][$r] // 0) as $n
|
|
| if $n > 0 then .stars = $n else . end)' site/index.json > index.starred.json
|
|
mv index.starred.json site/index.json
|
|
jq -r '.projects[] | "\(.id) \(.stars // 0)"' site/index.json
|
|
- name: Native mods that don't apply on the newest Nightly
|
|
run: |
|
|
# native-compat.yml's daily health: the version each names gets `broken_on`, the Horizon
|
|
# commit horizon-mixins refused it on and its code, so the launcher warns before an install.
|
|
if gh release download native-health --pattern native-health.json --dir health 2>/dev/null; then
|
|
jq --slurpfile h health/native-health.json '
|
|
$h[0] as $health
|
|
| .projects |= map(. as $p | .versions |= map(
|
|
($health.broken[$p.id] // null) as $b
|
|
| if $b != null and $b.version == .version
|
|
then .broken_on = [{horizon: $health.horizon, code: $b.code}] else . end))' \
|
|
site/index.json > index.health.json
|
|
mv index.health.json site/index.json
|
|
jq -r '.projects[] | select(.versions[0].broken_on) | "\(.id) \(.versions[0].version): \(.versions[0].broken_on[0].code)"' site/index.json
|
|
fi
|
|
- name: The site
|
|
run: |
|
|
cp -R icons site/icons
|
|
# Screenshots are served beside the icons: the index lists them at
|
|
# <site>screenshots/<id>/<name>.
|
|
if [ -d screenshots ]; then cp -R screenshots site/screenshots; fi
|
|
cat > site/index.html <<'HTML'
|
|
<!doctype html><meta charset="utf-8"><title>Horizon mods</title>
|
|
<meta http-equiv="refresh" content="0; url=https://playhorizon.dev/mods">
|
|
<p><a href="https://playhorizon.dev/mods">playhorizon.dev/mods</a> · <a href="index.json">index.json</a></p>
|
|
HTML
|
|
- uses: actions/configure-pages@v5
|
|
- uses: actions/upload-pages-artifact@v3
|
|
with:
|
|
path: site
|
|
- id: pages
|
|
uses: actions/deploy-pages@v4
|