Skip to content

Commit

Permalink
feat: use gotoolchain
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <troian.ap@gmail.com>
  • Loading branch information
troian committed Aug 10, 2023
1 parent 1b02811 commit e1766f2
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 53 deletions.
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
GOLANG_VERSION=1.20.2
KIND_VERSION=0.11.1
GO111MODULE=on

KIND_VERSION=0.11.1
ROOT_DIR=${AKASH_ROOT}

AKASH_DEVCACHE_BASE=${AKASH_ROOT}/.cache
AKASH_DEVCACHE=${AKASH_DEVCACHE_BASE}
AKASH_DEVCACHE_BIN=${AKASH_DEVCACHE}/bin
Expand Down
10 changes: 9 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,24 @@ if ! has readlink ; then
echo "readlink is not installed"; exit 1
fi


AKASH_ROOT=$(pwd)

export AKASH_ROOT

dotenv
dotenv_if_exists dev.env

GOROOT=$HOME/sdk/go1.21.0

PATH_add "$GOROOT/bin"

PATH_add "$AKASH_DEVCACHE_NODE_BIN"
PATH_add "$AKASH_DEVCACHE_BIN"

export AKASH=$AKASH_DEVCACHE_BIN/akash
AKASH=$AKASH_DEVCACHE_BIN/akash

export GOROOT
export AKASH

make cache
16 changes: 12 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ jobs:
- uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .env
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand Down Expand Up @@ -49,9 +53,13 @@ jobs:
- run: git fetch --prune --unshallow
- name: set environment
uses: HatsuneMiku3939/direnv-action@v1
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- name: detect release tag
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: configure variables
Expand Down
72 changes: 54 additions & 18 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ jobs:
- run: |
brew install bash
sudo chsh -s /usr/local/bin/bash
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- run: make bins
build-bins:
runs-on: ubuntu-latest
Expand All @@ -38,9 +42,13 @@ jobs:
- uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .env
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- run: make bins
- run: make docker-image

Expand All @@ -52,9 +60,13 @@ jobs:
- uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .env
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- run: make test-full

coverage:
Expand All @@ -65,9 +77,13 @@ jobs:
- uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .env
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- run: make test-coverage
- uses: codecov/codecov-action@v3

Expand All @@ -79,9 +95,13 @@ jobs:
- uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .env
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- run: make deps-tidy
- run: make build
- run: make test-vet
Expand All @@ -98,9 +118,13 @@ jobs:
- uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .env
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- run: make shellcheck

sims:
Expand All @@ -113,9 +137,13 @@ jobs:
- uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .env
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- name: test-sim-nondeterminism
run: make test-sim-nondeterminism
- name: test-sim-import-export
Expand All @@ -133,9 +161,13 @@ jobs:
- uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .env
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand Down Expand Up @@ -175,9 +207,13 @@ jobs:
- run: git fetch --prune --unshallow
- name: set environment
uses: HatsuneMiku3939/direnv-action@v1
- uses: actions/setup-go@v3
- run: |
toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//')
echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: "${{ env.GOLANG_VERSION }}"
go-version: "${{ env.GOVERSION }}"
- name: configure variables
run: |
test_required=$(./script/upgrades.sh test-required ${{ github.ref }})
Expand Down
1 change: 1 addition & 0 deletions .goreleaser-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ dockers:

archives:
- format: binary
rlcp: true
2 changes: 0 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ archives:
name_template: "akash_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: false
format: zip
rlcp: true
files:
- none*
- id: wo/version
Expand All @@ -125,7 +124,6 @@ archives:
name_template: "akash_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: false
format: zip
rlcp: true
files:
- none*

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/akash-network/node

go 1.20

toolchain go1.21.0

require (
github.com/akash-network/akash-api v0.0.26
github.com/blang/semver/v4 v4.0.0
Expand Down
38 changes: 13 additions & 25 deletions make/init.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,29 @@ ifndef AKASH_ROOT
PATH := $(AKASH_DEVCACHE_BIN):$(AKASH_DEVCACHE_NODE_BIN):$(PATH)
endif

SEMVER := $(ROOT_DIR)/script/semver.sh

# require go<major>.<minor> to be equal
GO_MIN_REQUIRED := $(shell echo $(GOLANG_VERSION) | cut -f1-2 -d ".")
DETECTED_GO_VERSION := $(shell go version | cut -d ' ' -f 3 | sed 's/go*//')
STRIPPED_GO_VERSION := $(shell echo $(DETECTED_GO_VERSION) | cut -f1-2 -d ".")
__IS_GO_UPTODATE := $(shell $(ROOT_DIR)/script/semver.sh compare $(STRIPPED_GO_VERSION) $(GO_MIN_REQUIRED); echo $?)
GO_MOD_VERSION := $(shell go mod edit -json | jq -r .Go | cut -f1-2 -d ".")
__IS_GO_MOD_MATCHING := $(shell $(SEMVER) compare $(GO_MOD_VERSION) $(GO_MIN_REQUIRED) && echo $?)

ifneq (0, $(__IS_GO_MOD_MATCHING))
$(error go version $(GO_MOD_VERSION) from go.mod does not match GO_MIN_REQUIRED=$(GO_MIN_REQUIRED))
endif
BINS := $(AKASH)
SEMVER := $(AKASH_ROOT)/script/semver.sh

ifneq (0, $(__IS_GO_UPTODATE))
$(error invalid go$(DETECTED_GO_VERSION) version. installed must be == $(GO_MIN_REQUIRED))
else
$(info using go$(DETECTED_GO_VERSION))
__local_go := $(shell GOTOOLCHAIN=local go version | cut -d ' ' -f 3 | sed 's/go*//')
__is_local_go_satisfies := $(shell $(SEMVER) compare "v$(__local_go)" "v1.20.7"; echo $?)

ifeq (-1, $(__is_local_go_satisfies))
$(error "unsupported local go$(__local_go) version . min required go1.21.0")
endif

BINS := $(AKASH)
GO_VERSION := $(shell go mod edit -json | jq -r .Go | sed 's/go*//')
GOTOOLCHAIN := $(shell go mod edit -json | jq -r .Toolchain | sed 's/go*//')

GO := GO111MODULE=$(GO111MODULE) go
GOWORK ?= on

GO_MOD ?= vendor
ifeq ($(GOWORK), on)
GO_MOD := readonly
endif

GO := GO111MODULE=$(GO111MODULE) go
GO_BUILD := $(GO) build -mod=$(GO_MOD)
GO_TEST := $(GO) test -mod=$(GO_MOD)
GO_VET := $(GO) vet -mod=$(GO_MOD)

GO_MOD_NAME := $(shell go list -m 2>/dev/null)

ifeq ($(OS),Windows_NT)
Expand All @@ -63,13 +52,13 @@ else
DETECTED_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif

# on MacOS disable deprecation warnings security framework
ifeq ($(DETECTED_OS), Darwin)
# on MacOS disable deprecation warnings security framework
export CGO_CFLAGS=-Wno-deprecated-declarations

# on MacOS Sonoma Beta there is a bit of discrepancy between Go and new prime linker
clang_version := $(shell echo | clang -dM -E - | grep __clang_major__ | cut -d ' ' -f 3 | tr -d '\n')
go_has_ld_fix := $(shell $(SEMVER) compare "v$(DETECTED_GO_VERSION)" "v1.21.0" | tr -d '\n')
go_has_ld_fix := $(shell $(SEMVER) compare "v$(GOTOOLCHAIN)" "v1.22.0" | tr -d '\n')

ifeq (15,$(clang_version))
ifeq (-1,$(go_has_ld_fix))
Expand All @@ -81,11 +70,10 @@ endif
# ==== Build tools versions ====
# Format <TOOL>_VERSION
GOLANGCI_LINT_VERSION ?= v1.51.2
GOLANG_VERSION ?= 1.16.1
STATIK_VERSION ?= v0.1.7
GIT_CHGLOG_VERSION ?= v0.15.1
MOCKERY_VERSION ?= 2.24.0
COSMOVISOR_VERSION ?= v1.4.0
COSMOVISOR_VERSION ?= v1.5.0

# ==== Build tools version tracking ====
# <TOOL>_VERSION_FILE points to the marker file for the installed version.
Expand Down
4 changes: 3 additions & 1 deletion make/releasing.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GON_CONFIGFILE ?= gon.json

GORELEASER_SKIP_VALIDATE ?= false
GORELEASER_DEBUG ?= false
GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GOLANG_VERSION)
GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GOTOOLCHAIN)
GORELEASER_RELEASE ?= false
GORELEASER_MOUNT_CONFIG ?= false

Expand Down Expand Up @@ -67,6 +67,7 @@ docker-image:
-e LINKMODE="$(GO_LINKMODE)" \
-e DOCKER_IMAGE=$(RELEASE_DOCKER_IMAGE) \
-e GOPATH=/go \
-e GOTOOLCHAIN="go$(GOTOOLCHAIN)" \
-v $(GOPATH):/go:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(GO_MOD_NAME) \
Expand Down Expand Up @@ -96,6 +97,7 @@ release: gen-changelog
-e GITHUB_TOKEN="$(GITHUB_TOKEN)" \
-e GORELEASER_CURRENT_TAG="$(RELEASE_TAG)" \
-e DOCKER_IMAGE=$(RELEASE_DOCKER_IMAGE) \
-e GOTOOLCHAIN="go$(GOTOOLCHAIN)" \
-e GOPATH=/go \
-v $(GOPATH):/go:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
Expand Down

0 comments on commit e1766f2

Please sign in to comment.