diff --git a/data/.github/workflows/sync-champions.yml b/data/.github/workflows/sync-champions.yml new file mode 100644 index 0000000..ca8ea19 --- /dev/null +++ b/data/.github/workflows/sync-champions.yml @@ -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: [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 diff --git a/data/.github/workflows/update-champions.yml b/data/.github/workflows/update-champions.yml index 56eac22..8131ef0 100644 --- a/data/.github/workflows/update-champions.yml +++ b/data/.github/workflows/update-champions.yml @@ -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: [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