File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,7 +39,10 @@ setup: |
3939 aarch64*|arm64*) ARCH_NAME="arm64" ;;
4040 *) echo "Unsupported architecture: ${ARCH}" >&2; exit 1 ;;
4141 esac
42- VERSION=$(curl -fsSL "https://api.github.com/repos/google/sam/releases?per_page=1" | grep '"tag_name":' | head -n 1 | sed -E 's/.*"([^"]+)".*/\1/')
42+ VERSION=$(curl -fsSL -o /dev/null -w "%{url_effective}" "https://github.com/google/sam/releases/latest" | sed 's|.*/||')
43+ if [[ -z "${VERSION}" || "${VERSION}" == "releases" ]]; then
44+ VERSION=$(curl -fsSL "https://api.github.com/repos/google/sam/releases?per_page=1" | grep '"tag_name":' | head -n 1 | sed -E 's/.*"([^"]+)".*/\1/')
45+ fi
4346 TMP_DIR=$(mktemp -d)
4447 curl -fsSL -o "${TMP_DIR}/sam.tar.gz" "https://github.com/google/sam/releases/download/${VERSION}/sam_Linux_${ARCH_NAME}.tar.gz"
4548 tar -xzf "${TMP_DIR}/sam.tar.gz" -C "${TMP_DIR}"
Original file line number Diff line number Diff line change @@ -22,17 +22,14 @@ case "${ARCH}" in
2222 * ) echo " Unsupported architecture: ${ARCH} " ; exit 1;;
2323esac
2424
25- # Get latest release version
25+ # Get latest release version via GitHub redirect (avoids api.github.com rate limits)
2626echo " Fetching latest release information..."
27- LATEST_RELEASE_URL=" https://api.github.com/repos/${REPO} /releases/latest"
28- # `|| true`: with pipefail, a grep that matches nothing would kill the script
29- # here instead of reaching the fallback/error below.
30- VERSION=$( curl -s " $LATEST_RELEASE_URL " | grep ' "tag_name":' | head -n 1 | sed -E ' s/.*"([^"]+)".*/\1/' || true)
31- if [ -z " $VERSION " ]; then
32- VERSION=$( curl -s " https://api.github.com/repos/${REPO} /releases?per_page=1" | grep ' "tag_name":' | head -n 1 | sed -E ' s/.*"([^"]+)".*/\1/' || true)
27+ VERSION=$( curl -fsSL -o /dev/null -w " %{url_effective}" " https://github.com/${REPO} /releases/latest" | sed ' s|.*/||' || true)
28+ if [ -z " $VERSION " ] || [ " $VERSION " = " releases" ]; then
29+ VERSION=$( curl -fsSL " https://api.github.com/repos/${REPO} /releases?per_page=1" | grep ' "tag_name":' | head -n 1 | sed -E ' s/.*"([^"]+)".*/\1/' || true)
3330fi
3431
35- if [ -z " $VERSION " ]; then
32+ if [ -z " $VERSION " ] || [ " $VERSION " = " releases " ] ; then
3633 echo " Error: Could not find the latest release."
3734 exit 1
3835fi
You can’t perform that action at this time.
0 commit comments