From 0f0cd5c2cfee4eb8ab5186ac41e9f32dca93f654 Mon Sep 17 00:00:00 2001 From: Ayoub Mrini Date: Tue, 15 Jul 2025 11:52:43 +0100 Subject: [PATCH] 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 Co-authored-by: Pratham --- Makefile | 8 ++++++-- scripts/check-node-version.sh | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100755 scripts/check-node-version.sh diff --git a/Makefile b/Makefile index beff8c4a80..ccae1ddfdb 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/scripts/check-node-version.sh b/scripts/check-node-version.sh new file mode 100755 index 0000000000..1c5d71c23a --- /dev/null +++ b/scripts/check-node-version.sh @@ -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