-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
79 lines (63 loc) · 1.31 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
# Go
GO = go
GOFMT = gofmt
GOFMT_FILES = $(shell find . -name '*.go' | grep -v vendor)
GOMOD = $(GO) mod
GOTEST = $(GO) test
GOCLEAN = $(GO) clean
# OS
RM = rm -f
ECHO = /bin/echo
# first rule is default rule
default: test
# run tests
test: fmtcheck deps
@$(ECHO) "==> $@"
$(GOTEST)
# format go code
fmt:
@$(ECHO) "==> $@"
$(GOFMT) -w $(GOFMT_FILES)
# check if code has been formatted
fmtcheck:
@$(ECHO) "==> $@"
@files=$$($(GOFMT) -l $(GOFMT_FILES)) ; \
if [[ -n $${files} ]]; then \
$(ECHO) "error: file(s) not gofmt formatted:" ; \
$(ECHO) "$${files}" ; \
$(ECHO) "run: 'make fmt' to reformat file(s)" ; \
exit 1 ; \
fi
# tidy go modules
tidy: deps
@$(ECHO) "==> $@"
$(GOMOD) tidy
# verify modules
verify:
@$(ECHO) "==> $@"
$(GOMOD) verify
# download modules to pre-fill the cache
deps:
@$(ECHO) "==> $@"
$(GOMOD) download
# clean
clean:
@$(ECHO) "==> $@"
$(GOCLEAN) -i
# remove build cache
cleaner: clean
@$(ECHO) "==> $@"
$(GOCLEAN) -cache
# remove module cache
cleanest: cleaner test-clean
@$(ECHO) "==> $@"
$(GOCLEAN) --modcache
# remove test cache
test-clean:
@$(ECHO) "==> $@"
$(GOCLEAN) -testcache
# store local copies of external dependenciew
vendor: deps
@$(ECHO) "==> $@"
$(GOMOD) vendor
.PHONY: test fmt fmtcheck tidy verify deps clean cleaner cleanest test-clean vendor