Skip to content

Commit

Permalink
feat: use gotoolchain
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Aug 14, 2023
1 parent c73e78b commit fe0b7ae
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 49 deletions.
2 changes: 0 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 50 additions & 30 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand 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
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 13 additions & 6 deletions make/init.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions make/releasing.mk
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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) \
Expand Down Expand Up @@ -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)\
Expand Down

0 comments on commit fe0b7ae

Please sign in to comment.