add makefile target and a script to check if the runtime versions are valid to run prometheus

Signed-off-by: Pratham <prathamjagga123@gmail.com>
This commit is contained in:
Pratham 2024-10-05 17:18:21 +05:30
parent a1c2f59bc5
commit 000fa45aca
No known key found for this signature in database
GPG key ID: CD1526A154BDB12F
2 changed files with 64 additions and 0 deletions

View file

@ -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

View file

@ -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."