-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
161 lines (121 loc) · 3.99 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
go ?= go
gofmt ?= $(go)fmt
pkgs = ./...
npm ?= npm
npx ?= npx
help: Makefile
@echo
@echo " Choose a command run in Sloth:"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
## install_revive: Install revive for linting.
.PHONY: install_revive
install_revive:
@echo ">> ============= Install Revive ============= <<"
$(go) install github.com/mgechev/revive@latest
## style: Check code style.
.PHONY: style
style:
@echo ">> ============= Checking Code Style ============= <<"
@fmtRes=$$($(gofmt) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
if [ -n "$${fmtRes}" ]; then \
echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
echo "Please ensure you are using $$($(go) version) for formatting code."; \
exit 1; \
fi
## check_license: Check if license header on all files.
.PHONY: check_license
check_license:
@echo ">> ============= Checking License Header ============= <<"
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
done); \
if [ -n "$${licRes}" ]; then \
echo "license header checking failed:"; echo "$${licRes}"; \
exit 1; \
fi
## test_short: Run test cases with short flag.
.PHONY: test_short
test_short:
@echo ">> ============= Running Short Tests ============= <<"
$(go) clean -testcache
$(go) test -mod=readonly -short $(pkgs)
## test: Run test cases.
.PHONY: test
test:
@echo ">> ============= Running All Tests ============= <<"
$(go) clean -testcache
$(go) test -mod=readonly -run=Unit -bench=. -benchmem -v -cover $(pkgs)
## integration: Run integration test cases (Requires etcd)
.PHONY: integration
integration:
@echo ">> ============= Running All Tests ============= <<"
$(go) clean -testcache
$(go) test -mod=readonly -run=Integration -bench=. -benchmem -v -cover $(pkgs)
## lint: Lint the code.
.PHONY: lint
lint:
@echo ">> ============= Lint All Files ============= <<"
revive -config config.toml -exclude vendor/... -formatter friendly ./...
## verify: Verify dependencies
.PHONY: verify
verify:
@echo ">> ============= List Dependencies ============= <<"
$(go) list -m all
@echo ">> ============= Verify Dependencies ============= <<"
$(go) mod verify
## format: Format the code.
.PHONY: format
format:
@echo ">> ============= Formatting Code ============= <<"
$(go) fmt $(pkgs)
## vet: Examines source code and reports suspicious constructs.
.PHONY: vet
vet:
@echo ">> ============= Vetting Code ============= <<"
$(go) vet $(pkgs)
## coverage: Create HTML coverage report
.PHONY: coverage
coverage:
@echo ">> ============= Coverage ============= <<"
rm -f coverage.html cover.out
$(go) test -mod=readonly -coverprofile=cover.out $(pkgs)
go tool cover -html=cover.out -o coverage.html
## serve_ui: Serve admin dashboard
.PHONY: serve_ui
serve_ui:
@echo ">> ============= Run Vuejs App ============= <<"
cd web;$(npm) run serve
## build_ui: Builds admin dashboard for production
.PHONY: build_ui
build_ui:
@echo ">> ============= Build Vuejs App ============= <<"
cd web;$(npm) install;$(npm) run build
## check_ui_format: Check dashboard code format
.PHONY: check_ui_format
check_ui_format:
@echo ">> ============= Validate js format ============= <<"
cd web;$(npx) prettier --check .
## format_ui: Format dashboard code
.PHONY: format_ui
format_ui:
@echo ">> ============= Format js Code ============= <<"
cd web;$(npx) prettier --write .
## package: Package assets
.PHONY: package
package:
@echo ">> ============= Package Assets ============= <<"
-rm $(shell pwd)/web/.env
echo "CHIMPMUNK_DASHBOARD_URL=" > $(shell pwd)/web/.env.dist
cd web;$(npm) run build
## run: Run the Server
.PHONY: run
run:
@echo ">> ============= Run API Server ============= <<"
$(go) run sloth.go server -c config.dist.yml
## ci: Run all CI tests.
.PHONY: ci
ci: style check_license test vet lint
@echo "\n==> All quality checks passed"
.PHONY: help