-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add build script and include metalinter
- Loading branch information
1 parent
0742026
commit e1bdb0c
Showing
2 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 ./... | ||
} | ||
|
||
# build the code | ||
build() { | ||
go build -v ./... | ||
} | ||
|
||
# run tests with coverage analysis | ||
test() { | ||
go test -v -cover ./... | ||
} | ||
|
||
check && lint && build && test |