mirror of
https://github.com/tiennm99/loldle.git
synced 2026-09-17 02:21:42 +00:00
refactor(ci): split scrape and sync into two workflows
- update-champions.yml: cron/manual only, scrapes + commits champions.json. Uses LOLDLE_PAT so the push retriggers sync. - sync-champions.yml: runs on push to champions.json (or manual dispatch), fans out to downstream repos via the sync_repo helper. Single responsibility per workflow; chained via the push trigger.
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
name: Sync champions to downstream repos
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths: [champions.json]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
|
||||
# Fan out 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
|
||||
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
|
||||
+4
-46
@@ -5,12 +5,6 @@ on:
|
||||
# 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
|
||||
@@ -19,65 +13,29 @@ jobs:
|
||||
update:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# LOLDLE_PAT so the subsequent push triggers sync-champions.yml;
|
||||
# default GITHUB_TOKEN would silently skip downstream triggers.
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
token: ${{ secrets.LOLDLE_PAT }}
|
||||
|
||||
- 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
|
||||
|
||||
Reference in New Issue
Block a user