chore: add Makefile target to check Node.js version (#16832)

This helps reduce confusion when UI-related targets fail without
directly indicating a version mismatch.

Automatically runs during UI builds and tests. The check is only
indicative.

The "go" binary can hard stop and print relevant messages on its
own for mismatches, thus not covered here.

supersedes https://github.com/prometheus/prometheus/pull/15106

Signed-off-by: machine424 <ayoubmrini424@gmail.com>
Co-authored-by: Pratham <prathamjagga123@gmail.com>
This commit is contained in:
Ayoub Mrini 2025-07-15 11:52:43 +01:00 committed by GitHub
parent 0fc5e75504
commit 0f0cd5c2cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -81,7 +81,7 @@ ui-lint:
.PHONY: assets
ifndef SKIP_UI_BUILD
assets: ui-install ui-build
assets: check-node-version ui-install ui-build
.PHONY: npm_licenses
npm_licenses: ui-install
@ -143,7 +143,7 @@ install-goyacc:
ifeq ($(GO_ONLY),1)
test: common-test check-go-mod-version
else
test: check-generated-parser common-test ui-build-module ui-test ui-lint check-go-mod-version
test: check-generated-parser common-test check-node-version ui-build-module ui-test ui-lint check-go-mod-version
endif
.PHONY: tarball
@ -192,3 +192,7 @@ update-all-go-deps:
$(GO) get $$m; \
done
@cd ./documentation/examples/remote_storage/ && $(GO) mod tidy
.PHONY: check-node-version
check-node-version:
@./scripts/check-node-version.sh

11
scripts/check-node-version.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
YELLOW='\033[0;33m'
NC='\033[0m'
MIN_NODE_VERSION=$(cat web/ui/.nvmrc | sed 's/v//')
CURRENT_NODE_VERSION=$(node --version | sed 's/v//')
if [ "$(echo -e "$CURRENT_NODE_VERSION\n$MIN_NODE_VERSION" | sort -V | head -n 1)" != "$MIN_NODE_VERSION" ]; then
printf "${YELLOW}Warning:${NC}: Node.js version mismatch! Required minimum: $MIN_NODE_VERSION Installed version: $CURRENT_NODE_VERSION\n"
fi