-
Notifications
You must be signed in to change notification settings - Fork 492
/
Makefile
172 lines (143 loc) · 3.96 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOGENERATE=$(GOCMD) generate
GOGET=$(GOCMD) get
GOINSTALL=$(GOCMD) install
GOLIST=$(GOCMD) list
GOMOD=$(GOCMD) mod
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
GOTOOL=$(GOCMD) tool
BINARY_NAME=bosun
BINARY_UNIX=$(BINARY_NAME)_unix
BINARY_MAC=$(BINARY_NAME)_mac
BINARY_WIN=$(BINARY_NAME)_win
BOSUN_PACKAGE=bosun.org/cmd/bosun
SCOLLECTOR_BINARY=scollector
SCOLLECTOR_PACKAGE=bosun.org/cmd/scollector
TSDBRELAY_BINARY=tsdbrelay
TSDBRELAY_PACKAGE=bosun.org/cmd/tsdbrelay
SRCS := $(shell find . -name '*.go')
LINTERS := \
golang.org/x/lint/golint \
golang.org/x/tools/cmd/goimports \
github.com/kisielk/errcheck \
honnef.co/go/tools/cmd/staticcheck
.PHONY: build
build:
$(GOBUILD) -v bosun.org/...
.PHONY: build-linux
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -v bosun.org/...
.PHONY: build-darwin
build-darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -v bosun.org/...
.PHONY: build-windows
build-windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -v bosun.org/...
.PHONY: deps
deps:
$(GOGET) -d -v ./...
npm install
.PHONY: updatedeps
updatedeps:
$(GOGET) -d -v -u -f ./...
.PHONY: testdeps
testdeps:
$(GOGET) -d -v -t ./...
$(GOGET) -v $(LINTERS)
.PHONY: updatetestdeps
updatetestdeps:
$(GOGET) -d -v -t -u -f ./...
$(GOGET) -u -v $(LINTERS)
.PHONY: install
install: deps
$(GOINSTALL) ./...
.PHONY: golint
golint:
@for file in $(SRCS); do \
golint $${file}; \
if [ -n "$$(golint $${file})" ]; then \
exit 1; \
fi; \
done
.PHONY: vet
vet:
$(GOVET) ./...
.PHONY: generate
generate:
$(GOGENERATE) ./...
@if [ -n "$$(git diff --exit-code --name-only)" ]; then \
echo "The following files are uncommitted changes in the repository:"; \
git diff --name-only; \
echo "Please commit the files created by go generate."; \
echo "This may be a false positive if there were uncommitted files before running this target."; \
exit 1; \
fi
.PHONY: goimports
goimports:
goimports -format-only -w ${SRCS}
.PHONY: goimports-check
goimports-check:
@if [ ! -z "$$(goimports -format-only -l ${SRCS})" ]; then \
echo "Found unformatted source files. Please run"; \
echo " make goimports"; \
echo "To automatically format your files"; \
exit 1; \
fi
.PHONY: tidy
tidy:
$(GOMOD) tidy
.PHONY: tidy-check
tidy-check: tidy
@if [ -n "$$(git diff-index --exit-code --ignore-submodules --name-only HEAD | grep -E '^go.(mod|sum)$$')" ]; then \
echo "go.mod or go.sum has changed after running go mod tidy for you."; \
echo "Please make sure you review and commit the changes."; \
exit 1; \
fi
.PHONY: errcheck
errcheck:
errcheck ./...
.PHONY: staticcheck
staticcheck:
staticcheck ./...
.PHONY: test
test:
$(GOTEST) -v ./...
.PHONY: test-coverprofile
test-coverprofile:
$(GOTEST) -covermode=count -coverprofile=coverage.out $$($(GOLIST) ./... | grep -v integration) -json > test-report.out
.PHONY: coverage
coverage:
$(GOTEST) -covermode=count -coverprofile=coverage.out $$($(GOLIST) ./... | grep -v integration)
$(GOTOOL) cover -html=coverage.out
.PHONY: checks
checks: goimports-check vet generate tidy-check
.PHONY: clean
clean:
$(GOCLEAN) -v ./...
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)
rm -f $(BINARY_MAC)
rm -f $(BINARY_WIN)
.PHONY: run
run: bosun
./$(BINARY_NAME)
# Cross compilation
all-os: bosun-linux bosun-darwin bosun-windows
bosun:
$(GOBUILD) -o $(BINARY_NAME) -v $(BOSUN_PACKAGE)
bosun-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v $(BOSUN_PACKAGE)
bosun-darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_MAC) -v $(BOSUN_PACKAGE)
bosun-windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_WIN) -v $(BOSUN_PACKAGE)
scollector:
$(GOBUILD) -o $(SCOLLECTOR_BINARY) -v $(SCOLLECTOR_PACKAGE)
tsdbrelay:
$(GOBUILD) -o $(TSDBRELAY_BINARY) -v $(TSDBRELAY_PACKAGE)
.PHONY: all
all: deps testdeps checks build all-os build test bosun scollector tsdbrelay