[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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
605f96fbea
Коммит
ee76ad435b
33
scripts/download_mmctl_release.sh
Исполняемый файл
33
scripts/download_mmctl_release.sh
Исполняемый файл
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# $1 - version to download
|
||||
|
||||
if [[ "$OS" = "Windows_NT" ]]
|
||||
then
|
||||
PLATFORM="Windows"
|
||||
else
|
||||
PLATFORM=$(uname)
|
||||
fi
|
||||
|
||||
# strip whitespace
|
||||
RELEASE_TO_DOWNLOAD=$(echo "$1" | xargs echo)
|
||||
echo "Downloading prepackaged binary: https://github.com/mattermost/mmctl/releases/$RELEASE_TO_DOWNLOAD";
|
||||
|
||||
case "$PLATFORM" in
|
||||
|
||||
Linux)
|
||||
MMCTL_FILE="linux_amd64.tar" && curl -f -O -L https://github.com/mattermost/mmctl/releases/download/"$RELEASE_TO_DOWNLOAD"/"$MMCTL_FILE" && tar -xvf "$MMCTL_FILE" -C bin && rm "$MMCTL_FILE";
|
||||
;;
|
||||
|
||||
Darwin)
|
||||
MMCTL_FILE="darwin_amd64.tar" && curl -f -O -L https://github.com/mattermost/mmctl/releases/download/"$RELEASE_TO_DOWNLOAD"/"$MMCTL_FILE" && tar -xvf "$MMCTL_FILE" -C bin && rm "$MMCTL_FILE";
|
||||
;;
|
||||
|
||||
Windows)
|
||||
MMCTL_FILE="windows_amd64.zip" && curl -f -O -L https://github.com/mattermost/mmctl/releases/download/"$RELEASE_TO_DOWNLOAD"/"$MMCTL_FILE" && unzip -o "$MMCTL_FILE" -d bin && rm "$MMCTL_FILE";
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "error downloading mmctl: can't detect OS";
|
||||
;;
|
||||
|
||||
esac
|
||||
@@ -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
|
||||
|
||||
Ссылка в новой задаче
Block a user