From e280aa1c63608b034289023bb2e66988861e68bf Mon Sep 17 00:00:00 2001 From: Jason Paul Deland <9366595+jaydeland@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:27:50 -0400 Subject: [PATCH] Update to get latest release from S3 (#15952) * Update to get latest release from S3 * Update mmctl to download to use S3 * Download MMCTL from S3 * Update download_mmctl_release.sh * Update Makefile * Update release.mk * Update the script called, remove call to sub shell and clean up indentation * Add quotes around THIS_BRANCH var * Update script to support overriding the OS for packaging Co-authored-by: Mattermod --- Makefile | 9 ++------- build/release.mk | 13 ++++++++----- scripts/download_mmctl_release.sh | 29 ++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index bf65ba7421..af0af2c2af 100644 --- a/Makefile +++ b/Makefile @@ -188,14 +188,9 @@ prepackaged-plugins: ## Populate the prepackaged-plugins directory prepackaged-binaries: ## Populate the prepackaged-binaries to the bin directory ifeq ($(shell test -f bin/mmctl && printf "yes"),yes) - @echo "mmctl already exists in bin/mmctl not downloading a new version." + @echo "MMCTL already exists in bin/mmctl not downloading a new version." else - @MMCTL_VERSION=$$(scripts/get_latest_release.sh mattermost/mmctl release-); if [ $$? -eq 0 ]; then \ - scripts/download_mmctl_release.sh $$MMCTL_VERSION; \ - else \ - echo $$MMCTL_VERSION; \ - exit 1; \ - fi; + @scripts/download_mmctl_release.sh endif golangci-lint: ## Run golangci-lint on codebase diff --git a/build/release.mk b/build/release.mk index b9711ff41c..4d37fc2e86 100644 --- a/build/release.mk +++ b/build/release.mk @@ -97,8 +97,8 @@ package: mkdir -p $(DIST_PATH)/client cp -RL $(BUILD_WEBAPP_DIR)/dist/* $(DIST_PATH)/client - $(eval MMCTL_REL_TO_DOWNLOAD := $(shell scripts/get_latest_release.sh 'mattermost/mmctl' 'release-')) - @echo "Using mmctl version $(MMCTL_REL_TO_DOWNLOAD)" + @#Download MMCTL + scripts/download_mmctl_release.sh @# Help files ifeq ($(BUILD_ENTERPRISE_READY),true) @@ -133,7 +133,8 @@ else cp $(GOBIN)/darwin_amd64/mattermost $(DIST_PATH)/bin # from cross-compiled bin dir cp $(GOBIN)/darwin_amd64/platform $(DIST_PATH)/bin # from cross-compiled bin dir endif - MMCTL_FILE="darwin_amd64.tar" && curl -f -O -L https://github.com/mattermost/mmctl/releases/download/$(MMCTL_REL_TO_DOWNLOAD)/$$MMCTL_FILE && tar -xvf $$MMCTL_FILE -C $(DIST_PATH)/bin && rm $$MMCTL_FILE + #Download MMCTL for OSX + scripts/download_mmctl_release.sh "Darwin" @# Prepackage plugins @for plugin_package in $(PLUGIN_PACKAGES) ; do \ ARCH="osx-amd64"; \ @@ -167,7 +168,8 @@ else cp $(GOBIN)/windows_amd64/mattermost.exe $(DIST_PATH)/bin # from cross-compiled bin dir cp $(GOBIN)/windows_amd64/platform.exe $(DIST_PATH)/bin # from cross-compiled bin dir endif - MMCTL_FILE="windows_amd64.zip" && curl -f -O -L https://github.com/mattermost/mmctl/releases/download/$(MMCTL_REL_TO_DOWNLOAD)/$$MMCTL_FILE && unzip -o $$MMCTL_FILE -d $(DIST_PATH)/bin && rm $$MMCTL_FILE + #Download MMCTL for Windows + scripts/download_mmctl_release.sh "Windows" @# Prepackage plugins @for plugin_package in $(PLUGIN_PACKAGES) ; do \ ARCH="windows-amd64"; \ @@ -201,7 +203,8 @@ else cp $(GOBIN)/linux_amd64/mattermost $(DIST_PATH)/bin # from cross-compiled bin dir cp $(GOBIN)/linux_amd64/platform $(DIST_PATH)/bin # from cross-compiled bin dir endif - MMCTL_FILE="linux_amd64.tar" && curl -f -O -L https://github.com/mattermost/mmctl/releases/download/$(MMCTL_REL_TO_DOWNLOAD)/$$MMCTL_FILE && tar -xvf $$MMCTL_FILE -C $(DIST_PATH)/bin && rm $$MMCTL_FILE + #Download MMCTL for Linux + scripts/download_mmctl_release.sh "Linux" @# Prepackage plugins @for plugin_package in $(PLUGIN_PACKAGES) ; do \ ARCH="linux-amd64"; \ diff --git a/scripts/download_mmctl_release.sh b/scripts/download_mmctl_release.sh index 0734b8af49..d9534a4108 100755 --- a/scripts/download_mmctl_release.sh +++ b/scripts/download_mmctl_release.sh @@ -8,22 +8,41 @@ else PLATFORM=$(uname) fi +if [[ ! -z "$1" ]]; +then + OVERRIDE_OS=$1 +fi + # strip whitespace -RELEASE_TO_DOWNLOAD=$(echo "$1" | xargs echo) -echo "Downloading prepackaged binary: https://github.com/mattermost/mmctl/releases/$RELEASE_TO_DOWNLOAD"; +THIS_BRANCH=$(git rev-parse --abbrev-ref HEAD) +if [[ "$THIS_BRANCH" =~ 'release-' ]]; +then + RELEASE_TO_DOWNLOAD="$THIS_BRANCH" +else + RELEASE_TO_DOWNLOAD=master +fi + +echo "Downloading prepackaged binary: https://releases.mattermost.com/mmctl/$RELEASE_TO_DOWNLOAD"; + +# When packaging we need to download different platforms +# Values need to match the case statement below +if [[ ! -z "$OVERRIDE_OS" ]]; +then + PLATFORM="$OVERRIDE_OS" +fi 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"; + MMCTL_FILE="linux_amd64.tar" && curl -f -O -L https://releases.mattermost.com/mmctl/"$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"; + MMCTL_FILE="darwin_amd64.tar" && curl -f -O -L https://releases.mattermost.com/mmctl/"$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"; + MMCTL_FILE="windows_amd64.zip" && curl -f -O -L https://releases.mattermost.com/mmctl/"$RELEASE_TO_DOWNLOAD"/"$MMCTL_FILE" && unzip -o "$MMCTL_FILE" -d bin && rm "$MMCTL_FILE"; ;; *)