diff --git a/.envrc b/.envrc index 5b205a86cf..57cf4c4159 100644 --- a/.envrc +++ b/.envrc @@ -47,17 +47,35 @@ if [ -z "$GOPATH" ]; then fi AKASH_ROOT=$(pwd) - export AKASH_ROOT dotenv dotenv_if_exists dev.env +TOOLS=${AKASH_ROOT}/script/tools.sh +SEMVER=${AKASH_ROOT}/script/semver.sh + +GOTOOLCHAIN=$(${TOOLS} gotoolchain) +GOTOOLCHAIN_SEMVER=$(echo "${GOTOOLCHAIN}" | sed 's/go*/v/' | tr -d '\n') + +if [[ "$OSTYPE" == "darwin"* ]]; then + # on MacOS disable deprecation warnings security framework + CGO_CFLAGS=-Wno-deprecated-declarations + + export CGO_CFLAGS +fi + +export SEMVER +export GOTOOLCHAIN +export GOTOOLCHAIN_SEMVER + PATH_add "$AKASH_DEVCACHE_NODE_BIN" PATH_add "$AKASH_DEVCACHE_BIN" +AKASH_DIRENV_SET=1 AKASH=$AKASH_DEVCACHE_BIN/akash +export AKASH_DIRENV_SET export AKASH make cache diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index aeb5b7ab83..896563025e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,9 +13,9 @@ jobs: steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: @@ -50,9 +50,9 @@ jobs: steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a73f761974..17394ed7c8 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -17,30 +17,34 @@ jobs: build-macos: runs-on: macos-latest steps: - - run: | + - name: Install dependencies + run: | brew install bash direnv sudo chsh -s /usr/local/bin/bash + - name: Hook direnv to bash + run: echo 'eval "$(direnv hook bash)"' >> $HOME/.bashrc - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - name: set environment - run: direnv allow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: go-version: "${{ env.GOVERSION }}" check-latest: true + - name: Setup direnv + run: | + direnv allow - run: make bins build-bins: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: @@ -56,9 +60,9 @@ jobs: steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: @@ -72,9 +76,9 @@ jobs: steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: @@ -89,9 +93,9 @@ jobs: steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: @@ -111,9 +115,9 @@ jobs: steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: @@ -129,9 +133,9 @@ jobs: env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - uses: actions/checkout@v3 - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: @@ -152,9 +156,9 @@ jobs: steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: @@ -178,9 +182,9 @@ jobs: steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: @@ -205,9 +209,9 @@ jobs: steps: - uses: actions/checkout@v3 - run: git fetch --prune --unshallow - - run: | - toolchain=$(cat go.mod | grep toolchain | cut -d ' ' -f 2 | sed 's/go*//') - echo "GOTOOLCHAIN=go${toolchain}" >> $GITHUB_ENV + - name: Detect required Go version + run: | + toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//') echo "GOVERSION=${toolchain}" >> $GITHUB_ENV - uses: actions/setup-go@v4 with: diff --git a/go.mod b/go.mod index e0af349257..c448233dc2 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/akash-network/node -go 1.20 - -toolchain go1.21.0 +go 1.21 require ( github.com/akash-network/akash-api v0.0.27 diff --git a/make/init.mk b/make/init.mk index 129242be11..4a012c02e7 100644 --- a/make/init.mk +++ b/make/init.mk @@ -7,33 +7,24 @@ UNAME_ARCH := $(shell uname -m) BASH_PATH := $(shell which bash) ifeq (, $(shell which direnv)) -$(warning "No direnv in $(PATH), consider installing. https://direnv.net") +$(error "No direnv in $(PATH), consider installing. https://direnv.net") +endif + +ifneq (1, $(AKASH_DIRENV_SET)) +$(error "no envrc detected. might need to run \"direnv allow\"") endif # AKASH_ROOT may not be set if environment does not support/use direnv # in this case define it manually as well as all required env variables ifndef AKASH_ROOT - AKASH_ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../) - include $(AKASH_ROOT)/.env - - AKASH := $(AKASH_DEVCACHE_BIN)/akash - # setup .cache bins first in paths to have precedence over already installed same tools for system wide use - PATH := $(AKASH_DEVCACHE_BIN):$(AKASH_DEVCACHE_NODE_BIN):$(PATH) +$(error "AKASH_ROOT is not set. might need to run \"direnv allow\"") endif -BINS := $(AKASH) -SEMVER := $(AKASH_ROOT)/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") +ifeq (, $(GOTOOLCHAIN)) +$(error "GOTOOLCHAIN is not set") 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') +BINS := $(AKASH) GO := GO111MODULE=$(GO111MODULE) go GOWORK ?= on @@ -53,21 +44,6 @@ else DETECTED_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown') endif -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 "$(GOTOOLCHAIN_SEMVER)" "v1.22.0" | tr -d '\n') - - ifeq (15,$(clang_version)) - ifeq (-1,$(go_has_ld_fix)) - export CGO_LDFLAGS=-Wl,-ld_classic -Wno-deprecated-declarations - endif - endif -endif - # ==== Build tools versions ==== # Format _VERSION GOLANGCI_LINT_VERSION ?= v1.51.2 diff --git a/meta.json b/meta.json index 2d93bb20c3..5afb8ccd02 100644 --- a/meta.json +++ b/meta.json @@ -1,7 +1,8 @@ { "releases": { "revoked": [ - "v0.22.1" + "v0.22.1", + "v0.26.0" ] }, "upgrades": { diff --git a/script/tools.sh b/script/tools.sh new file mode 100755 index 0000000000..599e1a0ec9 --- /dev/null +++ b/script/tools.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" +SEMVER=$SCRIPT_DIR/semver.sh + +gomod="$SCRIPT_DIR/../go.mod" + +function get_gotoolchain() { + local gotoolchain + local goversion + + gotoolchain=$(grep -E '^toolchain go[0-9]{1,}.[0-9]{1,}.[0-9]{1,}$' < "$gomod" | cut -d ' ' -f 2 | tr -d '\n') + + if [[ ${gotoolchain} == "" ]]; then + # determine go toolchain from go version in go.mod + if which go > /dev/null 2>&1 ; then + goversion=$(GOTOOLCHAIN=local go version | cut -d ' ' -f 3 | sed 's/go*//' | tr -d '\n') + fi + + if [[ $goversion != "" ]] && [[ $($SEMVER compare "v$goversion" v1.21.0) -ge 0 ]]; then + gotoolchain=go${goversion} + else + gotoolchain=go$(grep -E '^go [0-9]{1,}.[0-9]{1,}$' < "$gomod" | cut -d ' ' -f 2 | tr -d '\n').0 + fi + fi + + echo -n "$gotoolchain" +} + +case "$1" in +gotoolchain) + get_gotoolchain + ;; +esac