From 3380e38de955c2b2d6be332ec6cc2746310add94 Mon Sep 17 00:00:00 2001 From: Rui Liang Date: Wed, 15 Jul 2026 15:24:54 +0800 Subject: [PATCH] fix: update Homebrew tap through contents API --- .github/workflows/update-homebrew-tap.yml | 29 +++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/update-homebrew-tap.yml b/.github/workflows/update-homebrew-tap.yml index 77fcc46..c305ea3 100644 --- a/.github/workflows/update-homebrew-tap.yml +++ b/.github/workflows/update-homebrew-tap.yml @@ -4,18 +4,24 @@ on: workflow_run: workflows: [Build Binaries] types: [completed] + workflow_dispatch: + inputs: + release_tag: + description: Release tag to publish to Homebrew + required: true + type: string permissions: {} jobs: update-tap: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v') }} + if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v')) }} steps: - name: Update Homebrew formula env: GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} - RELEASE_TAG: ${{ github.event.workflow_run.head_branch }} + RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.release_tag || github.event.workflow_run.head_branch }} run: | set -euo pipefail @@ -31,11 +37,8 @@ jobs: SHAS["${asset}"]="${sha}" done - # Clone tap repo - git clone "https://x-access-token:${GH_TOKEN}@github.com/${TAP_REPO}.git" tap - cd tap - # Generate formula + mkdir -p "$(dirname "${FORMULA_PATH}")" cat > "${FORMULA_PATH}" << RUBY class Openabcode < Formula desc "AI coding agent with task routing and hosted gateway" @@ -77,9 +80,11 @@ jobs: # Remove leading whitespace from heredoc sed -i 's/^ //' "${FORMULA_PATH}" - # Commit and push - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add "${FORMULA_PATH}" - git commit -m "openabcode ${VERSION}" - git push + # Update the tap with the fine-grained PAT as a Bearer token. + formula_sha=$(gh api "repos/${TAP_REPO}/contents/${FORMULA_PATH}" --jq '.sha') + formula_content=$(base64 -w 0 "${FORMULA_PATH}") + gh api --method PUT "repos/${TAP_REPO}/contents/${FORMULA_PATH}" \ + -f message="openabcode ${VERSION}" \ + -f content="${formula_content}" \ + -f sha="${formula_sha}" \ + -f branch=main