# brew tap-new uses this file to generate a bottle publish workflow for the new tap
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)

permissions: {}

defaults:
  run:
    shell: bash -xeuo pipefail {0}

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@fd832223f9f99ebf0244dd20658680e5d4aca049 # 2026.08.03.2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Set up git
        id: git_setup
        uses: Homebrew/actions/git-user-config@fd832223f9f99ebf0244dd20658680e5d4aca049 # 2026.08.03.2

      - name: Pull bottles
        env:
          HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          HOMEBREW_GIT_COMMITTER_NAME: ${{ steps.git_setup.outputs.name }}
          HOMEBREW_GIT_COMMITTER_EMAIL: ${{ steps.git_setup.outputs.email }}
          # 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@fd832223f9f99ebf0244dd20658680e5d4aca049 # 2026.08.03.2
        with:
          branch: TAP_NEW_BRANCH
