Jelajahi Sumber

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 <marco@crowdsec.net>
Manuel Sabban 2 tahun lalu
induk
melakukan
7c3dbffcc6
3 mengubah file dengan 10 tambahan dan 14 penghapusan
  1. 5 1
      Makefile
  2. 5 8
      platform/unix_common.mk
  3. 0 5
      platform/windows.mk

+ 5 - 1
Makefile

@@ -46,6 +46,11 @@ BUILD_CMD = build
 
 
 MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
 MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
 MINIMUM_SUPPORTED_GO_MINOR_VERSION = 18
 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)
 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= \
 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.BuildDate=$(BUILD_TIMESTAMP)' \
 -X 'github.com/crowdsecurity/crowdsec/pkg/cwversion.Codename=$(BUILD_CODENAME)' \
 -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.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.defaultConfigDir=$(DEFAULT_CONFIGDIR)' \
 -X 'github.com/crowdsecurity/crowdsec/pkg/csconfig.defaultDataDir=$(DEFAULT_DATADIR)'
 -X 'github.com/crowdsecurity/crowdsec/pkg/csconfig.defaultDataDir=$(DEFAULT_DATADIR)'
 
 

+ 5 - 8
platform/unix_common.mk

@@ -5,18 +5,15 @@ CPR=cp -r
 MKDIR=mkdir -p
 MKDIR=mkdir -p
 
 
 # Go should not be required to run functional tests
 # 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
 #Current versioning information from env
-BUILD_VERSION?="$(shell git describe --tags)"
+BUILD_VERSION?=$(shell git describe --tags)
 BUILD_CODENAME="alphaga"
 BUILD_CODENAME="alphaga"
 BUILD_TIMESTAMP=$(shell date +%F"_"%T)
 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_CONFIGDIR?=/etc/crowdsec
 DEFAULT_DATADIR?=/var/lib/crowdsec/data
 DEFAULT_DATADIR?=/var/lib/crowdsec/data

+ 0 - 5
platform/windows.mk

@@ -8,11 +8,6 @@ PREFIX=$(shell $$env:TEMP)
 GOOS ?= $(shell go env GOOS)
 GOOS ?= $(shell go env GOOS)
 GOARCH ?= $(shell go env GOARCH)
 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
 #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')
 #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
 #hardcode it till i find a workaround