From c4f95c105e7f8abfbb1b9c19957e0b007087863a Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 11 Oct 2025 08:51:13 -0400 Subject: Add update homebrew script --- scripts/release.sh | 2 + scripts/update-homebrew.sh | 163 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100755 scripts/update-homebrew.sh (limited to 'scripts') diff --git a/scripts/release.sh b/scripts/release.sh index 4ce3e9d..8ba22a9 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -220,6 +220,8 @@ show_next_steps() { log_substep " git push origin v$version" log_substep "Or push both at once:" log_substep " git push origin $current_branch --follow-tags" + log_substep "Update Homebrew formula:" + log_substep " ./scripts/update-homebrew.sh $version" } main "$@" diff --git a/scripts/update-homebrew.sh b/scripts/update-homebrew.sh new file mode 100755 index 0000000..b3062fa --- /dev/null +++ b/scripts/update-homebrew.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash +set -eou pipefail + +source "$(dirname "${BASH_SOURCE[0]}")/lib/log.sh" +source "$(dirname "${BASH_SOURCE[0]}")/lib/path.sh" + +readonly HOMEBREW_TAP_REPO="git@git.sr.ht:~eugenetriguba/homebrew-bolt" +readonly HOMEBREW_TAP_DIR="/tmp/homebrew-bolt-update-$$" +readonly FORMULA_FILE="Formula/bolt.rb" +readonly ARCHIVE_DOWNLOAD_PATH="/tmp/bolt-archive-$$.tar.gz" + +trap cleanup EXIT + +usage() { + echo "Usage: $0 [version]" + echo "" + echo "Update the Homebrew formula with a new release version and artifact SHA." + echo "" + echo "Arguments:" + echo " version The version to update to" + echo "" + echo "Examples:" + echo " $0 0.11.0 # Bump homebrew formula to version 0.11.0" +} + +main() { + local version="${1:-}" + if [[ "$version" == "-h" || "$version" == "--help" ]]; then + usage + exit 0 + fi + if [[ -z "$version" ]]; then + log_error "No version specified" + exit 1 + fi + + log_header "Updating Homebrew Formula for v$version" + + local commit_sha + commit_sha=$(get_commit_sha_for_version "$version") + + local archive_url + archive_url="https://git.sr.ht/~eugenetriguba/bolt/archive/${commit_sha}.tar.gz" + + log_info "Version: $version" + log_info "Commit SHA: $commit_sha" + log_info "Archive URL: $archive_url" + log_newline + + local sha256 + sha256=$(calculate_archive_sha256 "$archive_url") + + log_info "SHA256: $sha256" + log_newline + + clone_homebrew_tap + update_formula "$version" "$commit_sha" "$sha256" + commit_and_push_formula "$version" + + log_success "Homebrew formula updated successfully!" +} + +get_commit_sha_for_version() { + local version="$1" + local tag="v$version" + + log_step "Getting commit SHA for $tag" + + # Ensure we have the latest tags. + git fetch --tags >/dev/null 2>&1 || true + + local sha + if ! sha=$(git rev-parse "$tag" 2>/dev/null); then + log_error "Tag $tag not found" + log_info "Make sure you've created and pushed the tag for this version" + exit 1 + fi + + echo "$sha" +} + +calculate_archive_sha256() { + local url="$1" + + log_step "Downloading and calculating SHA256 of archive" + if ! curl -fsSL "$url" -o "$ARCHIVE_DOWNLOAD_PATH"; then + log_error "Failed to download archive from $url" + exit 1 + fi + + local sha256 + if command -v sha256sum >/dev/null 2>&1; then + sha256=$(sha256sum "$ARCHIVE_DOWNLOAD_PATH" | awk '{print $1}') + else + log_error "sha256sum not found" + exit 1 + fi + + echo "$sha256" +} + +clone_homebrew_tap() { + log_step "Cloning Homebrew tap repository" + if [[ -d "$HOMEBREW_TAP_DIR" ]]; then + rm -rf "$HOMEBREW_TAP_DIR" + fi + + if ! git clone "$HOMEBREW_TAP_REPO" "$HOMEBREW_TAP_DIR" >/dev/null 2>&1; then + log_error "Failed to clone $HOMEBREW_TAP_REPO" + exit 1 + fi +} + +update_formula() { + local version="$1" + local commit_sha="$2" + local sha256="$3" + + log_step "Updating formula file" + + local formula_path="$HOMEBREW_TAP_DIR/$FORMULA_FILE" + if [[ ! -f "$formula_path" ]]; then + log_error "Formula file not found at $formula_path" + exit 1 + fi + + # Update URL with new commit SHA + sed -i.bak -E "s|url \"https://git.sr.ht/~eugenetriguba/bolt/archive/[^\"]+\"|url \"https://git.sr.ht/~eugenetriguba/bolt/archive/${commit_sha}.tar.gz\"|" "$formula_path" + + # Update version + sed -i.bak -E "s|version \"[^\"]+\"|version \"${version}\"|" "$formula_path" + + # Update sha256 + sed -i.bak -E "s|sha256 \"[^\"]+\"|sha256 \"${sha256}\"|" "$formula_path" + + rm -f "$formula_path.bak" + + log_substep "Updated $FORMULA_FILE" +} + +commit_and_push_formula() { + local version="$1" + + log_step "Committing and pushing changes" + + cd "$HOMEBREW_TAP_DIR" + git add "$FORMULA_FILE" + git commit -m "Update bolt to v$version" + + log_substep "Pushing to remote" + if ! git push origin main; then + log_error "Failed to push changes" + exit 1 + fi +} + +cleanup() { + log_step "Cleaning up" + rm -rf "$HOMEBREW_TAP_DIR" + rm -rf "$ARCHIVE_DOWNLOAD_PATH" +} + +main "$@" -- cgit v1.2.3