-
Notifications
You must be signed in to change notification settings - Fork 73
/
Makefile
121 lines (91 loc) · 3.69 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
MODULE = $(shell env GO111MODULE=on $(GO) list -m)
DATE ?= $(shell date +%FT%T%z)
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \
cat $(CURDIR)/.version 2> /dev/null || echo v0)
PKGS = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./... ))
TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \
'{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \
$(PKGS))
BIN = $(CURDIR)/.bin
GOLANGCI_VERSION = v1.52.2
GO = go
TIMEOUT_UNIT = 5m
TIMEOUT_E2E = 20m
V = 0
Q = $(if $(filter 1,$V),,@)
M = $(shell printf "\033[34;1m🐱\033[0m")
export GO111MODULE=on
COMMANDS=$(patsubst cmd/%,%,$(wildcard cmd/*))
BINARIES=$(addprefix bin/,$(COMMANDS))
.PHONY: all
all: fmt $(BINARIES) | $(BIN) ; $(info $(M) building executable…) @ ## Build program binary
$(BIN):
@mkdir -p $@
$(BIN)/%: | $(BIN) ; $(info $(M) building $(PACKAGE)…)
$Q tmp=$$(mktemp -d); \
env GO111MODULE=off GOPATH=$$tmp GOBIN=$(BIN) $(GO) get $(PACKAGE) \
|| ret=$$?; \
rm -rf $$tmp ; exit $$ret
## Linters configuration and targets
# TODO(vdemeester) gofmt and goimports checks (run them with -w and make a diff)
GOLINT = $(BIN)/golint
$(BIN)/golint: PACKAGE=golang.org/x/lint/golint
.PHONY: golint
golint: | $(GOLINT) ; $(info $(M) running golint…) @ ## Run golint
$Q $(GOLINT) -set_exit_status $(PKGS)
.PHONY: vet
vet: | ; $(info $(M) running go vet…) @ ## Run go vet
$Q go vet ./...
INEFFASSIGN = $(BIN)/ineffassign
$(BIN)/ineffassign: PACKAGE=github.com/gordonklaus/ineffassign
.PHONY: ineffassign
ineffassign: | $(INEFFASSIGN) ; $(info $(M) running static ineffassign…) @ ## Run ineffassign
$Q $(INEFFASSIGN) .
STATICCHECK = $(BIN)/staticcheck
$(BIN)/staticcheck: PACKAGE=honnef.co/go/tools/cmd/staticcheck
.PHONY: staticcheck
staticcheck: | $(STATICCHECK) ; $(info $(M) running static check…) @ ## Run staticcheck
$Q $(STATICCHECK) ./...
DUPL = $(BIN)/dupl
$(BIN)/dupl: PACKAGE=github.com/mibk/dupl
.PHONY: dupl
dupl: | $(DUPL) ; $(info $(M) running dupl…) ## Run dupl
$Q $(DUPL)
ERRCHECK = $(BIN)/errcheck
$(BIN)/errcheck: PACKAGE=github.com/kisielk/errcheck
.PHONY: errcheck
errcheck: | $(ERRCHECK) ; $(info $(M) running errcheck…) ## Run errcheck
$Q $(ERRCHECK) ./...
GOLANGCILINT = $(BIN)/golangci-lint
$(BIN)/golangci-lint: ; $(info $(M) getting golangci-lint $(GOLANGCI_VERSION))
cd tools; GOBIN=$(BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_VERSION)
.PHONY: golangci-lint
golangci-lint: | $(GOLANGCILINT) ; $(info $(M) running golangci-lint…) @ ## Run golangci-lint
$Q $(GOLANGCILINT) run --verbose --modules-download-mode=vendor --max-issues-per-linter=0 --max-same-issues=0 --deadline 15m
.PHONY: golangci-lint-check
golangci-lint-check: | $(GOLANGCILINT) ; $(info $(M) Testing if golint has been done…) @ ## Run golangci-lint for build tests CI job
$Q $(GOLANGCILINT) run -j 1 --color=never --deadline 15m
GOIMPORTS = $(BIN)/goimports
$(BIN)/goimports: PACKAGE=golang.org/x/tools/cmd/goimports
.PHONY: goimports
goimports: | $(GOIMPORTS) ; $(info $(M) running goimports…) ## Run goimports
$Q $(GOIMPORTS) -l -e -w pkg cmd test
.PHONY: fmt
fmt: ; $(info $(M) running gofmt…) @ ## Run gofmt on all source files
$Q $(GO) fmt $(PKGS)
.PHONY: cli-docs
cli-docs: ; $(info $(M) generating tkn-results docs) ## Generate tkn-results docs
$(GO) run ./cmd/cli-docs
# Misc
.PHONY: clean
clean: ; $(info $(M) cleaning…) @ ## Cleanup everything
@rm -rf $(BIN)
@rm -rf bin
@rm -rf test/tests.* test/coverage.*
.PHONY: help
help:
@grep -hE '^[ a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-17s\033[0m %s\n", $$1, $$2}'
.PHONY: version
version:
@echo $(VERSION)