aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-10-12 10:30:30 -0400
committerEugene Triguba <hello@eugenetriguba.com>2025-10-12 10:30:30 -0400
commit71fc703bfa18c4de5c64be89818f803d3fac4bf3 (patch)
tree2f5a9e039b66bdc3cf0dc8e56815f3821ba7eb63 /scripts
parentRelease version 0.2.0 (diff)
downloadcli-71fc703bfa18c4de5c64be89818f803d3fac4bf3.zip
Add ability to bump homebrew formula on release
Diffstat (limited to '')
-rwxr-xr-xscripts/release.sh108
1 files changed, 108 insertions, 0 deletions
diff --git a/scripts/release.sh b/scripts/release.sh
index 2c45e5c..2d7ef1a 100755
--- a/scripts/release.sh
+++ b/scripts/release.sh
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
+readonly HOMEBREW_REPO_URL="git@git.sr.ht:~eugenetriguba/homebrew-justify"
+
main() {
if [ $# -ne 1 ]; then
usage
@@ -30,6 +32,9 @@ main() {
echo ""
echo "Release $version created successfully!"
+ echo ""
+
+ bump_homebrew_formula "$version"
}
usage() {
@@ -257,4 +262,107 @@ push_changes() {
echo "Successfully pushed version $version"
}
+bump_homebrew_formula() {
+ local version="$1"
+
+ echo "Updating Homebrew formula..."
+
+ local temp_dir
+ temp_dir=$(mktemp -d)
+
+ if ! git clone "$HOMEBREW_REPO_URL" "$temp_dir" 2>/dev/null; then
+ echo "Error: Failed to clone Homebrew repository" >&2
+ exit 1
+ fi
+
+ local formula_file="$temp_dir/Formula/justify.rb"
+ if [ ! -f "$formula_file" ]; then
+ echo "Error: Formula file not found at $formula_file" >&2
+ exit 1
+ fi
+
+ local tarball_url="https://git.sr.ht/~eugenetriguba/justify/archive/v${version}.tar.gz"
+ local sha256
+ sha256=$(calculate_tarball_sha256 "$tarball_url")
+
+ update_homebrew_formula "$formula_file" "$version" "$tarball_url" "$sha256"
+
+ echo " Version: $version"
+ echo " URL: $tarball_url"
+ echo " SHA256: $sha256"
+ echo ""
+
+ commit_and_push_formula "$temp_dir" "$version"
+}
+
+calculate_tarball_sha256() {
+ local url="$1"
+ local temp_file
+ temp_file=$(mktemp)
+
+ if ! curl -sSL "$url" -o "$temp_file" 2>/dev/null; then
+ echo "Error: Failed to download tarball from $url" >&2
+ echo "Make sure the tag exists in the repository." >&2
+ rm -f "$temp_file"
+ exit 1
+ fi
+
+ local sha256
+ sha256=$(sha256sum "$temp_file" | awk '{print $1}')
+
+ rm -f "$temp_file"
+ echo "$sha256"
+}
+
+update_homebrew_formula() {
+ local formula_file="$1"
+ local version="$2"
+ local url="$3"
+ local sha256="$4"
+
+ local temp_file
+ temp_file=$(mktemp)
+
+ sed \
+ -e "s|url \".*\"|url \"$url\"|" \
+ -e "s|sha256 \".*\"|sha256 \"$sha256\"|" \
+ -e "s|version \".*\"|version \"$version\"|" \
+ "$formula_file" >"$temp_file"
+
+ mv "$temp_file" "$formula_file"
+}
+
+commit_and_push_formula() {
+ local repo_path="$1"
+ local version="$2"
+
+ cd "$repo_path"
+
+ read -p "Push Homebrew formula update? (y/N): " -n 1 -r
+ echo ""
+
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+ echo "Homebrew formula updated locally but not pushed."
+ echo "Repository location: $repo_path"
+ return 0
+ fi
+
+ if ! git add .; then
+ echo "Error: Failed to stage files" >&2
+ exit 1
+ fi
+
+ if ! git commit -m "Bump justify to $version"; then
+ echo "Error: Failed to create commit" >&2
+ exit 1
+ fi
+
+ if ! git push; then
+ echo "Error: Failed to push changes" >&2
+ exit 1
+ fi
+
+ echo "Successfully updated Homebrew formula to version $version"
+}
+
main "$@"