2020-08-01 00:09:05 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
2020-08-12 00:48:16 +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() {
|
|
|
|
if [ -x "$(command -v golangci-lint)" ]; then
|
|
|
|
cmd='golangci-lint'
|
|
|
|
else
|
|
|
|
cmd='go run github.com/golangci/golangci-lint/cmd/golangci-lint'
|
|
|
|
fi
|
|
|
|
echo "${cmd} run --modules-download-mode=readonly --timeout=10m"
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_cmd() {
|
|
|
|
if [ -x "$(command -v gotest)" ]; then
|
|
|
|
cmd='gotest'
|
|
|
|
else
|
|
|
|
cmd='go test'
|
|
|
|
fi
|
|
|
|
echo "${cmd} -race ./..."
|
|
|
|
}
|
|
|
|
|
2020-08-07 01:44:14 +00:00
|
|
|
function unittest_cmd() {
|
|
|
|
if [ -x "$(command -v gotest)" ]; then
|
|
|
|
cmd='gotest'
|
|
|
|
else
|
|
|
|
cmd='go test'
|
|
|
|
fi
|
|
|
|
echo "${cmd} -short -race ./..."
|
|
|
|
}
|
|
|
|
|
2020-08-13 21:10:41 +00:00
|
|
|
function codegen_cmd() {
|
2020-08-18 15:06:59 +00:00
|
|
|
echo "${ROOT}/hack/lib/codegen.sh codegen::generate"
|
2020-08-13 21:10:41 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 00:34:21 +00:00
|
|
|
function codegen_verify_cmd() {
|
2020-08-18 15:06:59 +00:00
|
|
|
echo "${ROOT}/hack/lib/codegen.sh codegen::verify"
|
2020-08-15 00:34:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 00:28:00 +00:00
|
|
|
# The race detector is slow, so sometimes you don't want to use it
|
|
|
|
function unittest_no_race_cmd() {
|
|
|
|
if [ -x "$(command -v gotest)" ]; then
|
|
|
|
cmd='gotest'
|
|
|
|
else
|
|
|
|
cmd='go test'
|
|
|
|
fi
|
|
|
|
echo "${cmd} -short ./..."
|
|
|
|
}
|
|
|
|
|
2020-08-01 00:09:05 +00:00
|
|
|
function with_modules() {
|
|
|
|
local cmd_function="${1}"
|
|
|
|
cmd="$(${cmd_function})"
|
|
|
|
|
2020-08-12 00:48:16 +00:00
|
|
|
pushd "${ROOT}"
|
2020-08-12 13:36:33 +00:00
|
|
|
for mod_file in $(find . -maxdepth 4 -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
|
|
|
export MOD_DIR
|
|
|
|
echo "=> "
|
|
|
|
echo " cd ${mod_dir} && ${cmd}"
|
|
|
|
cd "${mod_dir}" && MOD_DIR="$(pwd)" && ${cmd}
|
2020-08-01 00:09:05 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "Error: <task> must be specified"
|
2020-08-15 00:34:21 +00:00
|
|
|
echo " do.sh <task> [tidy, lint, test, unittest, unittest_no_race, codegen, codegen_verify]"
|
2020-08-01 00:09:05 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
case "${1:-invalid}" in
|
|
|
|
'tidy') with_modules 'tidy_cmd' ;;
|
|
|
|
'lint') with_modules 'lint_cmd' ;;
|
|
|
|
'test') with_modules 'test_cmd' ;;
|
2020-08-07 01:44:14 +00:00
|
|
|
'unittest') with_modules 'unittest_cmd' ;;
|
2020-08-12 00:28:00 +00:00
|
|
|
'unittest_no_race') with_modules 'unittest_no_race_cmd' ;;
|
2020-08-13 21:10:41 +00:00
|
|
|
'codegen') with_modules 'codegen_cmd' ;;
|
2020-08-15 00:34:21 +00:00
|
|
|
'codegen_verify') with_modules 'codegen_verify_cmd' ;;
|
2020-08-01 00:09:05 +00:00
|
|
|
*) usage ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-08-05 21:19:29 +00:00
|
|
|
main "$@"
|