Skip to content

Commit f4e4d00

Browse files
authored
fix install.sh (#562)
Fixes #561 Uses `cargo` to get the latest version instead of GH releases' latest because today GH releases do not have only `router` but also `node-addon` etc.
1 parent bb609c4 commit f4e4d00

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

install.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set -e
1212
GH_OWNER="graphql-hive"
1313
GH_REPO="router"
1414
BINARY_NAME="hive_router"
15+
CARGO_PKG_NAME="hive-router"
1516

1617
info() {
1718
echo "\033[34m[INFO]\033[0m $1"
@@ -76,23 +77,23 @@ detect_arch() {
7677

7778
get_version() {
7879
if [ -n "$1" ]; then
79-
VERSION="hive-router-$1"
80+
VERSION="$1"
8081
info "Installing specified version: $VERSION"
8182
else
82-
info "No version specified. Fetching the latest release from GitHub..."
83-
LATEST_RELEASE_URL="https://api.github.com/repos/${GH_OWNER}/${GH_REPO}/releases/latest"
84-
VERSION=$(curl -sL "$LATEST_RELEASE_URL" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
83+
info "No version specified. Fetching the latest version from crates.io..."
84+
CRATES_API_URL="https://crates.io/api/v1/crates/${CARGO_PKG_NAME}"
85+
VERSION=$(curl -sL "$CRATES_API_URL" | grep -o '"max_version":"[^"]*"' | head -1 | sed 's/"max_version":"\([^"]*\)"/\1/')
8586

8687
if [ -z "$VERSION" ]; then
87-
error "Could not determine the latest version. Please check the repository details."
88+
error "Could not determine the latest version from crates.io. Please check the crate name."
8889
fi
89-
info "Latest version found: $VERSION"
90+
info "Latest version found on crates.io: $VERSION"
9091
fi
9192
}
9293

9394
download_and_install() {
9495
ASSET_NAME="${BINARY_NAME}_${OS}_${ARCH}"
95-
DOWNLOAD_URL="https://github.com/${GH_OWNER}/${GH_REPO}/releases/download/${VERSION}/${ASSET_NAME}"
96+
DOWNLOAD_URL="https://github.com/${GH_OWNER}/${GH_REPO}/releases/download/router%2Fv${VERSION}/${ASSET_NAME}"
9697

9798
info "Downloading binary from: ${DOWNLOAD_URL}"
9899

0 commit comments

Comments
 (0)