Use direct download URLs instead of API

GitHub's API is throttled to 60 requests per hour per IP address when
for non-authenticated calls, which was causing severe CI flakiness.
While this adds another set of URLs to update for each release, the
alternative was adding an OAuth token and maintaining its ownership.
Moreover, this code is simpler than the previous API parsing.
This commit is contained in:
Andrew Schwartzmeyer 2016-09-02 16:32:06 -07:00
parent 363657717c
commit 27530c403c
2 changed files with 11 additions and 18 deletions

View file

@ -15,7 +15,9 @@ addons:
paths: $(ls powershell*{deb,pkg} | tr "\n" ":")
install:
- (cd tools && ./download.sh)
- pushd tools
- ./download.sh
- popd
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then rvm use 2.2.1; fi # Default 2.0.0 Ruby is buggy
script: ./tools/travis.sh

View file

@ -7,10 +7,9 @@ trap '
kill -s INT "$$"
' INT
# Retrieves asset ID and package name of asset ending in argument
# $info looks like: "id": 1698239, "name": "powershell_0.4.0-1_amd64.deb",
get_info() {
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | grep -B 1 "name.*$1"
get_url() {
release=v6.0.0-alpha.9
echo "https://github.com/PowerShell/PowerShell/releases/download/$release/$1"
}
# Get OS specific asset ID and package name
@ -25,7 +24,7 @@ case "$OSTYPE" in
sudo yum install -y curl
fi
version=rpm
package=powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm
;;
ubuntu)
if ! hash curl 2>/dev/null; then
@ -35,10 +34,10 @@ case "$OSTYPE" in
case "$VERSION_ID" in
14.04)
version=ubuntu1.14.04.1_amd64.deb
package=powershell_6.0.0-alpha.9-1ubuntu1.14.04.1_amd64.deb
;;
16.04)
version=ubuntu1.16.04.1_amd64.deb
package=powershell_6.0.0-alpha.9-1ubuntu1.16.04.1_amd64.deb
;;
*)
echo "Ubuntu $VERSION_ID is not supported!" >&2
@ -52,7 +51,7 @@ case "$OSTYPE" in
;;
darwin*)
# We don't check for curl as macOS should have a system version
version=pkg
package=powershell-6.0.0-alpha.9.pkg
;;
*)
echo "$OSTYPE is not supported!" >&2
@ -60,15 +59,7 @@ case "$OSTYPE" in
;;
esac
info=$(get_info "$version")
# Parses $info for asset ID and package name
read asset package <<< $(echo "$info" | sed 's/[,"]//g' | awk '{ print $2; print $4 }')
# Downloads asset to file
packageuri=$(curl -s -i -H 'Accept: application/octet-stream' "https://api.github.com/repos/PowerShell/PowerShell/releases/assets/$asset" |
grep location | sed 's/location: //g')
curl -C - -o "$package" ${packageuri%$'\r'}
curl -L -o "$package" $(get_url "$package")
if [[ ! -r "$package" ]]; then
echo "ERROR: $package failed to download! Aborting..." >&2