@@ -11,15 +11,22 @@ TEST_REPORTS_DIR ?= test-reports
1111GOTESTSUM_FORMAT ?= testname
1212VERSION ?= dev-build
1313LOCAL ?=
14- DEBUG ?=
14+
15+ # Detect where 'go install' will place binaries. Prefer GOBIN, then GOPATH/bin, then default to $(shell go env GOBIN) or $(shell go env GOPATH)/bin
16+ # Set AIR_BIN to that path plus '/air' so make can invoke it directly without relying on PATH.
17+ GOBIN ?= $(shell go env GOBIN)
18+ GOPATH ?= $(shell go env GOPATH)
19+ DEFAULT_GOBIN := $(if $(strip $(GOBIN ) ) ,$(GOBIN ) ,$(if $(strip $(GOPATH ) ) ,$(GOPATH ) /bin,) )
20+ AIR_BIN ?= $(if $(strip $(DEFAULT_GOBIN ) ) ,$(DEFAULT_GOBIN ) /air,air)
21+ GOTESTSUM_BIN := $(if $(strip $(DEFAULT_GOBIN ) ) ,$(DEFAULT_GOBIN ) /gotestsum,$(shell which gotestsum 2>/dev/null || echo gotestsum) )
1522
1623# Colors for output
17- RED =\033[0;31m
18- GREEN =\033[0;32m
19- YELLOW =\033[1;33m
20- BLUE =\033[0;34m
21- CYAN =\033[0;36m
22- NC =\033[0m # No Color
24+ RED =$( shell printf ' \033[0;31m')
25+ GREEN =$( shell printf ' \033[0;32m')
26+ YELLOW =$( shell printf ' \033[1;33m')
27+ BLUE =$( shell printf ' \033[0;34m')
28+ CYAN =$( shell printf ' \033[0;36m')
29+ NC =$( shell printf ' \033[0m')
2330
2431# Include deployment recipes
2532include recipes/fly.mk
@@ -56,24 +63,54 @@ cleanup-enterprise: ## Clean up enterprise directories if present
5663 @echo " $( GREEN) Enterprise cleaned up$( NC) "
5764
5865install-ui : cleanup-enterprise
66+ # Do not run install-ui as root on developer machines - this causes global npm installs to fail (Nix, etc.)
67+ @if [ -z " $$ CI" ] && [ -z " $$ GITHUB_ACTIONS" ] && [ " $$ (id -u)" -eq 0 ]; then \
68+ echo " $( RED) Error: Running 'make' as root is not supported for local development. Run as your user (without sudo).$( NC) " ; \
69+ exit 1; \
70+ fi
5971 @which node > /dev/null || (echo " $( RED) Error: Node.js is not installed. Please install Node.js first.$( NC) " && exit 1)
6072 @which npm > /dev/null || (echo " $( RED) Error: npm is not installed. Please install npm first.$( NC) " && exit 1)
6173 @echo " $( GREEN) Node.js and npm are installed$( NC) "
6274 @cd ui && npm install
63- @which next > /dev/null || (echo " $( YELLOW) Installing nextjs...$( NC) " && npm install -g next)
75+ # Prefer a local next installation (works on systems without global npm dirs, e.g. Nix)
76+ @cd ui && \
77+ if [ -x " ./node_modules/.bin/next" ]; then \
78+ echo " $( GREEN) next is available locally in ui/node_modules/.bin$( NC) " ; \
79+ elif which npx > /dev/null 2>&1 ; then \
80+ echo " $( YELLOW) Installing next locally using npm...$( NC) " ; \
81+ npm --prefix . install next || true ; \
82+ else \
83+ echo " $( YELLOW) npx not found and local next missing; attempting global install (may fail on Nix)...$( NC) " ; \
84+ npm install -g next || true ; \
85+ fi
6486 @echo " $( GREEN) UI deps are in sync$( NC) "
6587
6688install-air : # # Install air for hot reloading (if not already installed)
67- @which air > /dev/null || (echo " $( YELLOW) Installing air for hot reloading...$( NC) " && go install github.com/air-verse/air@latest)
68- @echo " $( GREEN) Air is ready$( NC) "
69-
70- install-delve : # # Install delve for debugging (if not already installed)
71- @which dlv > /dev/null || (echo " $( YELLOW) Installing delve for debugging...$( NC) " && go install github.com/go-delve/delve/cmd/dlv@latest)
72- @echo " $( GREEN) Delve is ready$( NC) "
89+ @echo " $( YELLOW) Checking for air binary...$( NC) "
90+ @if [ -x " $( AIR_BIN) " ]; then \
91+ echo " $( GREEN) air is available at: $( AIR_BIN) $( NC) " ; \
92+ else \
93+ echo " $( YELLOW) Installing air for hot reloading...$( NC) " ; \
94+ go install github.com/air-verse/air@latest; \
95+ INSTALLED=$$(if [ -n "$(GOBIN ) " ]; then echo "$(GOBIN ) /air"; elif [ -n "$(GOPATH ) " ]; then echo "$(GOPATH ) /bin/air"; else echo "$$(go env GOBIN ) /air"; fi) ; \
96+ echo " $( GREEN) air installed (expected path: $$ INSTALLED)$( NC) " ; \
97+ if ! which $$ INSTALLED > /dev/null 2>&1 && [ ! -x " $$ INSTALLED" ]; then \
98+ echo " $( YELLOW) Note: the installed air binary may not be on your PATH. Add its directory to PATH to run 'make dev' without errors.$( NC) " ; \
99+ fi ; \
100+ fi
73101
74102install-gotestsum : # # Install gotestsum for test reporting (if not already installed)
75- @which gotestsum > /dev/null || (echo " $( YELLOW) Installing gotestsum for test reporting...$( NC) " && go install gotest.tools/gotestsum@latest)
76- @echo " $( GREEN) gotestsum is ready$( NC) "
103+ @if [ -x " $( GOTESTSUM_BIN) " ] || which $(GOTESTSUM_BIN ) > /dev/null 2>&1 ; then \
104+ echo " $( GREEN) gotestsum is available at: $( GOTESTSUM_BIN) $( NC) " ; \
105+ else \
106+ echo " $( YELLOW) Installing gotestsum for test reporting...$( NC) " ; \
107+ go install gotest.tools/gotestsum@latest; \
108+ INSTALLED=$$(if [ -n "$(GOBIN ) " ]; then echo "$(GOBIN ) /gotestsum"; elif [ -n "$(GOPATH ) " ]; then echo "$(GOPATH ) /bin/gotestsum"; else echo "$$(go env GOBIN ) /gotestsum"; fi) ; \
109+ echo " $( GREEN) gotestsum installed (expected path: $$ INSTALLED)$( NC) " ; \
110+ if ! which $$ INSTALLED > /dev/null 2>&1 && [ ! -x " $$ INSTALLED" ]; then \
111+ echo " $( YELLOW) Note: the installed gotestsum binary may not be on your PATH. Add its directory to PATH to run 'make test' without errors or run tests via $( GOTESTSUM_BIN) $( NC) " ; \
112+ fi ; \
113+ fi
77114
78115install-junit-viewer : # # Install junit-viewer for HTML report generation (if not already installed)
79116 @if [ -z " $$ CI" ] && [ -z " $$ GITHUB_ACTIONS" ] && [ -z " $$ GITLAB_CI" ] && [ -z " $$ CIRCLECI" ] && [ -z " $$ JENKINS_HOME" ]; then \
@@ -115,15 +152,15 @@ dev: install-ui install-air setup-workspace $(if $(DEBUG),install-delve) ## Star
115152 if [ -n " $( DEBUG) " ]; then \
116153 echo " $( CYAN) Starting with air + delve debugger on port 2345...$( NC) " ; \
117154 echo " $( YELLOW) Attach your debugger to localhost:2345$( NC) " ; \
118- cd transports/bifrost-http && BIFROST_UI_DEV=true air -c .air.debug.toml -- \
119- -host " $( HOST) " \
120- -port " $( PORT) " \
121- -log-style " $( LOG_STYLE) " \
122- -log-level " $( LOG_LEVEL) " \
123- $(if $(PROMETHEUS_LABELS ) ,-prometheus-labels "$(PROMETHEUS_LABELS ) ") \
155+ cd transports/bifrost-http && BIFROST_UI_DEV=true $( AIR_BIN ) -c .air.debug.toml -- \
156+ -host " $( HOST) " \
157+ -port " $( PORT) " \
158+ -log-style " $( LOG_STYLE) " \
159+ -log-level " $( LOG_LEVEL) " \
160+ $(if $(PROMETHEUS_LABELS ) ,-prometheus-labels "$(PROMETHEUS_LABELS ) ") \
124161 $(if $(APP_DIR ) ,-app-dir "$(APP_DIR ) ") ; \
125162 else \
126- cd transports/bifrost-http && BIFROST_UI_DEV=true air -c .air.toml -- \
163+ cd transports/bifrost-http && BIFROST_UI_DEV=true $( AIR_BIN ) -c .air.toml -- \
127164 -host " $( HOST) " \
128165 -port " $( PORT) " \
129166 -log-style " $( LOG_STYLE) " \
@@ -309,7 +346,7 @@ generate-html-reports: ## Convert existing XML reports to HTML
309346test : install-gotestsum # # Run tests for bifrost-http
310347 @echo " $( GREEN) Running bifrost-http tests...$( NC) "
311348 @mkdir -p $(TEST_REPORTS_DIR )
312- @cd transports/bifrost-http && GOWORK=off gotestsum \
349+ @cd transports/bifrost-http && GOWORK=off $( GOTESTSUM_BIN ) \
313350 --format=$(GOTESTSUM_FORMAT ) \
314351 --junitfile=../../$(TEST_REPORTS_DIR ) /bifrost-http.xml \
315352 -- -v ./...
@@ -361,7 +398,7 @@ test-core: install-gotestsum ## Run core tests (Usage: make test-core PROVIDER=o
361398 CLEAN_TESTCASE=$$(echo "$$CLEAN_TESTCASE" | sed 's|^Test[A-Z][A-Za-z]*/[A-Z][A-Za-z]*Tests/||' ) ; \
362399 echo " $( CYAN) Running Test$$ {PROVIDER_TEST_NAME}/$$ {PROVIDER_TEST_NAME}Tests/$$ CLEAN_TESTCASE...$( NC) " ; \
363400 REPORT_FILE=" $( TEST_REPORTS_DIR) /core-$( PROVIDER) -$$ (echo $$ CLEAN_TESTCASE | sed 's|/|_|g').xml" ; \
364- cd core/providers/$(PROVIDER ) && GOWORK=off gotestsum \
401+ cd core/providers/$(PROVIDER ) && GOWORK=off $( GOTESTSUM_BIN ) \
365402 --format=$(GOTESTSUM_FORMAT ) \
366403 --junitfile=../../../$$ REPORT_FILE \
367404 -- -v -run " ^Test$$ {PROVIDER_TEST_NAME}$$ /.*Tests/$$ CLEAN_TESTCASE$$ " || TEST_FAILED=1; \
@@ -385,7 +422,7 @@ test-core: install-gotestsum ## Run core tests (Usage: make test-core PROVIDER=o
385422 else \
386423 echo " $( CYAN) Running Test$$ {PROVIDER_TEST_NAME}...$( NC) " ; \
387424 REPORT_FILE=" $( TEST_REPORTS_DIR) /core-$( PROVIDER) .xml" ; \
388- cd core/providers/$(PROVIDER ) && GOWORK=off gotestsum \
425+ cd core/providers/$(PROVIDER ) && GOWORK=off $( GOTESTSUM_BIN ) \
389426 --format=$(GOTESTSUM_FORMAT ) \
390427 --junitfile=../../../$$ REPORT_FILE \
391428 -- -v -run " ^Test$$ {PROVIDER_TEST_NAME}$$ " || TEST_FAILED=1; \
@@ -414,7 +451,7 @@ test-core: install-gotestsum ## Run core tests (Usage: make test-core PROVIDER=o
414451 exit 1; \
415452 fi ; \
416453 REPORT_FILE=" $( TEST_REPORTS_DIR) /core-all.xml" ; \
417- cd core && GOWORK=off gotestsum \
454+ cd core && GOWORK=off $( GOTESTSUM_BIN ) \
418455 --format=$(GOTESTSUM_FORMAT ) \
419456 --junitfile=../$$ REPORT_FILE \
420457 -- -v ./providers/... || TEST_FAILED=1; \
@@ -508,7 +545,7 @@ test-plugins: install-gotestsum ## Run plugin tests
508545 for dir in $$ (find . -name " *_test.go" -exec dirname {} \; | sort -u); do \
509546 plugin_name=$$(echo $$dir | sed 's|^\./||' | sed 's|/|-|g' ) ; \
510547 echo " Testing $$ dir..." ; \
511- cd $$ dir && gotestsum \
548+ cd $$ dir && $( GOTESTSUM_BIN ) \
512549 --format=$(GOTESTSUM_FORMAT ) \
513550 --junitfile=../../$(TEST_REPORTS_DIR ) /plugin-$$ plugin_name.xml \
514551 -- -v ./... && cd - > /dev/null; \
0 commit comments