2020-08-01 00:09:05 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-08-21 23:15:48 +00:00
|
|
|
|
2021-05-28 14:52:49 +00:00
|
|
|
# Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
|
2020-08-25 01:07:34 +00:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2020-08-01 00:09:05 +00:00
|
|
|
set -euo pipefail
|
2020-08-21 23:15:48 +00:00
|
|
|
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
2020-08-01 00:09:05 +00:00
|
|
|
|
|
|
|
function tidy_cmd() {
|
2020-08-07 00:30:18 +00:00
|
|
|
echo 'go mod tidy -v'
|
2020-08-01 00:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function lint_cmd() {
|
2020-12-17 22:30:34 +00:00
|
|
|
echo "golangci-lint run --modules-download-mode=readonly --timeout=10m"
|
2020-08-01 00:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_cmd() {
|
|
|
|
if [ -x "$(command -v gotest)" ]; then
|
|
|
|
cmd='gotest'
|
|
|
|
else
|
|
|
|
cmd='go test'
|
|
|
|
fi
|
2020-08-21 23:15:48 +00:00
|
|
|
echo "${cmd} -count 1 -race ./..."
|
2020-08-01 00:09:05 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 01:44:14 +00:00
|
|
|
function unittest_cmd() {
|
|
|
|
if [ -x "$(command -v gotest)" ]; then
|
|
|
|
cmd='gotest'
|
|
|
|
else
|
|
|
|
cmd='go test'
|
|
|
|
fi
|
2020-09-18 22:58:22 +00:00
|
|
|
echo "${cmd} -short -race ./..."
|
2020-08-07 01:44:14 +00:00
|
|
|
}
|
|
|
|
|
2020-08-01 00:09:05 +00:00
|
|
|
function with_modules() {
|
|
|
|
local cmd_function="${1}"
|
|
|
|
cmd="$(${cmd_function})"
|
|
|
|
|
2020-10-03 02:40:23 +00:00
|
|
|
# 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}"
|
|
|
|
|
2020-08-21 23:15:48 +00:00
|
|
|
pushd "${ROOT}" >/dev/null
|
2021-08-17 13:53:22 +00:00
|
|
|
for mod_file in $(find . -maxdepth 4 -not -path "./generated/*" -name go.mod | sort); do
|
2020-08-01 00:09:05 +00:00
|
|
|
mod_dir="$(dirname "${mod_file}")"
|
|
|
|
(
|
2020-08-14 22:58:50 +00:00
|
|
|
echo "=> "
|
2020-10-03 02:40:23 +00:00
|
|
|
echo " cd ${mod_dir} && ${env_vars} ${cmd}"
|
|
|
|
cd "${mod_dir}" && env ${env_vars} ${cmd}
|
2020-08-01 00:09:05 +00:00
|
|
|
)
|
|
|
|
done
|
2020-08-21 23:15:48 +00:00
|
|
|
popd >/dev/null
|
2020-08-01 00:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "Error: <task> must be specified"
|
2020-08-24 19:09:35 +00:00
|
|
|
echo " module.sh <task> [tidy, lint, test, unittest]"
|
2020-08-01 00:09:05 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
case "${1:-invalid}" in
|
2020-08-21 23:15:48 +00:00
|
|
|
'tidy')
|
|
|
|
with_modules 'tidy_cmd'
|
|
|
|
;;
|
|
|
|
'lint' | 'linter' | 'linters')
|
|
|
|
with_modules 'lint_cmd'
|
|
|
|
;;
|
|
|
|
'test' | 'tests')
|
|
|
|
with_modules 'test_cmd'
|
|
|
|
;;
|
|
|
|
'unittest' | 'unittests' | 'units' | 'unit')
|
|
|
|
with_modules 'unittest_cmd'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
2020-08-01 00:09:05 +00:00
|
|
|
esac
|
2020-08-21 23:15:48 +00:00
|
|
|
|
|
|
|
echo "=> "
|
|
|
|
echo " \"module.sh $1\" Finished successfully."
|
2020-08-01 00:09:05 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 21:19:29 +00:00
|
|
|
main "$@"
|