mirror of
https://github.com/tiennm99/loldle.git
synced 2026-10-19 18:15:51 +00:00
Add push trigger (paths: champions.json) so direct edits to champions.json auto-sync to miti99bot and loldle without needing a workflow_dispatch. Scraper + commit steps skip on push events (the data is already committed); sync step runs when either changed=true from the scraper path OR the trigger is push. Default GITHUB_TOKEN commits don't retrigger workflows, so no self-loop.
84 lines
2.7 KiB
YAML
84 lines
2.7 KiB
YAML
name: Update champions data
|
|
|
|
on:
|
|
schedule:
|
|
# Every Thursday at 06:00 UTC (day after Riot's Wednesday patch)
|
|
- cron: "0 6 * * 4"
|
|
workflow_dispatch:
|
|
# Manual edits to champions.json fan out without needing to run the scraper.
|
|
# Scraper-driven commits use the default GITHUB_TOKEN which (by policy) does
|
|
# NOT retrigger workflows, so this path is safe from self-loops.
|
|
push:
|
|
branches: [main]
|
|
paths: [champions.json]
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
update:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v5
|
|
|
|
- name: Set up Go
|
|
if: github.event_name != 'push'
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version-file: go.mod
|
|
|
|
- name: Run scraper
|
|
if: github.event_name != 'push'
|
|
run: go run .
|
|
|
|
- name: Commit and push if changed
|
|
if: github.event_name != 'push'
|
|
id: commit
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
git add champions.json
|
|
if git diff --cached --quiet; then
|
|
echo "No changes to commit"
|
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
git commit -m "chore: update champions data to latest patch"
|
|
git push
|
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
|
|
# Fan out updated champions.json to downstream repos.
|
|
# Each row: <repo> <dest-path> [post-copy command].
|
|
# Add a new target by appending one line — no other edits required.
|
|
- name: Sync to downstream repos
|
|
if: github.event_name == 'push' || steps.commit.outputs.changed == 'true'
|
|
env:
|
|
GH_PAT: ${{ secrets.LOLDLE_PAT }}
|
|
run: |
|
|
set -euo pipefail
|
|
git config --global user.name "github-actions[bot]"
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
sync_repo() {
|
|
local repo=$1 dest=$2 post=${3:-}
|
|
local dir=${repo##*/}
|
|
git clone --depth 1 \
|
|
"https://x-access-token:${GH_PAT}@github.com/${repo}.git" "$dir"
|
|
cp champions.json "$dir/$dest"
|
|
(
|
|
cd "$dir"
|
|
if [ -n "$post" ]; then eval "$post"; fi
|
|
git add -A
|
|
if git diff --cached --quiet; then
|
|
echo "$repo already up to date"
|
|
exit 0
|
|
fi
|
|
git commit -m "chore(data): sync champions from loldle-data@${GITHUB_SHA::7}"
|
|
git push
|
|
)
|
|
}
|
|
|
|
sync_repo tiennm99/miti99bot src/modules/loldle/champions.json "node scripts/build-loldle-data.js"
|
|
sync_repo tiennm99/loldle public/champions.json
|