forked from kyma-project/api-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
before-commit.sh
84 lines (71 loc) · 1.76 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
#!/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 -e "${NC}"
##
# GO BUILD
##
buildEnv=""
if [ "$1" == "$CI_FLAG" ]; then
# build binary statically
buildEnv="env CGO_ENABLED=0"
fi
${buildEnv} go build -o bin/manager main.go
goBuildResult=$?
if [ ${goBuildResult} != 0 ]; then
echo -e "${RED}✗ go build${NC}\n$goBuildResult${NC}"
exit 1
else echo -e "${GREEN}√ go build${NC}"
fi
##
# GO TEST
##
echo "? go test"
go test -short ./...
# Check if tests passed
if [ $? != 0 ]; then
echo -e "${RED}✗ go test\n${NC}"
exit 1
else echo -e "${GREEN}√ go test${NC}"
fi
##
# GO LINT
##
echo "? golint"
go install golang.org/x/lint/golint
golint ./... | grep -v internal/builders
echo -e "${GREEN}√ golint${NC}"
##
# GO FMT
##
echo "? go fmt"
go fmt ./...
echo -e "${GREEN}√ go fmt${NC}"
##
# GO VET
##
packagesToVet=($(go list ./... | grep -v /vendor/ | grep -v api-controller/pkg/clients ))
for vPackage in "${packagesToVet[@]}"; do
vetResult=$(go vet ${vPackage})
if [ $(echo ${#vetResult}) != 0 ]; then
echo -e "${RED}✗ go vet ${vPackage} ${NC}\n$vetResult${NC}"
exit 1
else echo -e "${GREEN}√ go vet ${vPackage} ${NC}"
fi
done
##
# INFO.JSON
##
author=$(git show -s --pretty=%an)
branch=$(git rev-parse --abbrev-ref HEAD)
commit=$(git rev-parse --verify HEAD)
commitMsg=$(git show -s --pretty=%s)
commitDate=$(git log -1 --format=%cd)
printf "{\n\t\"author\": \"""$author""\",\n\t\"commit\": \""$commit"\",\n\t\"branch\": \""$branch"\",\n\t\"commitDate\":\"""$commitDate""\",\n\t\"commitMessage\":\"""$commitMsg""\",\n\t\"deployDate\": \"""$(date)""\"\n}" >info.json
echo -e "${GREEN}√ info.json ${NC}" $(cat info.json)