diff --git a/.github/workflows/build-binary-package.yml b/.github/workflows/build-binary-package.yml index 115979a..9001f06 100644 --- a/.github/workflows/build-binary-package.yml +++ b/.github/workflows/build-binary-package.yml @@ -10,10 +10,10 @@ jobs: name: Build and upload binary package runs-on: ubuntu-latest steps: - - name: Set up Go 1.19 + - name: Set up Go 1.20.1 uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: 1.20.1 id: go - name: Check out code into the Go module directory uses: actions/checkout@v3 diff --git a/.github/workflows/functional_tests.yaml b/.github/workflows/functional_tests.yaml index f3ea5a2..dda14bc 100644 --- a/.github/workflows/functional_tests.yaml +++ b/.github/workflows/functional_tests.yaml @@ -11,10 +11,10 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - name: Set up Go 1.19 + - name: Set up Go 1.20.1 uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: 1.20.1 id: go - name: Check out code into the Go module directory uses: actions/checkout@v3 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d76dd55..d8372e3 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -12,10 +12,10 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - name: Set up Go 1.19 + - name: Set up Go 1.20.1 uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: 1.20.1 id: go - name: Check out code into the Go module directory uses: actions/checkout@v3 diff --git a/Makefile b/Makefile index 11faae1..78b9158 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ GOCLEAN=$(GOCMD) clean GOTEST=$(GOCMD) test GOGET=$(GOCMD) get - PREFIX?="/" PID_DIR = $(PREFIX)"/var/run/" BINARY_NAME=crowdsec-custom-bouncer @@ -28,7 +27,7 @@ all: clean test build static: clean $(GOBUILD) $(LD_OPTS) -o $(BINARY_NAME) -v -a -tags netgo -ldflags '-w -extldflags "-static"' -build: clean +build: goversion clean $(GOBUILD) $(LD_OPTS) -o $(BINARY_NAME) -v test: @@ -59,3 +58,5 @@ release: build func-tests: build pipenv install --dev pipenv run pytest -v + +include mk/goversion.mk diff --git a/go.mod b/go.mod index fea63f7..6d53bb0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/crowdsecurity/cs-custom-bouncer -go 1.19 +go 1.20 require ( github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf diff --git a/mk/goversion.mk b/mk/goversion.mk new file mode 100644 index 0000000..54c6116 --- /dev/null +++ b/mk/goversion.mk @@ -0,0 +1,23 @@ + +BUILD_REQUIRE_GO_MAJOR ?= 1 +BUILD_REQUIRE_GO_MINOR ?= 20 + +BUILD_GOVERSION = $(subst go,,$(shell go env GOVERSION)) + +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 $(BUILD_REQUIRE_GO_MAJOR).$(BUILD_REQUIRE_GO_MINOR) + +.PHONY: goversion +goversion: + @if [ $(GO_MAJOR_VERSION) -gt $(BUILD_REQUIRE_GO_MAJOR) ]; then \ + exit 0; \ + elif [ $(GO_MAJOR_VERSION) -lt $(BUILD_REQUIRE_GO_MAJOR) ]; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + elif [ $(GO_MINOR_VERSION) -lt $(BUILD_REQUIRE_GO_MINOR) ] ; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + fi diff --git a/pkg/version/version.go b/pkg/version/version.go index 60e6f81..0273749 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -19,10 +19,10 @@ Additional labels for pre-release and build metadata are available as extensions */ var ( - Version string // = "v0.0.0" - BuildDate string // = "I don't remember exactly" - Tag string // = "dev" - GoVersion = runtime.Version() // = "1.13" + Version string // = "v0.0.0" + BuildDate string // = "2023-03-06_09:55:34" + Tag string // = "dev" + GoVersion = runtime.Version()[2:] // = "1.20" ) func ShowStr() string {