Debian Codegraph @

pre-commit

raw
1 #!/bin/sh
2
3 LATEST_STABLE_SUPPORTED_GO_VERSION="1.11"
4
5 main() {
6 if local_go_version_is_latest_stable
7 then
8 run_gofmt
9 run_golint
10 run_govet
11 fi
12 run_unit_tests
13 }
14
15 local_go_version_is_latest_stable() {
16 go version | grep -q $LATEST_STABLE_SUPPORTED_GO_VERSION
17 }
18
19 log_error() {
20 echo "$*" 1>&2
21 }
22
23 run_gofmt() {
24 GOFMT_FILES=$(gofmt -l .)
25 if [ -n "$GOFMT_FILES" ]
26 then
27 log_error "gofmt failed for the following files:
28 $GOFMT_FILES
29
30 please run 'gofmt -w .' on your changes before committing."
31 exit 1
32 fi
33 }
34
35 run_golint() {
36 GOLINT_ERRORS=$(golint ./... | grep -v "Id should be")
37 if [ -n "$GOLINT_ERRORS" ]
38 then
39 log_error "golint failed for the following reasons:
40 $GOLINT_ERRORS
41
42 please run 'golint ./...' on your changes before committing."
43 exit 1
44 fi
45 }
46
47 run_govet() {
48 GOVET_ERRORS=$(go tool vet ./*.go 2>&1)
49 if [ -n "$GOVET_ERRORS" ]
50 then
51 log_error "go vet failed for the following reasons:
52 $GOVET_ERRORS
53
54 please run 'go tool vet ./*.go' on your changes before committing."
55 exit 1
56 fi
57 }
58
59 run_unit_tests() {
60 if [ -z "$NOTEST" ]
61 then
62 log_error 'Running short tests...'
63 env AMQP_URL= go test -short
64 fi
65 }
66
67 main