gotest.tools/gotestsum@v1.11.0/do (about) 1 #!/usr/bin/env bash 2 set -o errexit -o nounset -o pipefail 3 4 declare -A help 5 6 binary() { 7 mkdir -p dist 8 go build -o dist/gotestsum . 9 } 10 11 binary-static() { 12 echo "building static binary: dist/gotestsum" 13 CGO_ENABLED=0 binary 14 } 15 16 update-golden() { 17 gotestsum -- ./... -update 18 } 19 20 lint() { 21 golangci-lint run -v --config .project/golangci-lint.yml 22 } 23 24 go-mod-tidy() { 25 go mod tidy 26 git diff --stat --exit-code go.mod go.sum 27 } 28 29 help[shell]='Run a shell in a golang docker container. 30 31 Env vars: 32 33 GOLANG_VERSION - the docker image tag used to build the image. 34 ' 35 shell() { 36 local image; image="$(_docker-build-dev)" 37 docker run \ 38 --tty --interactive --rm \ 39 -v "$PWD:/work" \ 40 -v ~/.cache/go-build:/root/.cache/go-build \ 41 -v ~/go/pkg/mod:/go/pkg/mod \ 42 -w /work \ 43 "$image" \ 44 "${@-bash}" 45 } 46 47 _docker-build-dev() { 48 set -e 49 local idfile=".plsdo/docker-build-dev-image-id-${GOLANG_VERSION-default}" 50 local dockerfile=.project/Dockerfile 51 local tag=gotest.tools/gotestsum/builder 52 if [ -f "$idfile" ] && [ "$dockerfile" -ot "$idfile" ]; then 53 cat "$idfile" 54 return 0 55 fi 56 57 mkdir -p .plsdo 58 >&2 docker build \ 59 --iidfile "$idfile" \ 60 --file "$dockerfile" \ 61 --build-arg "UID=$UID" \ 62 --build-arg GOLANG_VERSION \ 63 --target "dev" \ 64 .plsdo 65 cat "$idfile" 66 } 67 68 help[godoc]="Run godoc locally to preview package documentation." 69 godoc() { 70 local url; url="http://localhost:6060/pkg/$(go list)/" 71 command -v xdg-open && xdg-open "$url" & 72 command -v open && open "$url" & 73 command godoc -http=:6060 74 } 75 76 help[list]="Print the list of tasks" 77 list() { 78 declare -F | awk '{print $3}' | grep -v '^_' 79 } 80 81 _plsdo_help() { 82 local topic="${1-}" 83 # print help for the topic 84 if [ -n "$topic" ]; then 85 if ! command -v "$topic" > /dev/null ; then 86 >&2 echo "No such task: $topic" 87 return 1 88 fi 89 90 printf "\nUsage:\n %s %s\n\n%s\n" "$0" "$topic" "${help[$topic]-}" 91 return 0 92 fi 93 94 # print list of tasks and their help line. 95 [ -n "${banner-}" ] && echo "$banner" && echo 96 for i in $(list); do 97 printf "%-12s\t%s\n" "$i" "${help[$i]-}" | head -1 98 done 99 } 100 101 _plsdo_run() { 102 case "${1-}" in 103 ""|help) 104 _plsdo_help "${2-}" ;; 105 *) 106 "$@" ;; 107 esac 108 } 109 110 _plsdo_run "$@"