diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7726f36..2e9bf49 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -313,14 +313,33 @@ jobs: - name: Push to Homebrew tap env: - GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} + GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} run: | - git clone https://x-access-token:${GITHUB_TOKEN}@github.com/harmony-labs/homebrew-tap.git tap + VERSION="${{ steps.version.outputs.version }}" + BRANCH="update-meta-cli-${VERSION}" + + gh repo clone harmony-labs/homebrew-tap tap mkdir -p tap/Formula cp meta-cli.rb tap/Formula/ cd tap git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add Formula/meta-cli.rb - git commit -m "Update meta-cli to v${{ steps.version.outputs.version }}" - git push + if ! git diff --cached --quiet; then + git checkout -b "$BRANCH" + git commit -m "Update meta-cli to v${VERSION}" + # Force push in case branch exists from a previous failed run + git push -f -u origin "$BRANCH" + # Create PR only if one doesn't already exist + if ! gh pr view "$BRANCH" --repo harmony-labs/homebrew-tap &>/dev/null; then + gh pr create \ + --title "Update meta-cli to v${VERSION}" \ + --body "Automated formula update from meta release v${VERSION}." \ + --repo harmony-labs/homebrew-tap + fi + gh pr merge "$BRANCH" \ + --auto --squash \ + --repo harmony-labs/homebrew-tap || echo "Auto-merge setup failed (may require approvals)" + else + echo "Formula unchanged, skipping commit" + fi