From fe0b7ae7cf91465c295d9fa415359e00a84600a0 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Thu, 10 Aug 2023 19:58:16 -0400 Subject: [PATCH] feat: use gotoolchain Signed-off-by: Artur Troian --- .env | 2 - .github/workflows/integration-tests.yaml | 12 +++- .github/workflows/release.yaml | 14 +++-- .github/workflows/tests.yaml | 80 +++++++++++++++--------- go.mod | 3 +- make/init.mk | 19 ++++-- make/releasing.mk | 6 +- 7 files changed, 87 insertions(+), 49 deletions(-) diff --git a/.env b/.env index 06cd756ab..45fd6b764 100644 --- a/.env +++ b/.env @@ -1,6 +1,4 @@ -GOLANG_VERSION=1.20.2 KINDEST_VERSION=v1.24.7 -GORELEASER_VERSION=v1.11.4 GO111MODULE=on REDIS_VERSION=7 ROOT_DIR=${AP_ROOT} diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 0af51c24b..8809ad6f2 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -19,10 +19,16 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: HatsuneMiku3939/direnv-action@v1 - - uses: actions/setup-go@v3 + - name: set environment + uses: HatsuneMiku3939/direnv-action@v1 + - 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 + echo "GOROOT=/opt/hostedtoolcache/go/${toolchain}/x64" >> $GITHUB_ENV + - uses: actions/setup-go@v4 with: - go-version: "${{ env.GOLANG_VERSION }}" + go-version: "${{ env.GOVERSION }}" - name: Fetch kind version from go modules run: echo "KIND_VERSION=$(go list -mod=readonly -m -f '{{ .Version }}' sigs.k8s.io/kind)" >> $GITHUB_ENV - name: Set up QEMU diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b2397287e..46e895ec1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,12 +16,16 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: c-py/action-dotenv-to-setenv@v3 + - name: set environment + uses: HatsuneMiku3939/direnv-action@v1 + - 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 + echo "GOROOT=/opt/hostedtoolcache/go/${toolchain}/x64" >> $GITHUB_ENV + - uses: actions/setup-go@v4 with: - env-file: .env - - uses: actions/setup-go@v3 - 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 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a96d176d9..1d7fa9014 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -19,12 +19,16 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: c-py/action-dotenv-to-setenv@v3 - with: - env-file: .env - - uses: actions/setup-go@v3 - with: - go-version: "${{ env.GOLANG_VERSION }}" + - name: set environment + uses: HatsuneMiku3939/direnv-action@v1 + - 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 + echo "GOROOT=/opt/hostedtoolcache/go/${toolchain}/x64" >> $GITHUB_ENV + - uses: actions/setup-go@v4 + with: + go-version: "${{ env.GOVERSION }}" - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx @@ -38,12 +42,16 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: c-py/action-dotenv-to-setenv@v3 - with: - env-file: .env - - uses: actions/setup-go@v3 - with: - go-version: "${{ env.GOLANG_VERSION }}" + - name: set environment + uses: HatsuneMiku3939/direnv-action@v1 + - 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 + echo "GOROOT=/opt/hostedtoolcache/go/${toolchain}/x64" >> $GITHUB_ENV + - uses: actions/setup-go@v4 + with: + go-version: "${{ env.GOVERSION }}" - run: make test-full lint: @@ -52,12 +60,16 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: c-py/action-dotenv-to-setenv@v3 - with: - env-file: .env - - uses: actions/setup-go@v3 - with: - go-version: "${{ env.GOLANG_VERSION }}" + - name: set environment + uses: HatsuneMiku3939/direnv-action@v1 + - 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 + echo "GOROOT=/opt/hostedtoolcache/go/${toolchain}/x64" >> $GITHUB_ENV + - uses: actions/setup-go@v4 + with: + go-version: "${{ env.GOVERSION }}" - run: make build - run: make test-vet - name: lint all @@ -73,12 +85,16 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: c-py/action-dotenv-to-setenv@v3 - with: - env-file: .env - - uses: actions/setup-go@v3 - with: - go-version: "${{ env.GOLANG_VERSION }}" + - name: set environment + uses: HatsuneMiku3939/direnv-action@v1 + - 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 + echo "GOROOT=/opt/hostedtoolcache/go/${toolchain}/x64" >> $GITHUB_ENV + - uses: actions/setup-go@v4 + with: + go-version: "${{ env.GOVERSION }}" - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx @@ -97,12 +113,16 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: c-py/action-dotenv-to-setenv@v3 - with: - env-file: .env - - uses: actions/setup-go@v3 - with: - go-version: "${{ env.GOLANG_VERSION }}" + - name: set environment + uses: HatsuneMiku3939/direnv-action@v1 + - 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 + echo "GOROOT=/opt/hostedtoolcache/go/${toolchain}/x64" >> $GITHUB_ENV + - uses: actions/setup-go@v4 + with: + go-version: "${{ env.GOVERSION }}" - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: diff --git a/go.mod b/go.mod index 40c911129..949bb8c3c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,7 @@ module github.com/akash-network/provider -go 1.18 +go 1.20 +toolchain go1.21.0 require ( github.com/akash-network/akash-api v0.0.26 diff --git a/make/init.mk b/make/init.mk index 01ac242e6..d6479018b 100644 --- a/make/init.mk +++ b/make/init.mk @@ -44,8 +44,6 @@ UNAME_OS_LOWER := $(shell uname -s | tr '[:upper:]' '[:lower:]') # uname reports x86_64. rename to amd64 to make it usable by goreleaser UNAME_ARCH ?= $(shell uname -m | sed "s/x86_64/amd64/g") -SEMVER := $(ROOT_DIR)/script/semver.sh - ifeq (, $(shell which wget)) $(error "No wget in $(PATH), consider installing") endif @@ -55,17 +53,26 @@ $(error "No realpath in $(PATH), consider installing") endif BINS := $(PROVIDER_SERVICES) akash +SEMVER := $(ROOT_DIR)/script/semver.sh + +__local_go := $(shell GOTOOLCHAIN=local go version | cut -d ' ' -f 3 | sed 's/go*//' | tr -d '\n') +__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 + +GO_VERSION := $(shell go mod edit -json | jq -r .Go | tr -d '\n') +GOTOOLCHAIN := $(shell go mod edit -json | jq -r .Toolchain | tr -d '\n') +GOTOOLCHAIN_SEMVER := v$(shell echo "$(GOTOOLCHAIN)" | sed 's/go*//' | tr -d '\n') GOWORK ?= on GO_MOD ?= readonly - export 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) -DETECTED_GO_VERSION := $(shell go version | cut -d ' ' -f 3 | sed 's/go*//') - ifeq ($(OS),Windows_NT) DETECTED_OS := Windows else @@ -78,7 +85,7 @@ ifeq ($(DETECTED_OS), Darwin) # 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 "$(GOTOOLCHAIN_SEMVER)" "v1.22.0" | tr -d '\n') ifeq (15,$(clang_version)) ifeq (-1,$(go_has_ld_fix)) diff --git a/make/releasing.mk b/make/releasing.mk index 0a77e55b5..5924f8362 100644 --- a/make/releasing.mk +++ b/make/releasing.mk @@ -1,6 +1,6 @@ GORELEASER_RELEASE ?= false GORELEASER_DEBUG ?= false -GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GOLANG_VERSION) +GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:$(GOTOOLCHAIN_SEMVER) GORELEASER_MOUNT_CONFIG ?= false ifeq ($(GORELEASER_RELEASE),true) @@ -60,6 +60,7 @@ docker-image: -e LINKMODE="$(GO_LINKMODE)" \ -e DOCKER_IMAGE=$(RELEASE_DOCKER_IMAGE) \ -e GOPATH=/go \ + -e GOTOOLCHAIN="$(GOTOOLCHAIN)" \ -v $(GOPATH):/go:ro \ -v /var/run/docker.sock:/var/run/docker.sock \ -v $(shell pwd):/go/src/$(GO_MOD_NAME) \ @@ -90,8 +91,9 @@ release: gen-changelog -e GITHUB_TOKEN="$(GITHUB_TOKEN)" \ -e GORELEASER_CURRENT_TAG="$(RELEASE_TAG)" \ -e DOCKER_IMAGE=$(RELEASE_DOCKER_IMAGE) \ - -v /var/run/docker.sock:/var/run/docker.sock \ + -e GOTOOLCHAIN="$(GOTOOLCHAIN)" \ -e GOPATH=/go \ + -v /var/run/docker.sock:/var/run/docker.sock \ -v $(GOPATH):/go:ro \ -v $(shell pwd):/go/src/$(GO_MOD_NAME) \ -w /go/src/$(GO_MOD_NAME)\