diff --git a/Makefile b/Makefile index 78df932ecb1..39ef2945d92 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,13 @@ -.PHONY: build package run stop run-client run-server stop-client stop-server restart restart-server restart-client start-docker clean-dist clean nuke check-style check-client-style check-server-style check-unit-tests test dist prepare-enteprise run-client-tests setup-run-client-tests cleanup-run-client-tests test-client build-linux build-osx build-windows internal-test-web-client vet run-server-for-web-client-tests diff-config prepackaged-plugins +.PHONY: build package run stop run-client run-server stop-client stop-server restart restart-server restart-client start-docker clean-dist clean nuke check-style check-client-style check-server-style check-unit-tests test dist prepare-enteprise run-client-tests setup-run-client-tests cleanup-run-client-tests test-client build-linux build-osx build-windows internal-test-web-client vet run-server-for-web-client-tests diff-config prepackaged-plugins prepackaged-binaries ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +ifeq ($(OS),Windows_NT) + PLATFORM := Windows +else + PLATFORM := $(shell uname) +endif + IS_CI ?= false MM_NO_DOCKER ?= false # Build Flags @@ -94,6 +100,7 @@ PLUGIN_PACKAGES += mattermost-plugin-jira-v2.3.2 PLUGIN_PACKAGES += mattermost-plugin-gitlab-v1.0.1 PLUGIN_PACKAGES += mattermost-plugin-jenkins-v1.0.0 + # Prepares the enterprise build if exists. The IGNORE stuff is a hack to get the Makefile to execute the commands outside a target ifeq ($(BUILD_ENTERPRISE_READY),true) IGNORE:=$(shell echo Enterprise build selected, preparing) @@ -113,9 +120,13 @@ 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)/') + include build/*.mk start-docker: ## Starts the docker containers for local development. @@ -161,6 +172,23 @@ prepackaged-plugins: ## Populate the prepackaged-plugins directory curl -f -O -L https://plugins-store.test.mattermost.com/release/$$plugin_package.tar.gz.sig; \ done +prepackaged-binaries: ## Populate the prepackaged-binaries to the bin directory +# Externally built binaries +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 $(GOBIN) && 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 $(GOBIN) && 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 $(DIST_PATH)/bin && rm $$MMCTL_FILE +else + @echo "mmctl error: can't detect OS" +endif + golangci-lint: ## Run golangci-lint on codebase # https://stackoverflow.com/a/677212/1027058 (check if a command exists or not) @if ! [ -x "$$(command -v golangci-lint)" ]; then \ @@ -311,7 +339,7 @@ validate-go-version: ## Validates the installed version of go against Mattermost exit 1; \ fi -run-server: validate-go-version start-docker ## Starts the server. +run-server: prepackaged-binaries validate-go-version start-docker ## Starts the server. @echo Running mattermost for development mkdir -p $(BUILD_WEBAPP_DIR)/dist/files diff --git a/build/release.mk b/build/release.mk index 6f571943554..18d518014dc 100644 --- a/build/release.mk +++ b/build/release.mk @@ -90,6 +90,7 @@ endif done; \ done + @# ----- PLATFORM SPECIFIC ----- @# Make osx package @@ -101,6 +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 @# Prepackage plugins @for plugin_package in $(PLUGIN_PACKAGES) ; do \ ARCH="osx-amd64"; \ @@ -122,6 +124,7 @@ endif @# Cleanup rm -f $(DIST_PATH)/bin/mattermost rm -f $(DIST_PATH)/bin/platform + rm -f $(DIST_PATH)/bin/mmctl rm -f $(DIST_PATH)/prepackaged_plugins/* @# Make windows package @@ -133,6 +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 @# Prepackage plugins @for plugin_package in $(PLUGIN_PACKAGES) ; do \ ARCH="windows-amd64"; \ @@ -154,6 +158,7 @@ endif @# Cleanup rm -f $(DIST_PATH)/bin/mattermost.exe rm -f $(DIST_PATH)/bin/platform.exe + rm -f $(DIST_PATH)/bin/mmctl.exe rm -f $(DIST_PATH)/prepackaged_plugins/* @# Make linux package @@ -165,6 +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 @# 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 new file mode 100755 index 00000000000..1de3078cc98 --- /dev/null +++ b/scripts/get_latest_release.sh @@ -0,0 +1,14 @@ +#!/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 +} + +# Usage +# $ get_latest_release "creationix/nvm" +# v0.31.4 +# Assume we are in a git dir +get_latest_release $1