-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
71 lines (60 loc) · 2.07 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
GO := go
ROOT_PACKAGE := github.com/seacraft/licctl
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: test format lint
## test: Test the package.
.PHONY: test
test:
@echo "===========> Testing packages"
@$(GO) test $(ROOT_PACKAGE)/...
.PHONY: goimports.verify
goimports.verify:
ifeq (,$(shell which goimports 2>/dev/null))
@echo "===========> Installing goimports"
@$(GO) install golang.org/x/tools/cmd/[email protected]
endif
.PHONY: golines.verify
golines.verify:
ifeq (,$(shell which golines 2>/dev/null))
@echo "===========> Installing golines"
@$(GO) install github.com/segmentio/[email protected]
endif
## format: Format the package with `gofmt`
.PHONY: format
format: golines.verify goimports.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"
@$(GO) install github.com/golangci/golangci-lint/cmd/[email protected]
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: updates.verify
updates.verify:
ifeq (,$(shell which go-mod-outdated 2>/dev/null))
@echo "===========> Installing go-mod-outdated"
@$(GO) install github.com/psampaz/[email protected]
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"