Skip to content

Commit

Permalink
feat: check go and node versions at build time. node version is pinne…
Browse files Browse the repository at this point in the history
…d, but ensure only minimal Go version
  • Loading branch information
eliziario committed Mar 21, 2023
1 parent c033fe7 commit 4f554e8
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions scripts/versions_check.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail # Bash "strict mode"

GO_VERSION=1.18
# VERSION NUMBERS
# FOR GO WE EXPECT _AT LEAST_ THIS VERSION, BUT WE ARE OK WITH SUPERIOR VERSIONS
GO_VERSION=1.20rc3

# FOR NODE, WE PIN THE EXACT VERSION NUMBER
NODE_VERSION=16.14.0


RED_BG=$(tput setab 1)
BLUE_BG=$(tput setab 4)
WHITE_FG=$(tput setaf 7)
NORMAL_BG=$(tput sgr0;)
BOLD=$(tput bold)
error=false;

echo " "

function parse_semver() {
local token="$1"
local major=0
local minor=0
local patch=0

if egrep '^[0-9]+\.[0-9]+(\.[0-9]+)?' <<<"${token}" >/dev/null 2>&1 ; then
# It has the correct syntax.
local n=${token//[!0-9]/ }
local a=(${n//\./ })
fi

echo "${a[@]}"
}

function compare_versions() {
local expected=($(parse_semver "$1"))
local found=($(parse_semver "$2"))
local len=${#expected[@]}
for (( i=0; i<len; i++ )) ; do
if ! [ "${expected[$i]}" == "${found[$i]}" ]; then
echo 1
fi
done
}
echo "${BLUE_BG}${WHITE_FG}${BOLD}Starting Kurtosis Build... ${NORMAL_BG}"

check_node_version() {
if [ -f ~/.nvm/nvm.sh ]; then
Expand All @@ -59,15 +40,27 @@ check_node_version() {
echo "${RED_BG}${WHITE_FG}nvm install "${NODE_VERSION}" ${NORMAL_BG}"
echo ""
error=true
else
echo "${BLUE_BG}${WHITE_FG}${BOLD}Node version "${GO_VERSION}" found. ok ${NORMAL_BG}"
fi
}

version_lte() {
if [ "$1" = "$2" ]; then
echo 1
return;
fi
$(printf '%s\n%s' "$1" "$2" | sort -C -V -u) && echo 1 || echo 0
}

check_go_version() {
local version=$(go version | { read -r _ _ v _; echo "${v#go}"; })
local result="$(compare_versions ${GO_VERSION} "${version}")"
if [ "$result" == 1 ]; then
if [ "$(version_lte "${GO_VERSION}" "${version}")" != 1 ]; then
echo "${RED_BG}${WHITE_FG}${BOLD}GO "${GO_VERSION}" not installed. Found ${version} ${NORMAL_BG}"
error=true
else
echo "${BLUE_BG}${WHITE_FG}${BOLD}Minimum GO version "${GO_VERSION}" expected. Found ${version} ... ok ${NORMAL_BG}"

fi
}

Expand All @@ -79,7 +72,7 @@ if "$error"; then
exit 1
fi

nvm use $NODE_VERSION
nvm use $NODE_VERSION &> /dev/null



0 comments on commit 4f554e8

Please sign in to comment.