Skip to content

Commit d1c1819

Browse files
authored
feat: enforce go version check before install/ build (#371)
check go version before install/ build
1 parent b18e8db commit d1c1819

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ LEDGER_ENABLED ?= true
1818
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
1919
BFT_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::') # grab everything after the space in "github.com/cometbft/cometbft v0.34.7"
2020

21+
GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
22+
GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
23+
GO_MINIMUM_MAJOR_VERSION = $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f2 | cut -d'.' -f1)
24+
GO_MINIMUM_MINOR_VERSION = $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f2 | cut -d'.' -f2)
25+
2126
# process build tags
2227
build_tags = netgo
2328
ifeq ($(LEDGER_ENABLED),true)
@@ -105,10 +110,10 @@ include sims.mk
105110

106111
all: build lint
107112

108-
install: go.sum
113+
install: check-go-version go.sum
109114
go install -mod=readonly $(BUILD_FLAGS) ./cmd/persistenceCore
110115

111-
build:
116+
build: check-go-version
112117
go build $(BUILD_FLAGS) -o bin/persistenceCore ./cmd/persistenceCore
113118

114119
$(BUILDDIR)/:
@@ -124,6 +129,19 @@ vulncheck: $(BUILDDIR)/
124129
### Tools & Dependencies ###
125130
###############################################################################
126131

132+
check-go-version:
133+
# picked from https://github.com/osmosis-labs/osmosis/blob/main/scripts/makefiles/build.mk#L23
134+
@echo "Go version: $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION)"
135+
@if [ $(GO_MAJOR_VERSION) -gt $(GO_MINIMUM_MAJOR_VERSION) ]; then \
136+
echo "Go version is sufficient"; \
137+
exit 0; \
138+
elif [ $(GO_MAJOR_VERSION) -lt $(GO_MINIMUM_MAJOR_VERSION) ]; then \
139+
echo '$(GO_VERSION_ERR_MSG)'; \
140+
exit 1; \
141+
elif [ $(GO_MINOR_VERSION) -lt $(GO_MINIMUM_MINOR_VERSION) ]; then \
142+
echo '$(GO_VERSION_ERR_MSG)'; \
143+
exit 1; \
144+
fi
127145
go.sum: go.mod
128146
@echo "Ensure dependencies have not been modified ..." >&2
129147
go mod verify

0 commit comments

Comments
 (0)