diff --git a/Makefile b/Makefile index a958f4715c..4026443624 100644 --- a/Makefile +++ b/Makefile @@ -120,12 +120,10 @@ else ALL_PACKAGES=$(TE_PACKAGES) endif -all: run ## Alias for 'run'. - # Decide what version of prebuilt binaries to download. This will use the release-* branch names or change to the latest. -# The second sed will look for v.* and if its not found replace it with the word latest -LATEST_RELEASE_MMCTL = $(shell scripts/get_latest_release.sh 'mattermost/mmctl') -REL_TO_DOWNLOAD = $(shell git rev-parse --abbrev-ref HEAD | sed 's/release-/v/' | sed '/v\([0-9]\)\./! s/\(.*\)/$(LATEST_RELEASE_MMCTL)/') +MMCTL_REL_TO_DOWNLOAD = $(shell scripts/get_latest_release.sh 'mattermost/mmctl' 'release-') + +all: run ## Alias for 'run'. include build/*.mk @@ -177,14 +175,14 @@ prepackaged-binaries: ## Populate the prepackaged-binaries to the bin directory ifeq ($(shell test -f bin/mmctl && echo -n yes),yes) @echo mmctl installed else ifeq ($(PLATFORM),Darwin) - @echo Downloading prepackaged binary: https://github.com/mattermost/mmctl/releases/$(REL_TO_DOWNLOAD) - @MMCTL_FILE="darwin_amd64.tar" && curl -f -O -L https://github.com/mattermost/mmctl/releases/download/$(REL_TO_DOWNLOAD)/$$MMCTL_FILE && tar -xvf $$MMCTL_FILE -C bin && rm $$MMCTL_FILE + @echo Downloading prepackaged binary: https://github.com/mattermost/mmctl/releases/$(MMCTL_REL_TO_DOWNLOAD) + @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 bin && rm $$MMCTL_FILE else ifeq ($(PLATFORM),Linux) - @echo Downloading prepackaged binary: https://github.com/mattermost/mmctl/releases/$(REL_TO_DOWNLOAD) - @MMCTL_FILE="linux_amd64.tar" && curl -f -O -L https://github.com/mattermost/mmctl/releases/download/$(REL_TO_DOWNLOAD)/$$MMCTL_FILE && tar -xvf $$MMCTL_FILE -C bin && rm $$MMCTL_FILE + @echo Downloading prepackaged binary: https://github.com/mattermost/mmctl/releases/$(MMCTL_REL_TO_DOWNLOAD) + @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 bin && rm $$MMCTL_FILE else ifeq ($(PLATFORM),Windows) - @echo Downloading prepackaged binary: https://github.com/mattermost/mmctl/releases/$(REL_TO_DOWNLOAD) - @MMCTL_FILE="windows_amd64.zip" && curl -f -O -L https://github.com/mattermost/mmctl/releases/download/$(REL_TO_DOWNLOAD)/$$MMCTL_FILE && unzip -o $$MMCTL_FILE -d bin && rm $$MMCTL_FILE + @echo Downloading prepackaged binary: https://github.com/mattermost/mmctl/releases/$(MMCTL_REL_TO_DOWNLOAD) + @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 bin && rm $$MMCTL_FILE else @echo "mmctl error: can't detect OS" endif diff --git a/build/release.mk b/build/release.mk index 18d518014d..83f5e1bf65 100644 --- a/build/release.mk +++ b/build/release.mk @@ -102,7 +102,7 @@ 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/$(REL_TO_DOWNLOAD)/$$MMCTL_FILE && tar -xvf $$MMCTL_FILE -C $(DIST_PATH)/bin && rm $$MMCTL_FILE + 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 @# Prepackage plugins @for plugin_package in $(PLUGIN_PACKAGES) ; do \ ARCH="osx-amd64"; \ @@ -136,7 +136,7 @@ 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/$(REL_TO_DOWNLOAD)/$$MMCTL_FILE && unzip -o $$MMCTL_FILE -d $(DIST_PATH)/bin && rm $$MMCTL_FILE + 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 @# Prepackage plugins @for plugin_package in $(PLUGIN_PACKAGES) ; do \ ARCH="windows-amd64"; \ @@ -170,7 +170,7 @@ 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/$(REL_TO_DOWNLOAD)/$$MMCTL_FILE && tar -xvf $$MMCTL_FILE -C $(DIST_PATH)/bin && rm $$MMCTL_FILE + 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 @# Prepackage plugins @for plugin_package in $(PLUGIN_PACKAGES) ; do \ ARCH="linux-amd64"; \ diff --git a/scripts/get_latest_release.sh b/scripts/get_latest_release.sh index 1de3078cc9..872f07c64e 100755 --- a/scripts/get_latest_release.sh +++ b/scripts/get_latest_release.sh @@ -1,14 +1,23 @@ #!/usr/bin/env bash -# Time: 2020-01-29 14:49:24 -# Author: https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c -get_latest_release() { - curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api - grep '"tag_name":' | # Get tag line - sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value -} +# $1 - repo to check against +# $2 - release branch pattern to match +# This script will check if the current repo has version pattern $2 ('release-5.20') in the branch name. +# If it does it will check for a matching release version in the $1 repo and if found check for the newest dot version. +# If the branch pattern isn't found than it will default to the newest release available in $1. +REPO_TO_USE=$1 +BRANCH_TO_USE=$2 -# Usage -# $ get_latest_release "creationix/nvm" -# v0.31.4 -# Assume we are in a git dir -get_latest_release $1 +LATEST_REL=$(curl --silent "https://api.github.com/repos/$REPO_TO_USE/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + +# Check if this is a release branch +THIS_BRANCH=$(git rev-parse --abbrev-ref HEAD) + +if [[ "$THIS_BRANCH" =~ $BRANCH_TO_USE ]]; +then + VERSION_REL=${THIS_BRANCH//$BRANCH_TO_USE/v} + REL_TO_USE=$(curl --silent "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) +else + REL_TO_USE=$(echo "$THIS_BRANCH" | sed "s/\(.*\)/$LATEST_REL/") +fi + +echo "$REL_TO_USE"