name: Update Latest Map Aliases

# Triggered when new map versions are pushed (chapter_*/**) or manually.
# Tiles are generated on the VPS by api_fortnite_v2 after each extraction —
# this Action only updates latest/ aliases and manifest.json.

on:
  push:
    branches: [main]
    paths:
      - "chapter_*/**"
  workflow_dispatch:

permissions:
  contents: write

jobs:
  update-latest:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "20"

      - name: Regenerate manifest
        run: node scripts/generate-manifest.js

      - name: Update latest/ aliases
        run: node scripts/update-latest.js

      - name: Regenerate manifest with latestModes
        run: node scripts/generate-manifest.js

      - name: Commit and push
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add manifest.json latest/
          git diff --cached --quiet && echo "No changes to commit" && exit 0
          git commit -m "auto: update latest/ aliases and manifest"
          git push
