Skip to content

Commit

Permalink
Improve install script rate limit handling
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Jun 24, 2018
1 parent 1bebb15 commit ca82a79
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 11 additions & 3 deletions install.sh
Expand Up @@ -9,11 +9,19 @@ set -o pipefail
REPO="walles/px"
PXPREFIX=${PXPREFIX:-/usr/local/bin}

# This is the download URL for the latest release
URL=$(curl -s https://api.github.com/repos/$REPO/releases \
| grep browser_download_url \
# Get the download URL for the latest release
TEMPFILE=$(mktemp || mktemp -t px-install-releasesjson.XXXXXXXX)
curl -s https://api.github.com/repos/$REPO/releases > "${TEMPFILE}"
if grep "API rate limit exceeded" "${TEMPFILE}" > /dev/null ; then
cat "${TEMPFILE}" >&2
exit 1
fi

URL=$(
grep browser_download_url "$TEMPFILE" \
| cut -d '"' -f 4 \
| head -n 1)
rm "${TEMPFILE}"

echo "Downloading the latest release..."
echo " $URL"
Expand Down
13 changes: 11 additions & 2 deletions tests/installtest.sh
Expand Up @@ -21,8 +21,12 @@ chmod a+x "${CURL}"
# ... and put both first in the PATH
export PATH=${WORKDIR}:$PATH

# Verify happy path install
PXPREFIX=${WORKDIR} bash -x ./install.sh
cat << EOF
#
# Testing happy-path install...
#
EOF
PXPREFIX=${WORKDIR} bash ./install.sh
test -x "${WORKDIR}/px"
test -x "${WORKDIR}/ptop"

Expand All @@ -37,6 +41,11 @@ chmod a+x "${CURL}"
rm "${WORKDIR}/px"
rm "${WORKDIR}/ptop"

cat << EOF
#
# Testing rate-limited by Github install...
#
EOF
# Installation should fail with an error code, that's why we're "!"ing it
! PXPREFIX=${WORKDIR} bash ./install.sh 2> "${WORKDIR}/message.txt"
# The installer should just have printed the error message on stderr
Expand Down

0 comments on commit ca82a79

Please sign in to comment.