From cba26c92f566eab65435ead2cf7ad06bcde74134 Mon Sep 17 00:00:00 2001 From: Joshua Casey Date: Fri, 10 May 2024 13:12:00 -0500 Subject: [PATCH] Remove with_modules from hack/module.sh --- hack/module.sh | 57 +++++++++++++------------------------------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/hack/module.sh b/hack/module.sh index d4843f567..17f83976b 100755 --- a/hack/module.sh +++ b/hack/module.sh @@ -7,43 +7,6 @@ set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -function tidy_cmd() { - local version="$(cat "${ROOT}/go.mod" | grep '^go ' | cut -f 2 -d ' ')" - echo "go mod tidy -v -go=${version} -compat=${version}" -} - -function test_cmd() { - echo "go test -count 1 -race ./..." -} - -function unittest_cmd() { - echo "go test -short -race ./..." -} - -function with_modules() { - local cmd_function="${1}" - cmd="$(${cmd_function})" - - # start the cache mutation detector by default so that cache mutators will be found - local kube_cache_mutation_detector="${KUBE_CACHE_MUTATION_DETECTOR:-true}" - - # panic the server on watch decode errors since they are considered coder mistakes - local kube_panic_watch_decode_error="${KUBE_PANIC_WATCH_DECODE_ERROR:-true}" - - env_vars="KUBE_CACHE_MUTATION_DETECTOR=${kube_cache_mutation_detector} KUBE_PANIC_WATCH_DECODE_ERROR=${kube_panic_watch_decode_error}" - - pushd "${ROOT}" >/dev/null - for mod_file in $(find . -maxdepth 4 -not -path "./generated/*" -name go.mod | sort); do - mod_dir="$(dirname "${mod_file}")" - ( - echo "=> " - echo " cd ${mod_dir} && ${env_vars} ${cmd}" - cd "${mod_dir}" && env ${env_vars} ${cmd} - ) - done - popd >/dev/null -} - function usage() { echo "Error: must be specified" echo " module.sh [tidy, lint, test, unittest]" @@ -51,9 +14,18 @@ function usage() { } function main() { + pushd "${ROOT}" > /dev/null + + # start the cache mutation detector by default so that cache mutators will be found + local kube_cache_mutation_detector="${KUBE_CACHE_MUTATION_DETECTOR:-true}" + + # panic the server on watch decode errors since they are considered coder mistakes + local kube_panic_watch_decode_error="${KUBE_PANIC_WATCH_DECODE_ERROR:-true}" + case "${1:-invalid}" in 'tidy') - with_modules 'tidy_cmd' + local version="$(cat "${ROOT}/go.mod" | grep '^go ' | cut -f 2 -d ' ')" + go mod tidy -v -go=${version} -compat=${version} ;; 'lint' | 'linter' | 'linters') golangci-lint --version @@ -73,11 +45,10 @@ function main() { golangci/golangci-lint:$lint_version \ ./hack/module.sh lint ;; - 'test' | 'tests') - with_modules 'test_cmd' - ;; 'unittest' | 'unittests' | 'units' | 'unit') - with_modules 'unittest_cmd' + KUBE_CACHE_MUTATION_DETECTOR=${kube_cache_mutation_detector} \ + KUBE_PANIC_WATCH_DECODE_ERROR=${kube_panic_watch_decode_error} \ + go test -short -race ./... ;; *) usage @@ -86,6 +57,8 @@ function main() { echo "=> " echo " \"module.sh $1\" Finished successfully." + + popd > /dev/null } main "$@"