From 000fa45acaee5cccf4496abb3f469c1fdd411f5f Mon Sep 17 00:00:00 2001 From: Pratham Date: Sat, 5 Oct 2024 17:18:21 +0530 Subject: [PATCH] add makefile target and a script to check if the runtime versions are valid to run prometheus Signed-off-by: Pratham --- Makefile | 5 +++ scripts/check-runtime-versions.sh | 59 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 scripts/check-runtime-versions.sh diff --git a/Makefile b/Makefile index 0b5935de00..4b6b27fd32 100644 --- a/Makefile +++ b/Makefile @@ -192,3 +192,8 @@ update-all-go-deps: $(GO) get -d $$m; \ done @cd ./documentation/examples/remote_storage/ && $(GO) mod tidy + +.PHONY: check-runtime-versions +check-runtime-versions: + @echo ">> checking runtime versions" + @./scripts/check-runtime-versions.sh diff --git a/scripts/check-runtime-versions.sh b/scripts/check-runtime-versions.sh new file mode 100755 index 0000000000..590bbba8fe --- /dev/null +++ b/scripts/check-runtime-versions.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# Required minimum versions. +REQUIRED_GO_VERSION="1.17" +REQUIRED_NODE_VERSION="16.0.0" +REQUIRED_NPM_VERSION="7.0.0" + +# Function to compare versions (checks if version A >= version B). +compare_versions() { + if [ "$1" = "$2" ]; then + return 0 + fi + local IFS=. + local i ver1=($1) ver2=($2) + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do + ver1[i]=0 + done + for ((i=0; i<${#ver1[@]}; i++)); do + if [[ -z ${ver2[i]} ]]; then + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})); then + return 0 + fi + if ((10#${ver1[i]} < 10#${ver2[i]})); then + return 1 + fi + done + return 0 +} + +# Check Go version. +GO_VERSION=$(go version | awk '{print $3}' | sed 's/go//') +if compare_versions "$GO_VERSION" "$REQUIRED_GO_VERSION"; then + echo "Go version $GO_VERSION is OK" +else + echo "Go version $GO_VERSION is too old, required >= $REQUIRED_GO_VERSION" + exit 1 +fi + +# Check Node.js version. +NODE_VERSION=$(node -v | sed 's/v//') +if compare_versions "$NODE_VERSION" "$REQUIRED_NODE_VERSION"; then + echo "Node.js version $NODE_VERSION is OK" +else + echo "Node.js version $NODE_VERSION is too old, required >= $REQUIRED_NODE_VERSION" + exit 1 +fi + +# Check npm version. +NPM_VERSION=$(npm -v) +if compare_versions "$NPM_VERSION" "$REQUIRED_NPM_VERSION"; then + echo "npm version $NPM_VERSION is OK" +else + echo "npm version $NPM_VERSION is too old, required >= $REQUIRED_NPM_VERSION" + exit 1 +fi + +echo "All versions are correct."