From 5015550f23ae529901c3311e672f2c07b72a64a4 Mon Sep 17 00:00:00 2001 From: Max Vovshin <36747317+Hyaxia@users.noreply.github.com> Date: Tue, 16 Jul 2019 16:08:31 +0300 Subject: [PATCH] GH-11530 - Go major and minor version validation. (#11531) * Added - golang version validation. * Updated error message to include the minor version that is supported. * Fixed issue with variable. * Renamed variable. * Added - golang version validation. Added validation for major and minor versions of go. * Fixed the way the validation is performed. * Changed function declaration (define validate_go_version) to a target (validate_go_version). * remove unneeded call to validate_go_version --- Makefile | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9ca7947f1b..58e65aa776 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,11 @@ LDFLAGS += -X "github.com/mattermost/mattermost-server/model.BuildDate=$(BUILD_D LDFLAGS += -X "github.com/mattermost/mattermost-server/model.BuildHash=$(BUILD_HASH)" LDFLAGS += -X "github.com/mattermost/mattermost-server/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)" LDFLAGS += -X "github.com/mattermost/mattermost-server/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)" +GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) +GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) +MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 +MINIMUM_SUPPORTED_GO_MINOR_VERSION = 12 +GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) # GOOS/GOARCH of the build host, used to determine whether we're cross-compiling or not BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)" @@ -449,7 +454,18 @@ test-data: start-docker ## Add test data to the local instance. @echo Login with a regular account username=user-1 password=user-1 @echo ======================================================================== -run-server: start-docker ## Starts the server. +validate-go-version: ## Validates the installed version of go against Mattermost's minimum requirement. + @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + exit 0 ;\ + elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + fi + +run-server: validate-go-version start-docker ## Starts the server. @echo Running mattermost for development mkdir -p $(BUILD_WEBAPP_DIR)/dist/files