-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
67 lines (53 loc) · 1.94 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
SHELL=/bin/bash -o pipefail
.DEFAULT_GOAL := help
PACKAGE := github.com/tier4/x
GO := go
GOPATH := $(shell go env GOPATH)
GOMODCACHE=$(shell go env GOMODCACHE)
GOBIN := $(abspath .bin)
GOTEST := $(or $(GOTEST),$(GO) test)
GOIMPORTSFLAGS := -local $(PACKAGE)
export GO111MODULE := on
export PATH := $(GOBIN):${PATH}
GO_DEPENDENCIES = golang.org/x/tools/cmd/goimports@master \
github.com/golangci/golangci-lint/cmd/[email protected]
define make-go-dependency
# go install is responsible for not re-building when the code hasn't changed
.bin/$(firstword $(subst @, ,$(notdir $1))): go.mod go.sum Makefile
GOBIN=$(GOBIN) go install $1
endef
$(foreach dep, $(GO_DEPENDENCIES), $(eval $(call make-go-dependency, $(dep))))
$(call make-lint-dependency)
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
OPEN := xdg-open
else ifeq ($(UNAME),Darwin)
OPEN := open
endif
.PHONY: deps
deps: ## download dependencies
find . -name go.mod -execdir $(GO) mod download \;
find . -name go.mod -execdir $(GO) mod tidy \;
.PHONY: test
test: unit-test ## test all
.PHONY: unit-test
unit-test: ## unit test
find . -name go.mod -execdir $(GOTEST) -failfast -cover -count=1 -race ./... \;
.PHONY: clean
clean: ## clean bin and cache
rm -rf ./.bin
$(GO) clean -testcache
.PHONY: fmt
fmt: .bin/goimports ## format source
find . -name go.mod -execdir goimports $(GOIMPORTSFLAGS) -w . \;
find . -name go.mod -execdir $(GO) mod tidy \;
.PHONY: golangci-lint
golangci-lint: .bin/golangci-lint ## Exec golangci-lint
find . -name go.mod -execdir golangci-lint run ./... \;
.PHONY: lint
lint: golangci-lint ## exec lint
# https://gist.github.com/tadashi-aikawa/da73d277a3c1ec6767ed48d1335900f3
.PHONY: $(shell grep -h -E '^[a-zA-Z_-]+:' $(MAKEFILE_LIST) | sed 's/://')
# https://postd.cc/auto-documented-makefile/
help: ## Show help message
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'