-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
151 lines (123 loc) · 3.21 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
# sourced by https://github.com/octomation/makefiles
.DEFAULT_GOAL = test-with-coverage
SHELL = /bin/bash -euo pipefail
GO111MODULE = on
GOFLAGS = -mod=vendor
GOPRIVATE = go.octolab.net
GOPROXY = direct
LOCAL = $(MODULE)
MODULE = `go list -m`
PACKAGES = `go list ./... 2> /dev/null`
PATHS = $(shell echo $(PACKAGES) | sed -e "s|$(MODULE)/\{0,1\}||g")
TIMEOUT = 1s
ifeq (, $(PACKAGES))
PACKAGES = $(MODULE)
endif
ifeq (, $(PATHS))
PATHS = .
endif
export GO111MODULE := $(GO111MODULE)
export GOFLAGS := $(GOFLAGS)
export GOPRIVATE := $(GOPRIVATE)
export GOPROXY := $(GOPROXY)
.PHONY: go-env
go-env:
@echo "GO111MODULE: `go env GO111MODULE`"
@echo "GOFLAGS: $(strip `go env GOFLAGS`)"
@echo "GOPRIVATE: $(strip `go env GOPRIVATE`)"
@echo "GOPROXY: $(strip `go env GOPROXY`)"
@echo "LOCAL: $(LOCAL)"
@echo "MODULE: $(MODULE)"
@echo "PACKAGES: $(PACKAGES)"
@echo "PATHS: $(strip $(PATHS))"
@echo "TIMEOUT: $(TIMEOUT)"
.PHONY: deps-check
deps-check:
@go mod verify
@if command -v egg > /dev/null; then \
egg deps check license; \
egg deps check version; \
fi
.PHONY: deps-clean
deps-clean:
@go clean -modcache
.PHONY: deps-shake
deps-shake:
@go mod tidy
@if [[ "`go env GOFLAGS`" =~ -mod=vendor ]]; then go mod vendor; fi
.PHONY: module-deps
module-deps:
@go mod download
@if [[ "`go env GOFLAGS`" =~ -mod=vendor ]]; then go mod vendor; fi
.PHONY: update
update: selector = '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}'
update:
@if command -v egg > /dev/null; then \
packages="`egg deps list`"; \
else \
packages="`go list -f $(selector) -m -mod=readonly all`"; \
fi; \
if [[ "`go version`" == *1.1[1-3]* ]]; then \
go get -d -mod= -u $$packages; \
else \
go get -d -u $$packages; \
fi; \
if [[ "`go env GOFLAGS`" =~ -mod=vendor ]]; then go mod vendor; fi
.PHONY: update-all
update-all:
@if [[ "`go version`" == *1.1[1-3]* ]]; then \
go get -d -mod= -u ./...; \
else \
go get -d -u ./...; \
fi; \
if [[ "`go env GOFLAGS`" =~ -mod=vendor ]]; then go mod vendor; fi
.PHONY: format
format:
@if command -v goimports > /dev/null; then \
goimports -local $(LOCAL) -ungroup -w $(PATHS); \
else \
gofmt -s -w $(PATHS); \
fi
.PHONY: go-generate
go-generate:
@go generate $(PACKAGES)
.PHONY: lint
lint:
@if command -v golangci-lint > /dev/null; then \
golangci-lint run ./...; \
else \
go vet $(PACKAGES); \
fi
.PHONY: test
test:
@go test -race -timeout $(TIMEOUT) $(PACKAGES)
.PHONY: test-clean
test-clean:
@go clean -testcache
.PHONY: test-with-coverage
test-with-coverage:
@go test -cover -timeout $(TIMEOUT) $(PACKAGES) | column -t | sort -r
.PHONY: test-with-coverage-profile
test-with-coverage-profile:
@go test -cover -covermode count -coverprofile c.out -timeout $(TIMEOUT) $(PACKAGES)
define go_tpl
.PHONY: go$(1)
go$(1):
docker run \
--rm -it \
-v $(PWD):/src \
-w /src \
golang:$(1) bash
endef
render_go_tpl = $(eval $(call go_tpl,$(version)))
$(foreach version,1.11 1.12 1.13 1.14,$(render_go_tpl))
.PHONY: clean
clean: deps-clean test-clean
.PHONY: deps
deps: module-deps
.PHONY: env
env: go-env
.PHONY: generate
generate: go-generate format
.PHONY: refresh
refresh: deps-shake update deps generate format test