Debian Codegraph @

Makefile

raw
1 #### Environment ####
2
3 # Enforce usage of the Go modules system.
4 export GO111MODULE := on
5
6 # Determine where `go get` will install binaries to.
7 GOBIN := $(HOME)/go/bin
8 ifdef GOPATH
9 GOBIN := $(GOPATH)/bin
10 endif
11
12 # All target for when make is run on its own.
13 .PHONY: all
14 all: test lint
15
16 #### Binary Dependencies ####
17
18 # Install binary for go-junit-report.
19 go-junit-report := $(GOBIN)/go-junit-report
20 $(go-junit-report):
21 cd /tmp && go get -u github.com/jstemmer/go-junit-report
22
23 # Install binary for golangci-lint.
24 golangci-lint := $(GOBIN)/golangci-lint
25 $(golangci-lint):
26 @./scripts/install-golangci-lint $(golangci-lint)
27
28 # Install binary for goimports.
29 goimports := $(GOBIN)/goimports
30 $(goimports):
31 cd /tmp && go get -u golang.org/x/tools/cmd/goimports
32
33 #### Linting ####
34
35 # Run code linters.
36 .PHONY: lint
37 lint: $(golangci-lint) style
38 golangci-lint run
39
40 # Run code formatters. Unformatted code will fail in CircleCI.
41 .PHONY: style
42 style: $(goimports)
43 ifdef CI
44 goimports -l .
45 else
46 goimports -l -w .
47 endif
48
49 #### Testing ####
50
51 # Run Go tests and generate a JUnit XML style test report for ingestion by CircleCI.
52 .PHONY: test
53 test: $(go-junit-report)
54 @mkdir -p test-results
55 @go test -race -v 2>&1 | tee test-results/report.log
56 @cat test-results/report.log | go-junit-report -set-exit-code > test-results/report.xml
57
58 # Clean up test reports.
59 .PHONY: clean
60 clean:
61 @rm -rf test-results