From 74a6299ed5d842ef0376c8c55fb0f57562e34291 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Tue, 24 Sep 2024 17:26:14 +0200 Subject: [PATCH] chore: reinforce go version for building AtomOne Require precisely go1.21.13 to enable reproducible builds with CI. Store version 1.21.13 in Makefile and make it available for CI. --- .github/workflows/release.yml | 5 +++-- Makefile | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6fb3fe4b..8d988660 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,8 +18,9 @@ jobs: with: fetch-depth: 0 - run: git fetch --force --tags - - name: Set Go version - run: echo "GO_VERSION=$(make required_go_version_full)" >> $GITHUB_ENV + + - name: Set go version + run: echo "GO_VERSION=$(make print_required_go_version)" >> $GITHUB_ENV - uses: actions/setup-go@v5 with: diff --git a/Makefile b/Makefile index 0464cba7..2d44a0a6 100644 --- a/Makefile +++ b/Makefile @@ -21,17 +21,12 @@ DOCKER := $(shell which docker) BUILDDIR ?= $(CURDIR)/build TEST_DOCKER_REPO=cosmos/contrib-atomonetest -GO_SYSTEM_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1-2) -REQUIRE_GO_VERSION = 1.21 -REQUIRE_GO_VERSION_FULL = 1.21.13 +GO_SYSTEM_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1) +REQUIRE_GO_VERSION = 1.21.13 export GO111MODULE = on export CGO_ENABLED = 0 -build-ledger: check_version go.sum $(BUILDDIR)/ - @echo "WARNING: Ledger build involves enabling cgo, which disables the ability to have reproducible builds." - CGO_ENABLED=1 go build -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) -o $(BUILDDIR)/ ./... - # process build tags build_tags = netgo @@ -102,12 +97,17 @@ include contrib/devtools/Makefile ### Build ### ############################################################################### -required_go_version_full: - @echo $(REQUIRE_GO_VERSION_FULL) +print_required_go_version: + @echo $(REQUIRE_GO_VERSION) check_version: ifneq ($(GO_SYSTEM_VERSION), $(REQUIRE_GO_VERSION)) - @echo "ERROR: Go version $(REQUIRE_GO_VERSION) is required for $(VERSION) of AtomOne." + @echo 'ERROR: Go version $(REQUIRE_GO_VERSION) is required for building AtomOne' + @echo '--> You can install it using:' + @echo 'go install golang.org/dl/go$(REQUIRE_GO_VERSION)@latest && go$(REQUIRE_GO_VERSION) download' + @echo '--> Then prefix your make command with:' + @echo 'GOROOT=$$(go$(REQUIRE_GO_VERSION) env GOROOT) PATH=$$GOROOT/bin:$$PATH' + exit 1 endif all: install lint run-tests test-e2e vulncheck @@ -119,6 +119,10 @@ build: BUILD_ARGS=-o $(BUILDDIR)/ $(BUILD_TARGETS): check_version go.sum $(BUILDDIR)/ go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./... +build-ledger: go.sum $(BUILDDIR)/ + @echo "WARNING: Ledger build involves enabling cgo, which disables the ability to have reproducible builds." + CGO_ENABLED=1 go build -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) -o $(BUILDDIR)/ ./... + $(BUILDDIR)/: mkdir -p $(BUILDDIR)/