-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
174 lines (142 loc) · 4.93 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
173
174
.DEFAULT_GOAL = all
SHELL = bash
skip = $(info $@: skipping, target disabled)
# Git
#
# Provide some nice to use variables for the git
# repository state
COMMIT := $(shell git rev-parse HEAD)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
SLUG := $(shell git remote -v | grep "(fetch)" | awk '{print$$2}' | sed -E 's/^.*(\/|:)([^ ]*)\/([^ ]*)$$/\2\/\3/;s/\.git//')
OS := $(shell uname)
# Directories
#
# All of the following directories can be
# overwritten. If this is done, it is
# only recommended to change the BUILD_DIR
# option.
BUILD_DIR := build
RELEASE_DIR := $(BUILD_DIR)/release
LINT_DIR := $(BUILD_DIR)/lint
TEST_DIR := $(BUILD_DIR)/test
IMAGE_DIR := $(BUILD_DIR)/container
DIST_DIR := $(BUILD_DIR)/dist
INT_DIR := $(BUILD_DIR)/integration
$(BUILD_DIR):
-mkdir $(BUILD_DIR)
$(RELEASE_DIR): | $(BUILD_DIR)
-mkdir $(RELEASE_DIR)
$(LINT_DIR): | $(BUILD_DIR)
-mkdir $(LINT_DIR)
$(TEST_DIR): | $(BUILD_DIR)
-mkdir $(TEST_DIR)
$(IMAGE_DIR): | $(BUILD_DIR)
-mkdir $(IMAGE_DIR)
$(DIST_DIR): | $(BUILD_DIR)
-mkdir $(DIST_DIR)
$(INT_DIR): | $(BUILD_DIR)
-mkdir $(INT_DIR)
GOPATH := $(shell go env GOPATH)
GOCACHE := $(shell go env GOCACHE)
GOBIN ?= $(GOPATH)/bin
# External binaries
#
# The following external binaries are required
# by this make file.
#
# We will abort any further commands if go
# is not installed.
#
# For docker, docker-compose, etc., we will
# only throw an error when evaluating targets
# that use that functionality and throw
# an error
GOLANGCILINT := $(GOBIN)/golangci-lint
GOIMPORTS := $(GOBIN)/goimports
GOCOVMERGE := $(GOBIN)/gocovmerge
GOCOVXML := $(GOBIN)/gocov-xml
GOCOV := $(GOBIN)/gocov
RICHGO := $(GOBIN)/richgo
MAKEDOC := $(GOBIN)/makedoc
STATIK := $(GOBIN)/statik
GORELEASER := bin/goreleaser/v.0.154.0/$(OS)/goreleaser
GOFUMPT := $(GOBIN)/gofumpt
$(GOLANGCILINT):
# To bump, simply change the version at the end to the desired version. The git sha here points to the newest commit
# of the install script verified by our team located here: https://github.com/golangci/golangci-lint/blob/master/install.sh
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/b90551cdf9c6214075f2a40d1b5595c6b41ffff0/install.sh | sh -s -- -b ${GOBIN} v1.32.2
$(GOIMPORTS):
$(GO) get -u golang.org/x/tools/cmd/goimports
$(GOCOVMERGE):
$(GO) get -u github.com/wadey/gocovmerge
$(GOCOVXML):
$(GO) get -u github.com/AlekSi/gocov-xml
$(GOCOV):
$(GO) get -u github.com/axw/gocov/gocov
$(RICHGO):
$(GO) get -u github.com/kyoh86/richgo
$(MAKEDOC):
$(GO) get -u github.com/paulbes/makedoc
$(STATIK):
$(GO) get -u github.com/rakyll/statik
$(GOFUMPT):
$(GO) get -u mvdan.cc/gofumpt
GO := $(shell command -v go 2> /dev/null)
ifndef GO
$(error go is required, please install)
endif
PKGS = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./...))
FILES = $(shell find . -name '.?*' -prune -o -name vendor -prune -o -name '*.go' -print)
## Release
release-local: $(GORELEASER)
$(GORELEASER) release --config=.goreleaser-local.yml --snapshot --skip-publish --rm-dist
## Generate
generate: $(STATIK)
$(GO) generate
## Format
fmt: $(GOFUMPT)
$(GO) fmt $(PKGS)
$(GOFUMPT) -s -w $(FILES)
## Imports
imports: $(GOIMPORTS)
$(foreach gofile,$(FILES),$(GOIMPORTS) -w $(gofile) &&) true
## Linting
lint: $(GOLANGCILINT)
$(GOLANGCILINT) run
## Testing
TIMEOUT = 10m
TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \
'{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \
$(PKGS))
TEST_TARGETS := test-default test-bench test-short test-verbose test-race
test-bench: ARGS=-run=__absolutelynothing__ -bench=.
test-short: ARGS=-short
test-verbose: ARGS=-v
test-race: ARGS=-race
$(TEST_TARGETS): test
check test tests: fmt lint $(RICHGO)
$(GO) test -timeout $(TIMEOUT) $(ARGS) $(TESTPKGS) | tee >(RICHGO_FORCE_COLOR=1 $(RICHGO) testfilter); \
test $${PIPESTATUS[0]} -eq 0
test-update:
$(GO) test ./... -update
integration:
$(GO) test -tags=integration ./...
COVERAGE_MODE = atomic
COVERAGE_PROFILE = $(COVERAGE_DIR)/profile.out
COVERAGE_XML = $(COVERAGE_DIR)/coverage.xml
COVERAGE_HTML = $(COVERAGE_DIR)/index.html
test-coverage-tools: | $(GOCOVMERGE) $(GOCOV) $(GOCOVXML)
test-coverage: COVERAGE_DIR := $(BUILD_DIR)/test/coverage.$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
test-coverage: fmt lint test-coverage-tools
@mkdir -p $(COVERAGE_DIR)/coverage
@for pkg in $(TESTPKGS); do \
go test \
-coverpkg=$$(go list -f '{{ join .Deps "\n" }}' $$pkg | \
grep '^$(MODULE)/' | \
tr '\n' ',')$$pkg \
-covermode=$(COVERAGE_MODE) \
-coverprofile="$(COVERAGE_DIR)/coverage/`echo $$pkg | tr "/" "-"`.cover" $$pkg ;\
done
@$(GOCOVMERGE) $(COVERAGE_DIR)/coverage/*.cover > $(COVERAGE_PROFILE)
@$(GO) tool cover -html=$(COVERAGE_PROFILE) -o $(COVERAGE_HTML)
@$(GOCOV) convert $(COVERAGE_PROFILE) | $(GOCOVXML) > $(COVERAGE_XML)