From 6926e2c484e75bf17407f89f8200f5d18b34b84c Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 1 Mar 2023 10:47:52 -0800 Subject: [PATCH 1/6] `make` bails on the wrong go version This code: 1. Extracts the required go minor from `go.mod` 2. Gets the current go version from `go version` and normalizes it 3. Checks whether the required go minor is a version prefix for the current go version, and bails if it isn't. --- make.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/make.sh b/make.sh index 60a938426..7e5d3a61a 100755 --- a/make.sh +++ b/make.sh @@ -1,5 +1,19 @@ #!/bin/sh set -eu + +REQUIRED_GO_MINOR=$(sed -En 's/^go[[:space:]]+([[:digit:].]+)$/\1/p' go.mod) +ACTUAL_GO_VERSION=$(go version | sed -n 's/^go version go\([0-9]*\.[0-9]*\.[0-9]*\)\(.*\)/\1/p') + +# We use 'case' instead of '[' to match values against complex patterns, because POSIX +# does not guarantee that '[' supports advanced features like globs and regex. +if case "$ACTUAL_GO_VERSION" in "$REQUIRED_GO_MINOR".*) false ;; *) true ;; esac then + red="\e[0;91m" + reset="\e[0m" + + printf "${red}PROBLEM: You need go %s to build d2, but you have %s installed.${reset}\n" "$REQUIRED_GO_MINOR" "$ACTUAL_GO_VERSION" + exit 1 +fi + if [ ! -e "$(dirname "$0")/ci/sub/.git" ]; then set -x git submodule update --init From 1712b5d8134dd3273866f5428d9d203e014c7c3e Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 1 Mar 2023 12:20:37 -0800 Subject: [PATCH 2/6] Incorporate feedback --- make.sh | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/make.sh b/make.sh index 7e5d3a61a..39364a619 100755 --- a/make.sh +++ b/make.sh @@ -1,19 +1,6 @@ #!/bin/sh set -eu -REQUIRED_GO_MINOR=$(sed -En 's/^go[[:space:]]+([[:digit:].]+)$/\1/p' go.mod) -ACTUAL_GO_VERSION=$(go version | sed -n 's/^go version go\([0-9]*\.[0-9]*\.[0-9]*\)\(.*\)/\1/p') - -# We use 'case' instead of '[' to match values against complex patterns, because POSIX -# does not guarantee that '[' supports advanced features like globs and regex. -if case "$ACTUAL_GO_VERSION" in "$REQUIRED_GO_MINOR".*) false ;; *) true ;; esac then - red="\e[0;91m" - reset="\e[0m" - - printf "${red}PROBLEM: You need go %s to build d2, but you have %s installed.${reset}\n" "$REQUIRED_GO_MINOR" "$ACTUAL_GO_VERSION" - exit 1 -fi - if [ ! -e "$(dirname "$0")/ci/sub/.git" ]; then set -x git submodule update --init @@ -23,4 +10,11 @@ fi PATH="$(cd -- "$(dirname "$0")" && pwd)/ci/sub/bin:$PATH" cd -- "$(dirname "$0")" +GO_VERSION=$(sed -En 's/^go[[:space:]]+([[:digit:].]+)$/\1/p' go.mod) + +if ! $(go version | grep -qF "${GO_VERSION}"); then + printferr "You need go %s to build d2.\n" "$GO_VERSION" + exit 1 +fi + _make "$@" From 07b34118f1d61c585109147279867b9076a380ba Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 1 Mar 2023 12:23:03 -0800 Subject: [PATCH 3/6] Reduce delta --- make.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/make.sh b/make.sh index 39364a619..4d0b2d2d4 100755 --- a/make.sh +++ b/make.sh @@ -1,6 +1,5 @@ #!/bin/sh set -eu - if [ ! -e "$(dirname "$0")/ci/sub/.git" ]; then set -x git submodule update --init From 4d3762994024865c330f9ee62c3afc44beb1b796 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 2 Mar 2023 10:43:03 -0800 Subject: [PATCH 4/6] Address comments --- make.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/make.sh b/make.sh index 4d0b2d2d4..ed9353b1d 100755 --- a/make.sh +++ b/make.sh @@ -9,10 +9,8 @@ fi PATH="$(cd -- "$(dirname "$0")" && pwd)/ci/sub/bin:$PATH" cd -- "$(dirname "$0")" -GO_VERSION=$(sed -En 's/^go[[:space:]]+([[:digit:].]+)$/\1/p' go.mod) - -if ! $(go version | grep -qF "${GO_VERSION}"); then - printferr "You need go %s to build d2.\n" "$GO_VERSION" +if ! $(go version | grep -qF "1.18."); then + printferr "You need go 1.18 to build d2.\n" exit 1 fi From de52064d9f7775679cf080574d4895a743c84931 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 3 Mar 2023 08:04:47 -0800 Subject: [PATCH 5/6] Update make.sh Co-authored-by: Anmol Sethi --- make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.sh b/make.sh index ed9353b1d..127d7a570 100755 --- a/make.sh +++ b/make.sh @@ -9,7 +9,7 @@ fi PATH="$(cd -- "$(dirname "$0")" && pwd)/ci/sub/bin:$PATH" cd -- "$(dirname "$0")" -if ! $(go version | grep -qF "1.18."); then +if ! go version | grep -qF '1.18'; then printferr "You need go 1.18 to build d2.\n" exit 1 fi From ff3f6784c23c0f91bc7c23d453e5e9620a0dae27 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 3 Mar 2023 08:04:56 -0800 Subject: [PATCH 6/6] Update make.sh Co-authored-by: Anmol Sethi --- make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.sh b/make.sh index 127d7a570..0bf643e7c 100755 --- a/make.sh +++ b/make.sh @@ -10,7 +10,7 @@ PATH="$(cd -- "$(dirname "$0")" && pwd)/ci/sub/bin:$PATH" cd -- "$(dirname "$0")" if ! go version | grep -qF '1.18'; then - printferr "You need go 1.18 to build d2.\n" + echoerr "You need go 1.18 to build d2." exit 1 fi