-
Notifications
You must be signed in to change notification settings - Fork 21
/
build
executable file
·62 lines (52 loc) · 1.32 KB
/
build
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
#!/usr/bin/env bash
#
# This script is used build this project
# TRACING:
#
# If the TRACE environment variable is truthy turn on tracing,
# using the bash -x option. Useful when debugging this script.
#
# TRACE=1 ./build
#
[[ "${TRACE}" ]] && set -x
# Set Bash Options.
#
# -e option will cause the script to exit immediately when a command fails.
#
# -o pipefail option sets the exit code of a pipeline to that of the
# rightmost command to exit with a non-zero status, or zero if all commands
# of the pipeline exit successfully.
set -eo pipefail
# Check if git is available, go is available and GOPATH is not empty
check() {
if ! [ -x "$(command -v git)" ]; then
echo 'ERROR: could not find the git command.' >&2
exit 1
fi
if ! [ -x "$(command -v go)" ]; then
echo 'ERROR: could not find the go command.' >&2
exit 1
fi
if [ -z "$GOPATH" ]; then
echo 'ERROR: GOPATH is empty.' >&2
exit 1
fi
}
# run gometalinter, install it if not present
lint() {
# if gometalinter is not installed, install it
if [ ! -f "$GOPATH/bin/gometalinter" ]; then
go get -u github.com/alecthomas/gometalinter
gometalinter --install
fi
gometalinter --enable-all --line-length=120 ./...
}
# build the code
build() {
go build -v ./...
}
# run tests with coverage analysis
test() {
go test -v -cover ./...
}
check && lint && build && test