name: tap-new publish template

on:
  workflow_dispatch:
    inputs:
      pull_request:
        description: Pull request number
        required: true
      head_sha:
        description: Expected pull request head commit SHA (optional)

jobs:
  pr-pull:
    if: github.repository == ''
    runs-on: ubuntu-latest
    permissions:
      actions: read
      checks: read
      contents: write
      issues: read
      # tap-new-github-packages-start
      packages: write
      # tap-new-github-packages-end
      pull-requests: write
    steps:
      - name: Set up Homebrew
        uses: Homebrew/actions/setup-homebrew@df4b09108a1de9d6f995fe68f302b3f68bd6d2ef # 2026.07.20.1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Set up git
        uses: Homebrew/actions/git-user-config@df4b09108a1de9d6f995fe68f302b3f68bd6d2ef # 2026.07.20.1

      - name: Pull bottles
        env:
          HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          # tap-new-github-packages-start
          HOMEBREW_GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          HOMEBREW_GITHUB_PACKAGES_USER: ${{ github.repository_owner }}
          # tap-new-github-packages-end
          HEAD_SHA: ${{ inputs.head_sha }}
          PULL_REQUEST: ${{ inputs.pull_request }}
        run: |
          if [[ -n "$HEAD_SHA" ]]
          then
            brew pr-pull --debug --tap="$GITHUB_REPOSITORY" --head-sha="$HEAD_SHA" "$PULL_REQUEST"
          else
            brew pr-pull --debug --tap="$GITHUB_REPOSITORY" "$PULL_REQUEST"
          fi

      - name: Push commits
        uses: Homebrew/actions/git-try-push@df4b09108a1de9d6f995fe68f302b3f68bd6d2ef # 2026.07.20.1
        with:
          branch: TAP_NEW_BRANCH
