Skip to content

Commit 37a8e5e

Browse files
authored
Do not hit github api to get latest version from install script (#347)
* do not hit github api to get latest version * don't use PCRE
1 parent dd6f633 commit 37a8e5e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Diff for: install.sh

+19-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ initDownloadTool() {
6767
echo "Using $DOWNLOAD_TOOL as download tool"
6868
}
6969

70+
checkLatestVersion() {
71+
# Use the GitHub releases webpage to find the latest version for this project
72+
# so we don't get rate-limited.
73+
local tag
74+
local regex="[0-9][A-Za-z0-9\.-]*"
75+
local latest_url="https://github.com/arduino/arduino-cli/releases/latest"
76+
if [ "$DOWNLOAD_TOOL" = "curl" ]; then
77+
tag=$(curl -SsL $latest_url | grep -o "Release $regex · arduino/arduino-cli" | grep -o "$regex")
78+
elif [ "$DOWNLOAD_TOOL" = "wget" ]; then
79+
tag=$(wget -q -O - $latest_url | grep -o "Release $regex · arduino/arduino-cli" | grep -o "$regex")
80+
fi
81+
if [ "x$tag" == "x" ]; then
82+
echo "Cannot determine latest tag."
83+
exit 1
84+
fi
85+
eval "$1='$tag'"
86+
}
87+
7088
get() {
7189
local url="$2"
7290
local body
@@ -101,8 +119,7 @@ getFile() {
101119
}
102120

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

0 commit comments

Comments
 (0)