[MM-28303]: check if mmctl exists before checking on Github and reduce requests to Github (#15387)

Summary:
Every make call would ping Github to find out the mmctl version to download. Each check made 4 requests to Github. So every make execution resulted in 4 requests to Github. This leads to frequent rate-limit errors from Github.
In this PR we check for the mmctl version only if mmctl doesn't already exist. We also print a more helpful error message.
Reduce the number the number of requests to Github from 4 to 2.

Ticket Link:
https://mattermost.atlassian.net/browse/MM-28303
Этот коммит содержится в:
Ashish Bhate
2020-09-24 14:54:57 +05:30
коммит произвёл GitHub
родитель 605f96fbea
Коммит ee76ad435b
4 изменённых файлов: 68 добавлений и 39 удалений

Просмотреть файл

@@ -14,39 +14,44 @@ BASIC_AUTH=""
# much more strict for unauthenticated requests.
if [[ ! -z "$GITHUB_USERNAME" && ! -z "$GITHUB_TOKEN" ]];
then
BASIC_AUTH="--user $GITHUB_USERNAME:$GITHUB_TOKEN"
BASIC_AUTH="--user $GITHUB_USERNAME:$GITHUB_TOKEN"
fi
LATEST_REL=$(curl \
LATEST_RELEASE=$(curl \
--silent \
$BASIC_AUTH \
"https://api.github.com/repos/$REPO_TO_USE/releases/latest" \
| grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
$BASIC_AUTH \
"https://api.github.com/repos/$REPO_TO_USE/releases/latest")
DRAFT=$(curl \
RELEASES=$(curl \
--silent \
$BASIC_AUTH \
"https://api.github.com/repos/$REPO_TO_USE/releases/latest" \
| grep '"draft":' | sed -E 's/.*: ([^,]+).*/\1/')
$BASIC_AUTH \
"https://api.github.com/repos/$REPO_TO_USE/releases")
PRERELEASE=$(curl \
--silent \
$BASIC_AUTH \
"https://api.github.com/repos/$REPO_TO_USE/releases" \
| grep '"prerelease":' | sed -E 's/.*: ([^,]+).*/\1/')
LATEST_REL=$(echo "$LATEST_RELEASE" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
DRAFT=$(echo "$LATEST_RELEASE" | grep '"draft":' | sed -E 's/.*: ([^,]+).*/\1/')
PRERELEASE=$(echo "$RELEASES" | grep '"prerelease":' | sed -E 's/.*: ([^,]+).*/\1/')
# Check if this is a release branch
THIS_BRANCH=$(git rev-parse --abbrev-ref HEAD)
#THIS_BRANCH="release-5.27"# - Used to test release logic on a non release branch
if [[ "$THIS_BRANCH" =~ $BRANCH_TO_USE || $DRAFT =~ "true" ]]; then
VERSION_REL=${THIS_BRANCH//$BRANCH_TO_USE/v}
REL_TO_USE=$(curl --silent $BASIC_AUTH "https://api.github.com/repos/$REPO_TO_USE/releases" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed -n "/$VERSION_REL/p" | sort -rV | head -n 1)
VERSION_REL=${THIS_BRANCH//$BRANCH_TO_USE/v}
REL_TO_USE=$(echo "$RELEASES" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed -n "/$VERSION_REL/p" | sort -rV | head -n 1)
elif [[ "$THIS_BRANCH" =~ "master" ]]; then
# Get the latest release even if its a pre-release
REL_TO_USE=$(curl --silent $BASIC_AUTH "https://api.github.com/repos/$REPO_TO_USE/releases" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sort -rV | head -n 1)
# Get the latest release even if its a pre-release
REL_TO_USE=$(echo "$RELEASES" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sort -rV | head -n 1)
else
REL_TO_USE=$LATEST_REL
REL_TO_USE=$LATEST_REL
fi
echo "$REL_TO_USE"
if [[ -z "$REL_TO_USE" ]]
then
echo "An error has occured trying to get the latest mmctl release. Aborting. Perhaps api.github.com is down, or you are being rate-limited.";
echo "Set the GITHUB_USERNAME and GITHUB_TOKEN environment variables to the appropriate values to work around Github rate-limiting.";
exit 1;
else
echo "$REL_TO_USE"
fi