Skip to content

Commit d039320

Browse files
Fix/install script rate limit handling (#354)
* fix: handle GitHub API rate limits in install scripts The install scripts used `curl -s` which silently swallows HTTP errors. When the GitHub API returns a 403 (rate limit) or other failure, the scripts would either print a misleading "Could not find release" error or, in the case of install-latest-linux.sh, proceed with an empty URL. Switch to `curl -sf` so HTTP errors produce a non-zero exit code, and add explicit error handling with a clear message about rate limiting. Also add a missing empty-URL guard to install-latest-linux.sh. * review feedback + enhancements from PR 343 * review feedback --------- Co-authored-by: Bryce Adelstein Lelbach aka wash <brycelelbach@gmail.com>
1 parent 9e0e34b commit d039320

3 files changed

Lines changed: 27 additions & 30 deletions

File tree

bin/install-latest-linux.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

bin/install-latest.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ case "${ARCH}" in
99
aarch64) ARCH="arm64" ;;
1010
esac
1111

12-
# Get the appropriate download URL for this platform
13-
DOWNLOAD_URL="$(curl -s https://api.github.com/repos/brevdev/brev-cli/releases/latest | grep "browser_download_url.*${OS}.*${ARCH}" | cut -d '"' -f 4)"
12+
# Fetch release metadata from GitHub API
13+
API_RESPONSE="$(curl -sf ${GITHUB_TOKEN:+-H "Authorization: token ${GITHUB_TOKEN}"} https://api.github.com/repos/brevdev/brev-cli/releases/latest)" || {
14+
echo "Error: Failed to fetch release info from GitHub API." >&2
15+
echo "This is often caused by rate limiting when many requests come from the same IP." >&2
16+
echo "If you are using a VPN, try turning it off and running this script again." >&2
17+
echo "You can also set GITHUB_TOKEN to avoid rate limits." >&2
18+
echo "For more details, see: https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting" >&2
19+
exit 1
20+
}
1421

15-
# Verify we found a suitable release
22+
# Extract the download URL for this platform
23+
DOWNLOAD_URL="$(echo "${API_RESPONSE}" | grep "browser_download_url.*${OS}.*${ARCH}" | cut -d '"' -f 4 || true)"
1624
if [ -z "${DOWNLOAD_URL}" ]; then
1725
echo "Error: Could not find release for ${OS} ${ARCH}" >&2
26+
echo "GitHub API response (truncated): ${API_RESPONSE:0:200}" >&2
1827
exit 1
1928
fi
2029

scripts/install-agent-skill.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,21 @@ done
116116
rm -rf "$TMPDIR"
117117

118118
# Resolve commit SHA and write .version file
119-
COMMIT_SHA=$(curl -fsSL "https://api.github.com/repos/$REPO/commits/$BRANCH" 2>/dev/null | grep '"sha"' | head -1 | sed 's/.*"sha": *"\([^"]*\)".*/\1/')
120-
if [[ -n "$COMMIT_SHA" ]]; then
121-
for dir in "${INSTALL_DIRS[@]}"; do
122-
printf 'branch=%s\ncommit=%s\n' "$BRANCH" "$COMMIT_SHA" > "$dir/.version"
123-
done
124-
echo -e " ${GREEN}${NC} .version (${COMMIT_SHA:0:12})"
119+
VERSION_RESPONSE=$(curl -fsSL "https://api.github.com/repos/$REPO/commits/$BRANCH" 2>&1) || true
120+
if echo "$VERSION_RESPONSE" | grep -q "API rate limit exceeded"; then
121+
echo -e " ${YELLOW}${NC} .version (skipped — GitHub API rate limit exceeded)"
122+
echo -e " ${YELLOW}If you are using a VPN, try turning it off and running this script again.${NC}"
123+
echo -e " ${YELLOW}See: https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting${NC}"
124+
else
125+
COMMIT_SHA=$(echo "$VERSION_RESPONSE" | grep '"sha"' | head -1 | sed 's/.*"sha": *"\([^"]*\)".*/\1/' || true)
126+
if [[ -n "$COMMIT_SHA" ]]; then
127+
for dir in "${INSTALL_DIRS[@]}"; do
128+
printf 'branch=%s\ncommit=%s\n' "$BRANCH" "$COMMIT_SHA" > "$dir/.version"
129+
done
130+
echo -e " ${GREEN}${NC} .version (${COMMIT_SHA:0:12})"
131+
else
132+
echo -e " ${YELLOW}${NC} .version (could not resolve commit SHA)"
133+
fi
125134
fi
126135

127136
echo ""

0 commit comments

Comments
 (0)