2020-08-01 00:09:05 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-08-21 23:15:48 +00:00
|
|
|
|
2020-09-16 14:05:51 +00:00
|
|
|
# Copyright 2020 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() {
|
|
|
|
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
|
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-08-21 23:15:48 +00:00
|
|
|
echo "${cmd} -count 1 -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-08-21 23:15:48 +00:00
|
|
|
pushd "${ROOT}" >/dev/null
|
2020-08-24 19:09:35 +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 "=> "
|
|
|
|
echo " cd ${mod_dir} && ${cmd}"
|
2020-08-21 19:30:50 +00:00
|
|
|
cd "${mod_dir}" && ${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 "$@"
|