From 7c3dbffcc6d62fb2b3a92df7df8bcd71a10ee25c Mon Sep 17 00:00:00 2001 From: Manuel Sabban Date: Fri, 2 Dec 2022 13:04:00 +0100 Subject: [PATCH] clean up BUILD_GOVERSION which is set at runtime with runtime lib (#1901) * clean up BUILD_GOVERSION which is set at runtime with runtime lib * simplify version check Co-authored-by: sabban <15465465+sabban@users.noreply.github.com> Co-authored-by: Marco Mariani --- Makefile | 6 +++++- platform/unix_common.mk | 13 +++++-------- platform/windows.mk | 5 ----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index d38e479a5..897bb00df 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,11 @@ BUILD_CMD = build MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 MINIMUM_SUPPORTED_GO_MINOR_VERSION = 18 + +go_major_minor = $(subst ., ,$(BUILD_GOVERSION)) +GO_MAJOR_VERSION = $(word 1, $(go_major_minor)) +GO_MINOR_VERSION = $(word 2, $(go_major_minor)) + GO_VERSION_VALIDATION_ERR_MSG = Golang version ($(BUILD_GOVERSION)) is not supported, please use at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) LD_OPTS_VARS= \ @@ -55,7 +60,6 @@ LD_OPTS_VARS= \ -X 'github.com/crowdsecurity/crowdsec/pkg/cwversion.BuildDate=$(BUILD_TIMESTAMP)' \ -X 'github.com/crowdsecurity/crowdsec/pkg/cwversion.Codename=$(BUILD_CODENAME)' \ -X 'github.com/crowdsecurity/crowdsec/pkg/cwversion.Tag=$(BUILD_TAG)' \ --X 'github.com/crowdsecurity/crowdsec/pkg/cwversion.GoVersion=$(BUILD_GOVERSION)' \ -X 'github.com/crowdsecurity/crowdsec/pkg/csconfig.defaultConfigDir=$(DEFAULT_CONFIGDIR)' \ -X 'github.com/crowdsecurity/crowdsec/pkg/csconfig.defaultDataDir=$(DEFAULT_DATADIR)' diff --git a/platform/unix_common.mk b/platform/unix_common.mk index 30c56a1ed..7692fd14d 100644 --- a/platform/unix_common.mk +++ b/platform/unix_common.mk @@ -5,18 +5,15 @@ CPR=cp -r MKDIR=mkdir -p # Go should not be required to run functional tests -GOOS ?= $(shell command -v go >/dev/null && go env GOOS) -GOARCH ?= $(shell command -v go >/dev/null && go env GOARCH) +GOOS ?= $(shell go env GOOS) +GOARCH ?= $(shell go env GOARCH) -GO_MAJOR_VERSION = $(shell command -v go >/dev/null && go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) -GO_MINOR_VERSION = $(shell command -v go >/dev/null && go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) - -BUILD_GOVERSION="$(shell command -v go >/dev/null && go version | cut -d " " -f3 | sed -E 's/[go]+//g')" +BUILD_GOVERSION=$(shell go env GOVERSION | sed s/go//) #Current versioning information from env -BUILD_VERSION?="$(shell git describe --tags)" +BUILD_VERSION?=$(shell git describe --tags) BUILD_CODENAME="alphaga" BUILD_TIMESTAMP=$(shell date +%F"_"%T) -BUILD_TAG?="$(shell git rev-parse HEAD)" +BUILD_TAG?=$(shell git rev-parse HEAD) DEFAULT_CONFIGDIR?=/etc/crowdsec DEFAULT_DATADIR?=/var/lib/crowdsec/data diff --git a/platform/windows.mk b/platform/windows.mk index 0370859b2..a8fa4483b 100644 --- a/platform/windows.mk +++ b/platform/windows.mk @@ -8,11 +8,6 @@ PREFIX=$(shell $$env:TEMP) GOOS ?= $(shell go env GOOS) GOARCH ?= $(shell go env GOARCH) -GO_MAJOR_VERSION ?= $(shell (go env GOVERSION).replace("go","").split(".")[0]) -GO_MINOR_VERSION ?= $(shell (go env GOVERSION).replace("go","").split(".")[1]) -MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 -MINIMUM_SUPPORTED_GO_MINOR_VERSION = 17 -GO_VERSION_VALIDATION_ERR_MSG = Golang version ($(BUILD_GOVERSION)) is not supported, please use least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) #Current versioning information from env #BUILD_VERSION?=$(shell (Invoke-WebRequest -UseBasicParsing -Uri https://api.github.com/repos/crowdsecurity/crowdsec/releases/latest).Content | jq -r '.tag_name') #hardcode it till i find a workaround