Skip to content

Commit 48f0d8d

Browse files
committed
update: scripts/release-homebrew.sh
1 parent e3682ac commit 48f0d8d

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

scripts/release-homebrew.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ VERSION=$1
4242
TAP_PATH=${2:-${HOMEBREW_TAP_PATH:-"$REPO_ROOT/../homebrew-tap"}}
4343
FORMULA_PATH="$TAP_PATH/Formula/rsworktree.rb"
4444

45+
infer_repo_url() {
46+
case "$1" in
47+
git@github.com:*)
48+
local path=${1#git@github.com:}
49+
path=${path%.git}
50+
echo "https://github.com/$path"
51+
;;
52+
https://github.com/*)
53+
local path=${1#https://github.com/}
54+
path=${path%.git}
55+
echo "https://github.com/$path"
56+
;;
57+
*)
58+
echo ""
59+
;;
60+
esac
61+
}
62+
4563
if [[ ! -d "$TAP_PATH" ]]; then
4664
echo "error: tap path '$TAP_PATH' not found" >&2
4765
exit 1
@@ -62,14 +80,24 @@ if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
6280
exit 1
6381
fi
6482

65-
TARBALL_URL=${HOMEBREW_TARBALL_URL:-"https://github.com/ozan/rust-git-worktree/archive/refs/tags/v${VERSION}.tar.gz"}
83+
origin_url=$(git -C "$REPO_ROOT" remote get-url origin 2>/dev/null || true)
84+
default_repo_url=$(infer_repo_url "$origin_url")
85+
if [[ -z "$default_repo_url" ]]; then
86+
default_repo_url="https://github.com/ozankasikci/rust-git-worktree"
87+
fi
88+
89+
TARBALL_URL=${HOMEBREW_TARBALL_URL:-"${default_repo_url}/archive/refs/tags/v${VERSION}.tar.gz"}
6690

6791
tmpdir=$(mktemp -d)
6892
trap 'rm -rf "$tmpdir"' EXIT
6993
tarball="$tmpdir/rsworktree-${VERSION}.tar.gz"
7094

7195
echo "Downloading release tarball to compute checksum..."
72-
curl -sSL --fail "$TARBALL_URL" -o "$tarball"
96+
if ! curl -sSL --fail "$TARBALL_URL" -o "$tarball"; then
97+
echo "error: failed to download $TARBALL_URL" >&2
98+
echo " make sure tag v$VERSION is published or set HOMEBREW_TARBALL_URL" >&2
99+
exit 1
100+
fi
73101

74102
SHA256=$($checksum_cmd "$tarball" | awk '{print $1}')
75103

0 commit comments

Comments
 (0)