2020-08-01 00:09:05 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
root_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
|
|
|
|
|
|
|
|
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 ./..."
|
|
|
|
}
|
|
|
|
|
|
|
|
function with_modules() {
|
|
|
|
local cmd_function="${1}"
|
|
|
|
cmd="$(${cmd_function})"
|
|
|
|
|
|
|
|
pushd "${root_dir}"
|
2020-08-05 21:19:29 +00:00
|
|
|
for mod_file in $(find . -maxdepth 4 -name go.mod); do
|
2020-08-01 00:09:05 +00:00
|
|
|
mod_dir="$(dirname "${mod_file}")"
|
|
|
|
(
|
|
|
|
echo "=> " && \
|
|
|
|
echo " cd ${mod_dir} && ${cmd}" && \
|
|
|
|
cd "${mod_dir}" && ${cmd}
|
|
|
|
)
|
|
|
|
done
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "Error: <task> must be specified"
|
|
|
|
echo " do.sh <task> [tidy, lint, test]"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
case "${1:-invalid}" in
|
|
|
|
'tidy') with_modules 'tidy_cmd' ;;
|
|
|
|
'lint') with_modules 'lint_cmd' ;;
|
|
|
|
'test') with_modules 'test_cmd' ;;
|
|
|
|
*) usage ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-08-05 21:19:29 +00:00
|
|
|
main "$@"
|