Allow aliases for the first argument of module.sh
- Makes it easier to guess/remember what are the legal arguments - Also update the output a little to make it easier to tell when the command has succeeded - And run tests using `-count 1` because cached test results are not very trustworthy
This commit is contained in:
parent
76bd274fc4
commit
d4b184a7d5
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
|
||||||
function tidy_cmd() {
|
function tidy_cmd() {
|
||||||
@ -21,7 +23,7 @@ function test_cmd() {
|
|||||||
else
|
else
|
||||||
cmd='go test'
|
cmd='go test'
|
||||||
fi
|
fi
|
||||||
echo "${cmd} -race ./..."
|
echo "${cmd} -count 1 -race ./..."
|
||||||
}
|
}
|
||||||
|
|
||||||
function unittest_cmd() {
|
function unittest_cmd() {
|
||||||
@ -30,7 +32,7 @@ function unittest_cmd() {
|
|||||||
else
|
else
|
||||||
cmd='go test'
|
cmd='go test'
|
||||||
fi
|
fi
|
||||||
echo "${cmd} -short -race ./..."
|
echo "${cmd} -count 1 -short -race ./..."
|
||||||
}
|
}
|
||||||
|
|
||||||
function codegen_cmd() {
|
function codegen_cmd() {
|
||||||
@ -41,21 +43,11 @@ function codegen_verify_cmd() {
|
|||||||
echo "${ROOT}/hack/lib/codegen.sh codegen::verify"
|
echo "${ROOT}/hack/lib/codegen.sh codegen::verify"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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 ./..."
|
|
||||||
}
|
|
||||||
|
|
||||||
function with_modules() {
|
function with_modules() {
|
||||||
local cmd_function="${1}"
|
local cmd_function="${1}"
|
||||||
cmd="$(${cmd_function})"
|
cmd="$(${cmd_function})"
|
||||||
|
|
||||||
pushd "${ROOT}"
|
pushd "${ROOT}" >/dev/null
|
||||||
for mod_file in $(find . -maxdepth 4 -name go.mod | sort); do
|
for mod_file in $(find . -maxdepth 4 -name go.mod | sort); do
|
||||||
mod_dir="$(dirname "${mod_file}")"
|
mod_dir="$(dirname "${mod_file}")"
|
||||||
(
|
(
|
||||||
@ -64,26 +56,42 @@ function with_modules() {
|
|||||||
cd "${mod_dir}" && ${cmd}
|
cd "${mod_dir}" && ${cmd}
|
||||||
)
|
)
|
||||||
done
|
done
|
||||||
popd
|
popd >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
echo "Error: <task> must be specified"
|
echo "Error: <task> must be specified"
|
||||||
echo " do.sh <task> [tidy, lint, test, unittest, unittest_no_race, codegen, codegen_verify]"
|
echo " module.sh <task> [tidy, lint, test, unittest, codegen, codegen_verify]"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
case "${1:-invalid}" in
|
case "${1:-invalid}" in
|
||||||
'tidy') with_modules 'tidy_cmd' ;;
|
'tidy')
|
||||||
'lint') with_modules 'lint_cmd' ;;
|
with_modules 'tidy_cmd'
|
||||||
'test') with_modules 'test_cmd' ;;
|
;;
|
||||||
'unittest') with_modules 'unittest_cmd' ;;
|
'lint' | 'linter' | 'linters')
|
||||||
'unittest_no_race') with_modules 'unittest_no_race_cmd' ;;
|
with_modules 'lint_cmd'
|
||||||
'codegen') with_modules 'codegen_cmd' ;;
|
;;
|
||||||
'codegen_verify') with_modules 'codegen_verify_cmd' ;;
|
'test' | 'tests')
|
||||||
*) usage ;;
|
with_modules 'test_cmd'
|
||||||
|
;;
|
||||||
|
'unittest' | 'unittests' | 'units' | 'unit')
|
||||||
|
with_modules 'unittest_cmd'
|
||||||
|
;;
|
||||||
|
'codegen' | 'codegens')
|
||||||
|
with_modules 'codegen_cmd'
|
||||||
|
;;
|
||||||
|
'codegen_verify' | 'verify_codegen')
|
||||||
|
with_modules 'codegen_verify_cmd'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
echo "=> "
|
||||||
|
echo " \"module.sh $1\" Finished successfully."
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
Loading…
Reference in New Issue
Block a user