-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathMakefile
82 lines (69 loc) · 2.73 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
GO := go
ROOT_PACKAGE := github.com/marmotedu/marmotedu-sdk-go
ifeq ($(origin ROOT_DIR),undefined)
ROOT_DIR := $(shell pwd)
endif
# Linux command settings
FIND := find . ! -path './third_party/*' ! -path './vendor/*'
XARGS := xargs --no-run-if-empty
all: verify-copyright test format lint
## test: Test the package.
.PHONY: test
test:
@echo "===========> Testing packages"
@$(GO) test $(ROOT_PACKAGE)/...
.PHONY: golines.verify
golines.verify:
ifeq (,$(shell which golines 2>/dev/null))
@echo "===========> Installing golines"
@$(GO) get -u github.com/segmentio/golines
endif
## format: Format the package with `gofmt`
.PHONY: format
format: golines.verify
@echo "===========> Formating codes"
@$(FIND) -type f -name '*.go' | $(XARGS) gofmt -s -w
@$(FIND) -type f -name '*.go' | $(XARGS) goimports -w -local $(ROOT_PACKAGE)
@$(FIND) -type f -name '*.go' | $(XARGS) golines -w --max-len=120 --reformat-tags --shorten-comments --ignore-generated .
.PHONY: lint.verify
lint.verify:
ifeq (,$(shell which golangci-lint 2>/dev/null))
@echo "===========> Installing golangci lint"
@GO111MODULE=off $(GO) get -u github.com/golangci/golangci-lint/cmd/golangci-lint
endif
## lint: Check syntax and styling of go sources.
.PHONY: lint
lint: lint.verify
@echo "===========> Run golangci to lint source codes"
@golangci-lint run $(ROOT_DIR)/...
.PHONY: copyright.verify
copyright.verify:
ifeq (,$(shell which addlicense 2>/dev/null))
@echo "===========> Installing addlicense"
@$(GO) get -u github.com/marmotedu/addlicense
endif
## verify-copyright: Verify the boilerplate headers for all files.
.PHONY: verify-copyright
verify-copyright: copyright.verify
@echo "===========> Verifying the boilerplate headers for all files"
@addlicense --check -f $(ROOT_DIR)/boilerplate.txt $(ROOT_DIR) --skip-dirs=third_party
## add-copyright: Ensures source code files have copyright license headers.
.PHONY: add-copyright
add-copyright: copyright.verify
@addlicense -v -f $(ROOT_DIR)/boilerplate.txt $(ROOT_DIR) --skip-dirs=third_party
.PHONY: updates.verify
updates.verify:
ifeq (,$(shell which go-mod-outdated 2>/dev/null))
@echo "===========> Installing go-mod-outdated"
@$(GO) get -u github.com/psampaz/go-mod-outdated
endif
## check-updates: Check outdated dependencies of the go projects.
.PHONY: check-updates
check-updates: updates.verify
@$(GO) list -u -m -json all | go-mod-outdated -update -direct
## help: Show this help info.
.PHONY: help
help: Makefile
@echo -e "\nUsage: make <TARGETS> ...\n\nTargets:"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo "$$USAGE_OPTIONS"