From 9ed702c7dcb4d82d8bbf342a487ed526cfd7ac73 Mon Sep 17 00:00:00 2001 From: A Ibrahim Date: Fri, 3 Apr 2026 14:43:48 -0400 Subject: [PATCH 1/2] fix: make homebrew tap update script retry-safe Handle re-runs when the branch was pushed but PR creation failed (e.g. due to missing label). Checks for existing open PRs and remote branches before attempting to push or create a new PR. Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/update-homebrew.sh | 45 +++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/scripts/update-homebrew.sh b/scripts/update-homebrew.sh index a3abd01..d26d51a 100755 --- a/scripts/update-homebrew.sh +++ b/scripts/update-homebrew.sh @@ -19,6 +19,7 @@ TAP_REPO="${HOMEBREW_TAP_REPO:-tigrisdata/homebrew-tap}" CLI_REPO="tigrisdata/cli" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" TEMPLATE="${SCRIPT_DIR}/../homebrew/Formula/tigris.rb" +BRANCH="update-tigris-${VERSION}" if [ ! -f "$TEMPLATE" ]; then echo "ERROR: Formula template not found at $TEMPLATE" @@ -77,7 +78,14 @@ if [ -n "${HOMEBREW_TAP_TOKEN:-}" ]; then CLONE_URL="https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/${TAP_REPO}.git" fi -BRANCH="update-tigris-${VERSION}" +export GH_TOKEN="${HOMEBREW_TAP_TOKEN:-}" + +# Check if a PR already exists for this version +EXISTING_PR="$(gh pr list --repo "$TAP_REPO" --head "$BRANCH" --state open --json number --jq '.[0].number // empty' 2>/dev/null || true)" +if [ -n "$EXISTING_PR" ]; then + echo "PR #${EXISTING_PR} already exists for ${BRANCH}." + exit 0 +fi echo "" echo "Cloning ${TAP_REPO}..." @@ -85,30 +93,37 @@ git clone --depth 1 "$CLONE_URL" "$TMP_DIR/tap" cd "$TMP_DIR/tap" -mkdir -p Formula -echo "$FORMULA" > Formula/tigris.rb +# Check if the branch already exists on the remote (e.g. from a previous failed run) +REMOTE_BRANCH_EXISTS="$(git ls-remote --heads origin "$BRANCH" | head -1)" -git add Formula/tigris.rb +if [ -n "$REMOTE_BRANCH_EXISTS" ]; then + # Branch was pushed but PR creation failed — just create the PR + echo "Branch ${BRANCH} already exists on remote. Creating PR..." +else + mkdir -p Formula + echo "$FORMULA" > Formula/tigris.rb -if git diff --cached --quiet; then - echo "Formula is already up to date." - exit 0 -fi + git add Formula/tigris.rb -git checkout -b "$BRANCH" -git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" \ - commit -m "tigris ${VERSION}" -git push origin "$BRANCH" + if git diff --cached --quiet; then + echo "Formula is already up to date." + exit 0 + fi + + git checkout -b "$BRANCH" + git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" \ + commit -m "tigris ${VERSION}" + git push origin "$BRANCH" +fi echo "" echo "Creating pull request..." -GH_TOKEN="${HOMEBREW_TAP_TOKEN:-}" gh pr create \ +gh pr create \ --repo "$TAP_REPO" \ --base main \ --head "$BRANCH" \ --title "tigris ${VERSION}" \ - --body "Update Tigris CLI formula to [v${VERSION}](https://github.com/${CLI_REPO}/releases/tag/v${VERSION})." \ - --label "automated" + --body "Update Tigris CLI formula to [v${VERSION}](https://github.com/${CLI_REPO}/releases/tag/v${VERSION})." echo "" echo "Pull request created for v${VERSION}" From 0ecef5ca58bb7ab509b78ab1de32176d0af01947 Mon Sep 17 00:00:00 2001 From: A Ibrahim Date: Mon, 6 Apr 2026 16:58:49 +0200 Subject: [PATCH 2/2] fix: move retry checks before expensive downloads in homebrew script Existing-PR and remote-branch checks now run before downloading archives and computing SHA256 hashes, avoiding unnecessary work on retries. Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/update-homebrew.sh | 73 +++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/scripts/update-homebrew.sh b/scripts/update-homebrew.sh index d26d51a..affbc7d 100755 --- a/scripts/update-homebrew.sh +++ b/scripts/update-homebrew.sh @@ -26,6 +26,35 @@ if [ ! -f "$TEMPLATE" ]; then exit 1 fi +CLONE_URL="https://github.com/${TAP_REPO}.git" +if [ -n "${HOMEBREW_TAP_TOKEN:-}" ]; then + CLONE_URL="https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/${TAP_REPO}.git" +fi + +export GH_TOKEN="${HOMEBREW_TAP_TOKEN:-}" + +# Early exit: if a PR already exists for this version, nothing to do +EXISTING_PR="$(gh pr list --repo "$TAP_REPO" --head "$BRANCH" --state open --json number --jq '.[0].number // empty' 2>/dev/null || true)" +if [ -n "$EXISTING_PR" ]; then + echo "PR #${EXISTING_PR} already exists for ${BRANCH}." + exit 0 +fi + +# Early exit: if the branch exists but no PR, skip downloads and just create the PR +REMOTE_BRANCH_EXISTS="$(git ls-remote "https://github.com/${TAP_REPO}.git" "refs/heads/${BRANCH}" | head -1)" +if [ -n "$REMOTE_BRANCH_EXISTS" ]; then + echo "Branch ${BRANCH} already exists on remote. Creating PR..." + gh pr create \ + --repo "$TAP_REPO" \ + --base main \ + --head "$BRANCH" \ + --title "tigris ${VERSION}" \ + --body "Update Tigris CLI formula to [v${VERSION}](https://github.com/${CLI_REPO}/releases/tag/v${VERSION})." + echo "" + echo "Pull request created for v${VERSION}" + exit 0 +fi + # Download each archive and compute SHA256 compute_sha256() { local asset_name="$1" @@ -73,49 +102,27 @@ echo "---" TMP_DIR="$(mktemp -d)" trap 'rm -rf "$TMP_DIR"' EXIT -CLONE_URL="https://github.com/${TAP_REPO}.git" -if [ -n "${HOMEBREW_TAP_TOKEN:-}" ]; then - CLONE_URL="https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/${TAP_REPO}.git" -fi - -export GH_TOKEN="${HOMEBREW_TAP_TOKEN:-}" - -# Check if a PR already exists for this version -EXISTING_PR="$(gh pr list --repo "$TAP_REPO" --head "$BRANCH" --state open --json number --jq '.[0].number // empty' 2>/dev/null || true)" -if [ -n "$EXISTING_PR" ]; then - echo "PR #${EXISTING_PR} already exists for ${BRANCH}." - exit 0 -fi - echo "" echo "Cloning ${TAP_REPO}..." git clone --depth 1 "$CLONE_URL" "$TMP_DIR/tap" cd "$TMP_DIR/tap" -# Check if the branch already exists on the remote (e.g. from a previous failed run) -REMOTE_BRANCH_EXISTS="$(git ls-remote --heads origin "$BRANCH" | head -1)" - -if [ -n "$REMOTE_BRANCH_EXISTS" ]; then - # Branch was pushed but PR creation failed — just create the PR - echo "Branch ${BRANCH} already exists on remote. Creating PR..." -else - mkdir -p Formula - echo "$FORMULA" > Formula/tigris.rb +mkdir -p Formula +echo "$FORMULA" > Formula/tigris.rb - git add Formula/tigris.rb +git add Formula/tigris.rb - if git diff --cached --quiet; then - echo "Formula is already up to date." - exit 0 - fi - - git checkout -b "$BRANCH" - git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" \ - commit -m "tigris ${VERSION}" - git push origin "$BRANCH" +if git diff --cached --quiet; then + echo "Formula is already up to date." + exit 0 fi +git checkout -b "$BRANCH" +git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" \ + commit -m "tigris ${VERSION}" +git push origin "$BRANCH" + echo "" echo "Creating pull request..." gh pr create \