Skip to content

Commit

Permalink
[build] Check for minimum Go version 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
teo committed Dec 7, 2023
1 parent 6d3f8cb commit b9fff20
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ BUILD := `git rev-parse --short HEAD`

ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 20

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)
GO_VERSION_VALIDATION_ERR_MSG = Go version $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION) is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)

HOST_GOOS=$(shell go env GOOS)
HOST_GOARCH=$(shell go env GOARCH)
CGO_LDFLAGS=
Expand Down Expand Up @@ -82,6 +89,17 @@ build: $(WHAT)

all: vendor generate build

validate-go-version: ## Validates the installed version of go against AliECS 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

install: $(INSTALL_WHAT)
# @for w in $(WHAT); do \
# FLAGS="WHAT_$${w}_BUILD_FLAGS"; \
Expand All @@ -90,7 +108,7 @@ install: $(INSTALL_WHAT)
# $(WHAT_$${w}_BUILD_FLAGS) go install $(VERBOSE_$(V)) $(LDFLAGS) ./cmd/$$w; \
# done

$(WHAT):
$(WHAT): validate-go-version
# @echo -e "WHAT_$@_BUILD_FLAGS $(WHAT_$@_BUILD_FLAGS)"
@echo -e "\033[1;33mgo build -mod=vendor\033[0m ./cmd/$@ \033[1;33m==>\033[0m \033[1;34m./bin/$@\033[0m"
# @echo ${PWD}
Expand All @@ -103,7 +121,7 @@ $(WHAT):
chmod +x bin/o2-aliecs-shmcleaner; \
fi; \

$(INSTALL_WHAT):
$(INSTALL_WHAT): validate-go-version
# @echo -e "WHAT_$(@:install_%=%)_BUILD_FLAGS $(WHAT_$(@:install_%=%)_BUILD_FLAGS)"
@echo -e "\033[1;33mgo install -mod=vendor\033[0m ./cmd/$(@:install_%=%) \033[1;33m==>\033[0m \033[1;34m$$GOPATH/bin/$(@:install_%=%)\033[0m"
# @echo ${PWD}
Expand Down Expand Up @@ -153,7 +171,7 @@ cleanall:
@rm -rf bin tools vendor
@echo -e "clean done: \033[1;34mbin tools vendor\033[0m"

vendor:
vendor: validate-go-version
@echo -e "\033[1;33mgo mod vendor\033[0m"
@go mod vendor

Expand Down

0 comments on commit b9fff20

Please sign in to comment.