Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not hit github api to get latest version from install script #347

Merged
merged 3 commits into from
Aug 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ initDownloadTool() {
echo "Using $DOWNLOAD_TOOL as download tool"
}

checkLatestVersion() {
# Use the GitHub releases webpage to find the latest version for this project
# so we don't get rate-limited.
local tag
local regex="[0-9][A-Za-z0-9\.-]*"
local latest_url="https://github.com/arduino/arduino-cli/releases/latest"
if [ "$DOWNLOAD_TOOL" = "curl" ]; then
tag=$(curl -SsL $latest_url | grep -o "Release $regex · arduino/arduino-cli" | grep -o "$regex")
elif [ "$DOWNLOAD_TOOL" = "wget" ]; then
tag=$(wget -q -O - $latest_url | grep -o "Release $regex · arduino/arduino-cli" | grep -o "$regex")
fi
if [ "x$tag" == "x" ]; then
echo "Cannot determine latest tag."
exit 1
fi
eval "$1='$tag'"
}

get() {
local url="$2"
local body
Expand Down Expand Up @@ -101,8 +119,7 @@ getFile() {
}

downloadFile() {
get TAG_JSON https://api.github.com/repos/arduino/arduino-cli/releases/latest
TAG=$(echo $TAG_JSON | python -c 'import json,sys;obj=json.load(sys.stdin, strict=False);sys.stdout.write(obj["tag_name"])')
checkLatestVersion TAG
echo "TAG=$TAG"
# arduino-cli_0.4.0-rc1_Linux_64bit.[tar.gz, zip]
if [ "$OS" == "Windows" ]; then
Expand Down