Skip to content

Commit dc6791e

Browse files
committed
Retry fetching go-pear.phar correctly
curl's `--retry` is only for temporary transfer errors, and auth failures (401, 403) will not be retried. We must implement a crude retry. Here, we sleep 3 minutes up to 10 times to see if the API rate limiting is lifted while we run the build.
1 parent b0da7a5 commit dc6791e

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

bin/compile

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
#!/usr/bin/env bash
22

33
function fetch_pear() {
4+
set +o errexit
5+
local tries max_tries
6+
7+
tries=1
8+
max_tries=10
9+
sleep_interval=180
10+
411
if [ -n $GITHUB_TOKEN ]; then
512
auth_flag="-H 'Authorization: token $GITHUB_TOKEN'"
613
fi
714

8-
latest_tag=$(curl -sSfL --retry 20 "${auth_flag}" https://api.github.com/repos/pear/pearweb_phars/releases/latest | jq -r .tag_name)
9-
curl -sSfL "${auth_flag}" --retry 20 -O https://raw.githubusercontent.com/pear/pearweb_phars/${latest_tag}/go-pear.phar
15+
while [[ $tries -le $max_tries ]]; do
16+
echo "Try $tries of $max_tries"
17+
latest_tag=$(curl -sSfL --retry 20 "${auth_flag}" https://api.github.com/repos/pear/pearweb_phars/releases/latest | jq -r .tag_name)
18+
if [ -n $latest_tag ]; then
19+
curl -sSfL "${auth_flag}" --retry 20 -O https://raw.githubusercontent.com/pear/pearweb_phars/${latest_tag}/go-pear.phar
20+
fi
21+
22+
if [ -f go-pear.phar ]; then
23+
break
24+
fi
25+
26+
let tries=$tries+1
27+
echo "Failed to fetch the latest go-pear.phar. Sleeping for ${sleep_interval} seconds."
28+
sleep $sleep_interval
29+
done
30+
1031

1132
if [ ! -f go-pear.phar ]; then
1233
echo "Latest PEAR tarball not found"
1334
exit 1
1435
fi
36+
set -o errexit
1537
}
1638

1739
set -o errexit
@@ -43,7 +65,7 @@ sudo wget -O /usr/local/ssl/cert.pem https://curl.haxx.se/ca/cacert.pem
4365
if [[ ! $VERSION =~ ^master$ || $VERSION =~ snapshot$ ]]; then
4466
# pear
4567
fetch_pear
46-
68+
4769
env TZ=UTC $TRAVIS_BUILD_DIR/bin/install-pear
4870
rm go-pear.phar
4971
"$INSTALL_DEST/$VERSION/bin/pear" config-set php_ini "$INSTALL_DEST/$VERSION/etc/php.ini" system

0 commit comments

Comments
 (0)