Skip to content

Commit

Permalink
chore: reinforce go version for building AtomOne
Browse files Browse the repository at this point in the history
Require precisely go1.21.13 to enable reproducible builds with CI.
Store version 1.21.13 in Makefile and make it available for CI.
  • Loading branch information
tbruyelle committed Sep 24, 2024
1 parent 0eb17ba commit 74a6299
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 14 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)/

Expand Down

0 comments on commit 74a6299

Please sign in to comment.