From efe34da2bfa6a9929b03915088db7c65f7440244 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Mon, 19 Aug 2024 08:54:35 -0500 Subject: [PATCH] fix(build): use goversion to pull correct toolchain image Signed-off-by: Artur Troian --- .envrc | 99 +++++++++++++++++++++++++++-------------------- make/releasing.mk | 2 +- script/tools.sh | 11 ++++++ 3 files changed, 68 insertions(+), 44 deletions(-) diff --git a/.envrc b/.envrc index 8134cbe9..ca83ffaa 100644 --- a/.envrc +++ b/.envrc @@ -2,15 +2,15 @@ direnv_version_major=$(direnv version | cut -d "." -f1 | tr -d '\n') direnv_version_minor=$(direnv version | cut -d "." -f2 | tr -d '\n') if [[ $direnv_version_major -lt 2 ]] || [[ $direnv_version_major -eq 2 ]] && [[ $direnv_version_minor -lt 32 ]]; then - echo -e "\033[31munsupported direnv version $(direnv version) < 2.32.x" - exit 1 + echo -e "\033[31munsupported direnv version $(direnv version) < 2.32.x" + exit 1 fi if [[ "$SHELL" == "bash" ]]; then - if [ "${BASH_VERSINFO:-0}" -lt 4 ]; then - echo -e "\033[31mthe environment needs BASH 4 or above" >&2 - exit 1 - fi + if [ "${BASH_VERSINFO:-0}" -lt 4 ]; then + echo -e "\033[31mthe environment needs BASH 4 or above" >&2 + exit 1 + fi fi AP_ROOT=$(pwd) @@ -21,40 +21,48 @@ dotenv_if_exists dev.env path="$AP_DEVCACHE_NODE_BIN:$AP_DEVCACHE_BIN" -if ! has make ; then - echo -e "\033[31mmake is not installed"; exit 1 +if ! has make; then + echo -e "\033[31mmake is not installed" + exit 1 fi -if ! has go ; then - echo -e "\033[31mgo is not installed"; exit 1 +if ! has go; then + echo -e "\033[31mgo is not installed" + exit 1 fi -if ! has kind ; then +if ! has kind; then echo "kind is not installed. dev environment will try to install it" fi -if ! has unzip ; then - echo -e "\033[31munzip is not installed"; exit 1 +if ! has unzip; then + echo -e "\033[31munzip is not installed" + exit 1 fi -if ! has wget ; then - echo -e "\033[31mwget is not installed"; exit 1 +if ! has wget; then + echo -e "\033[31mwget is not installed" + exit 1 fi -if ! has curl ; then - echo -e "\033[31mcurl is not installed"; exit 1 +if ! has curl; then + echo -e "\033[31mcurl is not installed" + exit 1 fi -if ! has npm ; then - echo -e "\033[31mnpm is not installed"; exit 1 +if ! has npm; then + echo -e "\033[31mnpm is not installed" + exit 1 fi -if ! has jq ; then - echo -e "\033[31mjq is not installed"; exit 1 +if ! has jq; then + echo -e "\033[31mjq is not installed" + exit 1 fi -if ! has readlink ; then - echo -e "\033[31mreadlink is not installed"; exit 1 +if ! has readlink; then + echo -e "\033[31mreadlink is not installed" + exit 1 fi TOOLS=${AP_ROOT}/script/tools.sh @@ -63,37 +71,40 @@ SEMVER=${AP_ROOT}/script/semver.sh GOTOOLCHAIN=$(${TOOLS} gotoolchain) GOTOOLCHAIN_SEMVER=$(echo "${GOTOOLCHAIN}" | sed 's/go*/v/' | tr -d '\n') +GOVERSION=$(${TOOLS} goversion) +GOVERSION_SEMVER=$(echo "${GOVERSION}" | sed 's/go*/v/' | tr -d '\n') + AKASH_DIRENV_SET=1 if [[ "$OSTYPE" == "darwin"* ]]; then - # on MacOS disable deprecation warnings security framework - CGO_CFLAGS=-Wno-deprecated-declarations + # on MacOS disable deprecation warnings security framework + CGO_CFLAGS=-Wno-deprecated-declarations - export CGO_CFLAGS + export CGO_CFLAGS - if ! has brew; then - echo -e "\033[31mhomebrew is not installed. visit https://brew.sh" - exit 1 - fi + if ! has brew; then + echo -e "\033[31mhomebrew is not installed. visit https://brew.sh" + exit 1 + fi - if [[ -z $HOMEBREW_PREFIX ]]; then - HOMEBREW_PREFIX=$(brew --prefix) - fi + if [[ -z $HOMEBREW_PREFIX ]]; then + HOMEBREW_PREFIX=$(brew --prefix) + fi - # don't use brew list, as it is utterly slow - getopt_bin=${HOMEBREW_PREFIX}/opt/gnu-getopt/bin + # don't use brew list, as it is utterly slow + getopt_bin=${HOMEBREW_PREFIX}/opt/gnu-getopt/bin - if [ ! -d "$getopt_bin" ]; then - echo -e "\033[31mgnu-getopt is not installed. to install \"brew install gnu-getopt\"" - exit 1 - else - path=$path:"$getopt_bin" - fi + if [ ! -d "$getopt_bin" ]; then + echo -e "\033[31mgnu-getopt is not installed. to install \"brew install gnu-getopt\"" + exit 1 + else + path=$path:"$getopt_bin" + fi fi if [[ -z "$GOPATH" ]]; then - GOPATH=$(go env GOPATH) - export GOPATH + GOPATH=$(go env GOPATH) + export GOPATH fi PATH_add "$path" @@ -104,6 +115,8 @@ AKASH=$AP_DEVCACHE_BIN/akash export SEMVER export GOTOOLCHAIN export GOTOOLCHAIN_SEMVER +export GOVERSION +export GOVERSION_SEMVER PATH_add "$path" diff --git a/make/releasing.mk b/make/releasing.mk index b842b194..b5ce38c1 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:$(GOTOOLCHAIN_SEMVER) +GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:$(GOVERSION_SEMVER) GORELEASER_MOUNT_CONFIG ?= false GORELEASER_SKIP_FLAGS := $(GORELEASER_SKIP) diff --git a/script/tools.sh b/script/tools.sh index 8b355b67..490a0555 100755 --- a/script/tools.sh +++ b/script/tools.sh @@ -40,6 +40,14 @@ function get_gotoolchain() { echo -n "$gotoolchain" } +function get_goversion() { + local goversion + + goversion=$(go list -mod=readonly -f '{{ .Module.GoVersion }}') + + echo -n "go$goversion" +} + function build_akash() { dev_cache=${AP_DEVCACHE_BIN} cd "$1" || exit 1 @@ -80,6 +88,9 @@ case "$1" in gotoolchain) get_gotoolchain ;; + goversion) + get_goversion + ;; build-akash) shift build_akash "$@"