name: "AppleMETA"

on:
  schedule:
    - cron: "00 01,13 * * *"

permissions:
  contents: write

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - name: Set up Go
        uses: actions/setup-go@v7
        with:
          go-version: "1.26"
          cache: false
      - name: Cache go.mod
        uses: actions/cache@v5
        with:
          path: |
            ~/.cache/go-build
            ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-
      - name: Run build
        run: |
          make build
      - name: Run download git --json --webkit
        run: ./ipsw download git --json --api ${{ secrets.GITHUB_TOKEN }} --output /tmp
      - name: Switch branch
        run: |
          git stash
          git checkout apple_meta
      - name: Commit JSON
        run: |
          go install github.com/josephburnett/jd@v1.5.1
          jd -set /tmp/tag_links.json github/tag_links.json || true
          mv /tmp/tag_links.json github/tag_links.json
          git --no-pager diff github/tag_links.json
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git commit -am "AppleMETA refresh"
          git push
