11#! /bin/bash
22
3+ set -euo pipefail
4+
35REPO_ROOT=$( git rev-parse --show-toplevel)
4- cd $REPO_ROOT
6+ cd " $REPO_ROOT "
57
68IMPORT_DIR=" ./imports"
79DOCS_DIR=" ./docs"
@@ -20,29 +22,40 @@ if [ ! -d "$STATIC_DIR" ]; then
2022 exit 1
2123fi
2224
25+ # Check if jq is installed
26+ if ! command -v jq > /dev/null 2>&1 ; then
27+ echo " Error: 'jq' is required but not installed. Please install jq and try again."
28+ exit 1
29+ fi
30+
31+ VERSION=$( echo " ${1:- } " | tr -cd ' [:alnum:].-' )
32+
2333# Handle tag name parameter - default to "latest" if not provided
24- if [ -z " $1 " ]; then
34+ if [ -z " $VERSION " ] || [ " $VERSION " = " latest " ]; then
2535 API_ENDPOINT=" https://api.github.com/repos/stacklok/toolhive/releases/latest"
26- echo " No tag specified, using latest release"
36+ echo " No tag specified or 'latest' specified , using latest release"
2737else
28- TAG_NAME=" $1 "
38+ TAG_NAME=" $VERSION "
2939 API_ENDPOINT=" https://api.github.com/repos/stacklok/toolhive/releases/tags/$TAG_NAME "
3040 echo " Using specified tag: $TAG_NAME "
3141fi
3242
3343# Fetch release information
34- RELEASE_JSON=$( curl -s " $API_ENDPOINT " )
35- RELEASE_TARBALL=$( echo " $RELEASE_JSON " | grep " tarball_url" | cut -d ' "' -f 4)
36- RELEASE_VERSION=$( echo " $RELEASE_JSON " | grep ' "tag_name"' | cut -d ' "' -f 4)
44+ RELEASE_JSON=$( curl -sf " $API_ENDPOINT " || {
45+ echo " Failed to fetch release information from GitHub API"
46+ exit 1
47+ })
48+ RELEASE_TARBALL=$( echo " $RELEASE_JSON " | jq -r ' .tarball_url // empty' )
49+ RELEASE_VERSION=$( echo " $RELEASE_JSON " | jq -r ' .tag_name // empty' )
3750
3851if [ -z " $RELEASE_TARBALL " ]; then
3952 echo " Failed to get release tarball URL for release: ${RELEASE_VERSION} "
4053 echo " Please check if the tag exists in the repository"
4154 exit 1
4255fi
4356
44- # Output the release version for use in CI workflows
45- if [ ! -z " $GITHUB_OUTPUT " ]; then
57+ # Output the release version for use in CI workflows (if running in GitHub Actions)
58+ if [ -n " ${ GITHUB_OUTPUT:- } " ]; then
4659 echo " version=$RELEASE_VERSION " >> " $GITHUB_OUTPUT "
4760fi
4861
@@ -54,7 +67,7 @@ echo "Fetching ToolHive release (${RELEASE_VERSION}) from: $RELEASE_TARBALL"
5467echo " Importing to: $IMPORT_DIR "
5568
5669# Download and extract the release tarball
57- curl -sL " $RELEASE_TARBALL " | tar xz --strip-components=1 -C ./imports/toolhive
70+ curl -sfL " $RELEASE_TARBALL " | tar xz --strip-components=1 -C ./imports/toolhive
5871
5972# Determine release type and process accordingly
6073if [[ " $RELEASE_VERSION " =~ ^v.* ]]; then
0 commit comments