-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
151 lines (128 loc) · 4.48 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
.PHONY : update updatetools tools
.PHONY : lint test integration coverage
.PHONY : build
.PHONY : clean cleancoverage cleantools
PROJECT_PATH = $(shell pwd -L)
TOOLSDIR = $(PROJECT_PATH)/tools
BINDIR = $(PROJECT_PATH)/bin
BUILDDIR = $(PROJECT_PATH)/.build
GOFLAGS ::= ${GOFLAGS}
COVERDIR = $(PROJECT_PATH)/.coverage
COVEROUT = $(wildcard $(COVERDIR)/*.out)
COVERINTERCHANGE = $(COVEROUT:.out=.interchange)
COVERHTML = $(COVEROUT:.out=.html)
COVERXML = $(COVEROUT:.out=.xml)
COVERCOMBINED ::= $(COVERDIR)/combined.out
BUILDNAME = remouse
# Tools need to be enumerated here in order to support updating them.
# They will only be used in the context of the /tools directory which
# is a special sub-module that is only engaged when handling the tools.
# We do this to prevent having tools included in the actual project
# dependencies.
TOOLS ::= github.com/golang/mock/mockgen
TOOLS ::= $(TOOLS) golang.org/x/tools/cmd/goimports
TOOLS ::= $(TOOLS) github.com/golangci/golangci-lint/cmd/golangci-lint
TOOLS ::= $(TOOLS) github.com/axw/gocov/gocov
TOOLS ::= $(TOOLS) github.com/matm/gocov-html
TOOLS ::= $(TOOLS) github.com/AlekSi/gocov-xml
TOOLS ::= $(TOOLS) github.com/wadey/gocovmerge
UNIT_PKGS = $(shell go list ./... | sed 1d | paste -sd "," -)
update:
GO111MODULE=on go get -u
updatetools: cleantools
# Regenerate the module files for the tools and then
# reinstall them. This should be done periodically but
# infrequently.
cd $(TOOLSDIR) && GO111MODULE=on go get -u $(TOOLS)
$(MAKE) $(BINDIR)
$(BINDIR):
cd $(TOOLSDIR) && GOBIN=$(BINDIR) go install $(TOOLS)
tools: $(BINDIR)
# This is an alias for generating the tools. Unless
# $(BINDIR) is set elsewhere it will generate a local
# /bin directory in the repo.
fmt: $(BINDIR)
# Apply goimports to all code files. Here we intentionally
# ignore everything in /vendor if it is present.
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
$(BINDIR)/goimports -w -v \
-local github.com/kevinconway/ \
$(shell find . -type f -name '*.go' -not -path "./vendor/*")
lint: $(BINDIR)
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
$(BINDIR)/golangci-lint run \
--config .golangci.yaml \
--print-resources-usage \
--verbose
test: $(BINDIR) $(COVERDIR)
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
go test \
-v \
-cover \
-race \
-coverpkg="$(UNIT_PKGS)" \
-coverprofile="$(COVERDIR)/unit.out" \
./...
build: $(BUILDDIR)
# Optionally build the service if it has an executable
# present in the project root.
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
go build -o $(BUILDDIR)/$(BUILDNAME) main.go
$(BUILDDIR):
mkdir -p $(BUILDDIR)
generate: $(BINDIR)
# Run any code generation steps.
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
PATH="${PATH}:$(BINDIR)" \
go generate github.com/kevinconway/remouseable/pkg github.com/kevinconway/remouseable/pkg/internal
$(MAKE) fmt
coverage: $(BINDIR) $(COVERDIR) $(COVERCOMBINED) $(COVERINTERCHANGE) $(COVERHTML) $(COVERXML)
# The cover rule is an alias for a number of other rules that each
# generate part of the full coverage report. First, any coverage reports
# are combined so that there is a report both for an individual test run
# and a report that covers all test runs together. Then all coverage
# files are converted to an interchange format. From there we generate
# an HTML and XML report. XML reports may be used with jUnit style parsers,
# the HTML report is for human consumption in order to help identify
# the location of coverage gaps, and the original reports are available
# for any purpose.
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
go tool cover -func $(COVERCOMBINED)
$(COVERCOMBINED):
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
$(BINDIR)/gocovmerge $(COVERDIR)/*.out > $(COVERCOMBINED)
# NOTE: I couldn't figure out how to automatically include
# the combined files with the list of other .out files that
# are processed in bulk. For now, this needs to have specific
# calls to make for combined coverage.
$(MAKE) $(COVERCOMBINED:.out=.interchange)
$(MAKE) $(COVERCOMBINED:.out=.xml)
$(MAKE) $(COVERCOMBINED:.out=.html)
$(COVERDIR)/%.interchange: $(COVERDIR)/%.out
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
$(BINDIR)/gocov convert $< > $@
$(COVERDIR)/%.xml: $(COVERDIR)/%.interchange
cat $< | \
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
$(BINDIR)/gocov-xml > $@
$(COVERDIR)/%.html: $(COVERDIR)/%.interchange
cat $< | \
GO111MODULE=on \
GOFLAGS="$(GOFLAGS)" \
$(BINDIR)/gocov-html > $@
$(COVERDIR):
mkdir -p $(COVERDIR)
clean: cleancoverage cleantools ;
cleantools:
rm -rf $(BINDIR)
cleancoverage:
rm -rf $(COVERDIR)