forked from joshdk/go-junit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
61 lines (48 loc) · 1.36 KB
/
Makefile
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
#### Environment ####
# Enforce usage of the Go modules system.
export GO111MODULE := on
# Determine where `go get` will install binaries to.
GOBIN := $(HOME)/go/bin
ifdef GOPATH
GOBIN := $(GOPATH)/bin
endif
# All target for when make is run on its own.
.PHONY: all
all: test lint
#### Binary Dependencies ####
# Install binary for go-junit-report.
go-junit-report := $(GOBIN)/go-junit-report
$(go-junit-report):
cd /tmp && go get -u github.com/jstemmer/go-junit-report
# Install binary for golangci-lint.
golangci-lint := $(GOBIN)/golangci-lint
$(golangci-lint):
@./scripts/install-golangci-lint $(golangci-lint)
# Install binary for goimports.
goimports := $(GOBIN)/goimports
$(goimports):
cd /tmp && go get -u golang.org/x/tools/cmd/goimports
#### Linting ####
# Run code linters.
.PHONY: lint
lint: $(golangci-lint) style
golangci-lint run
# Run code formatters. Unformatted code will fail in CircleCI.
.PHONY: style
style: $(goimports)
ifdef CI
goimports -l .
else
goimports -l -w .
endif
#### Testing ####
# Run Go tests and generate a JUnit XML style test report for ingestion by CircleCI.
.PHONY: test
test: $(go-junit-report)
@mkdir -p test-results
@go test -race -v 2>&1 | tee test-results/report.log
@cat test-results/report.log | go-junit-report -set-exit-code > test-results/report.xml
# Clean up test reports.
.PHONY: clean
clean:
@rm -rf test-results