diff --git a/Makefile-modules.mk b/Makefile-modules.mk index 0c951fb0c..4ab29c1e4 100644 --- a/Makefile-modules.mk +++ b/Makefile-modules.mk @@ -4,8 +4,8 @@ MYGOBIN = $(shell go env GOPATH)/bin endif export PATH := $(MYGOBIN):$(PATH) -export KUSTOMIZE_ROOT=$(shell pwd | sed 's|kustomize/.*|kustomize/|') - +# only set this if not already set, so importing makefiles can override it +export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize).*|\1|') include $(KUSTOMIZE_ROOT)/Makefile-tools.mk .PHONY: lint test fix fmt tidy vet diff --git a/hack/for-each-module.sh b/hack/for-each-module.sh index 17cb38499..e1b975615 100755 --- a/hack/for-each-module.sh +++ b/hack/for-each-module.sh @@ -15,8 +15,10 @@ fi cmd=$1 -seen="" -kustomize_root=$(pwd | sed 's|kustomize/.*|kustomize/|') +seen=() +# Hack scripts must be run from the root of the repository. +KUSTOMIZE_ROOT=$(pwd) +export KUSTOMIZE_ROOT # verify all modules pass validation for i in $(find . -name go.mod -not -path "./site/*"); do @@ -25,18 +27,25 @@ for i in $(find . -name go.mod -not -path "./site/*"); do set +x dir=$(pwd) - module="${dir#$kustomize_root}" + module="${dir#$KUSTOMIZE_ROOT}" echo -e "\n----------------------------------------------------------" echo "Running command in $module" echo -e "----------------------------------------------------------" set -x bash -c "$cmd" - seen+=" - $module\n" + seen+=("$module") popd done set +x echo -e "\n\n----------------------------------------------------------" echo -e "SUCCESS: Ran '$cmd' on the following modules:" -echo -e "$seen" +printf " - %s\n" "${seen[@]}" + +EXPECTED_MODULE_COUNT=44 +if [[ "${#seen[@]}" -ne $EXPECTED_MODULE_COUNT ]]; then + echo + echo "SANITY CHECK FAILURE: Expected to see $EXPECTED_MODULE_COUNT modules, but saw ${#seen[@]}" + exit 1 +fi diff --git a/kustomize/Makefile b/kustomize/Makefile deleted file mode 120000 index d2f92ca51..000000000 --- a/kustomize/Makefile +++ /dev/null @@ -1 +0,0 @@ -../Makefile-modules.mk \ No newline at end of file diff --git a/kustomize/Makefile b/kustomize/Makefile new file mode 100644 index 000000000..266eb4a6f --- /dev/null +++ b/kustomize/Makefile @@ -0,0 +1,3 @@ +export KUSTOMIZE_ROOT=$(shell cd .. && pwd) + +include ../Makefile-modules.mk