forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbefore-commit.sh
executable file
·114 lines (99 loc) · 2.41 KB
/
before-commit.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
readonly CI_FLAG=ci
RED='\033[0;31m'
GREEN='\033[0;32m'
INVERTED='\033[7m'
NC='\033[0m' # No Color
echo -e "${INVERTED}"
echo "USER: " + $USER
echo "PATH: " + $PATH
echo "GOPATH:" + $GOPATH
echo -e "${NC}"
##
# GO BUILD
##
buildEnv=""
if [ "$1" == "$CI_FLAG" ]; then
# build binary statically
buildEnv="env CGO_ENABLED=0"
fi
${buildEnv} go build -o console-backend-service
goBuildResult=$?
rm console-backend-service
if [ ${goBuildResult} != 0 ]; then
echo -e "${RED}✗ go build${NC}\n$goBuildResult${NC}"
exit 1
else echo -e "${GREEN}√ go build${NC}"
fi
##
# DEP
##
echo "? dep status"
depResult=$(dep status -v)
if [ $? != 0 ]
then
echo -e "${RED}✗ dep status\n$depResult${NC}"
exit 1;
else echo -e "${GREEN}√ dep status${NC}"
fi
##
# GO TEST
##
echo "? go test"
go test ./...
# Check if tests passed
if [ $? != 0 ];
then
echo -e "${RED}✗ go test\n${NC}"
exit 1;
else echo -e "${GREEN}√ go test${NC}"
fi
filesToCheck=$(find . -type f -name "*.go" | egrep -v "\/vendor\/|_*/automock/|_*/testdata/|/pkg\/|_*export_test.go")
#
# GO IMPORTS
#
go build -o goimports-vendored ./vendor/golang.org/x/tools/cmd/goimports
goImportsResult=$(echo "${filesToCheck}" | xargs -L1 ./goimports-vendored -w -l)
rm goimports-vendored
if [ $(echo ${#goImportsResult}) != 0 ]
then
echo -e "${RED}✗ goimports ${NC}\n$goImportsResult${NC}"
exit 1;
else echo -e "${GREEN}√ goimports ${NC}"
fi
#
# GO FMT
#
goFmtResult=$(echo "${filesToCheck}" | xargs -L1 go fmt)
if [ $(echo ${#goFmtResult}) != 0 ]
then
echo -e "${RED}✗ go fmt${NC}\n$goFmtResult${NC}"
exit 1;
else echo -e "${GREEN}√ go fmt${NC}"
fi
##
# ERRCHECK
##
go build -o errcheck-vendored ./vendor/github.com/kisielk/errcheck
buildErrCheckResult=$?
if [[ ${buildErrCheckResult} != 0 ]]; then
echo -e "${RED}✗ go build errcheck${NC}\n${buildErrCheckResult}${NC}"
exit 1
fi
errCheckResult=$(./errcheck-vendored -blank -asserts -ignoregenerated -exclude automock ./...)
rm errcheck-vendored
if [[ $(echo ${#errCheckResult}) != 0 ]]; then
echo -e "${RED}✗ [errcheck] unchecked error in:${NC}\n${errCheckResult}${NC}"
exit 1
else echo -e "${GREEN}√ errcheck ${NC}"
fi
#
# GO VET
#
goVetResult=$(echo "${filesToCheck}" | xargs -L1 go vet)
if [ $(echo ${#goVetResult}) != 0 ]
then
echo -e "${RED}✗ go vet${NC}\n$goVetResult${NC}"
exit 1;
else echo -e "${GREEN}√ go vet${NC}"
fi