-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.sh
executable file
·68 lines (62 loc) · 1.7 KB
/
build.sh
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
66
67
68
#! /usr/bin/env bash
set -eo pipefail
trap 'echo -e "\033[33;5mBuild failed on build.sh:$LINENO\033[0m"' ERR
for arg in "$@"; do
case "$arg" in
--all | -a)
LINT=1
TEST=1
RACE=-race
;;
--lint | -l)
LINT=1
;;
--race | -r)
TEST=1
RACE=-race
;;
--test | -t)
TEST=1
;;
--help | -h)
echo "$0 [options]"
echo " -a, --all Equivalent to --lint --test --race"
echo " -l, --lint Run the linters"
echo " -r, --race Run the tests with race-checking enabled"
echo " -t, --test Run the tests"
echo " -h, --help This help text"
exit 0
;;
*)
echo "Invalid argument: $arg"
exit 1
;;
esac
done
# Build the code
echo -e "\033[33mBuilding...\033[0m"
go build -v ./...
# Run the linters
if [ "$LINT"x == "1x" ]; then
GOLANGCI_LINT_VERSION=$(curl --head -s https://github.com/golangci/golangci-lint/releases/latest | grep -i location: | sed 's/^.*v//' | tr -d '\r\n')
TOOLS_DIR=$(go env GOPATH)/bin
if [ ! -e "$TOOLS_DIR/golangci-lint" ] || [ "$("$TOOLS_DIR/golangci-lint" version 2>&1 | awk '{ print $4 }' || true)x" != "${GOLANGCI_LINT_VERSION}x" ]; then
echo -e "\033[33mInstalling version $GOLANGCI_LINT_VERSION of golangci-lint into $TOOLS_DIR...\033[0m"
mkdir -p "$TOOLS_DIR"
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$TOOLS_DIR" v$GOLANGCI_LINT_VERSION
fi
echo -e "\033[33mLinting...\033[0m"
"$TOOLS_DIR/golangci-lint" run
fi
# Run the tests
if [ "$TEST"x == "1x" ]; then
if [ -n "$RACE" ]; then
echo -e "\033[33mTesting with -race enabled...\033[0m"
else
echo -e "\033[33mTesting...\033[0m"
fi
go test $RACE ./...
fi
# Install executables
echo -e "\033[33mInstalling executables...\033[0m"
go install -v ./i18n/i18n