-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathall.bash
executable file
·65 lines (58 loc) · 1.72 KB
/
all.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
base="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$base/script/build"
: ${build_go:=1}
set -eu
main() {
cd $base
rm -f $base/coverage.{info,txt} $base/*.gcda $base/*.gcno
echo "build version: $(build_version)"
if [[ "$build_go" != "0" ]] ; then
export GO111MODULE=on
go install -v github.com/xlab/c-for-go@latest
go install -v golang.org/x/tools/cmd/stringer@latest
go get -v github.com/golang/protobuf/[email protected]
ensure_golangci_lint
go generate ./...
go build ./...
go test -timeout 3m -race -coverprofile=$base/coverage.txt -covermode=atomic ./...
go test -bench=. -vet= ./...
golangci-lint run || true
fi
paths=$(find . -type d ! -path '.' ! -path '*/.*' ! -path './script*' ! -path './target*' ! -path './vendor*')
for d in $paths ; do
# skip directories without files
if [[ -z "$(find $base/$d -depth 1 ! -type d ! -path '*/.*')" ]] ; then continue ; fi
# skip directories with .go files, already built them
if ls "$base/$d"/*.go >/dev/null 2>&1 ; then continue ; fi
echo "no build defined for $d" >&2
exit 1
done
}
ensure_golangci_lint() {
golangci-lint -h &>/dev/null && return 0
echo "$0: golangci-lint is not installed; CI should just work" >&2
confirm "Local dev? Install golangci-lint? [yN] " || return 1
(
set -eux
cd $(mktemp -d)
export GO111MODULE=on
go mod init tmp
go get github.com/golangci/golangci-lint/cmd/golangci-lint
rm -rf $PWD
)
}
confirm() {
local reply
local prompt="$1"
read -n1 -p "$prompt" -t31 reply >&2
echo "" >&2
local rc=0
local default_y=" \[Yn\] $"
if [[ -z "$reply" ]] && [[ "$prompt" =~ $default_y ]] ; then
reply="y"
fi
[[ "$reply" != "y" ]] && rc=1
return $rc
}
main "$@"