-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
133 lines (117 loc) · 4.35 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
#! /usr/bin/make -f
# Project variables.
PROJECT_NAME = 'ignite apps'
## goget: Run go get for all apps.
goget:
@echo Running go get $(REPO)...
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running go get $(REPO) in $$dir"; \
cd "$$dir" && go get $(REPO); \
fi \
done
## modtidy: Run go mod tidy for all apps.
modtidy:
@echo Running go mod tidy...
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running go mod tidy in $$dir"; \
cd "$$dir" && go mod tidy; \
fi \
done
## govet: Run go vet for all apps.
govet:
@echo Running go vet...
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running go vet in $$dir"; \
cd "$$dir" && go vet ./...; \
fi \
done
## govulncheck: Run govulncheck for all apps.
govulncheck:
@command -v govulncheck >/dev/null 2>&1 || { \
echo "Installing govulncheck..."; \
go install golang.org/x/vuln/cmd/govulncheck@latest; \
}
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running go vet in $$dir"; \
cd "$$dir" && govulncheck ./...; \
fi \
done
@echo Running govulncheck...
## lint: Run Golang Lint for all apps.
lint:
@command -v golangci-lint >/dev/null 2>&1 || { \
echo "Installing golangci-lint..."; \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.60.3; \
}
@echo Running golangci-lint...
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running golangci-lint in $$dir"; \
cd "$$dir" && golangci-lint run; \
fi \
done
## lint-ci: Run Golang CI Lint for all apps.
lint-ci:
@command -v golangci-lint >/dev/null 2>&1 || { \
echo "Installing golangci-lint..."; \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.60.3; \
}
@echo Running golangci-lint...
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running golangci-lint in $$dir"; \
cd "$$dir" && golangci-lint run --out-format=tab --issues-exit-code=0; \
fi \
done
## ci: Run CI pipeline govet, govulncheck and lint
ci: govet govulncheck lint-ci
## format: Install and run goimports and gofumpt for all apps.
format:
@echo Formatting...
@command -v gofumpt >/dev/null 2>&1 || { \
echo "Installing gofumpt..."; \
go install mvdan.cc/gofumpt@latest; \
}
@command -v goimports >/dev/null 2>&1 || { \
echo "Installing goimports..."; \
go install golang.org/x/tools/cmd/goimports@latest; \
}
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running format in $$dir"; \
cd "$$dir" && gofumpt -w .; \
cd "$$dir" && goimports -w -local github.com/ignite/apps .; \
fi \
done
.PHONY: govet format lint
## test-unit: Run unit tests for all apps.
test-unit:
@echo Running unit tests...
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d -not -path '*/integration*'); do \
if [ -e "$$dir/go.mod" ]; then \
echo "Running unit tests in $$dir"; \
cd "$$dir" && go test -race -failfast -v -coverpkg=./... $(go list ./... | grep -v integration); \
fi \
done
## test-integration: Run the integration tests.
test-integration:
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
if [ -e "$$dir/go.mod" ] && [ -d "$$dir/integration" ]; then \
echo "Running integration tests in $$dir"; \
cd "$$dir" && go test -race -failfast -v -timeout 60m ./integration/...; \
fi \
done
## test: Run unit and integration tests.
test: govet govulncheck test-unit test-integration
.PHONY: test-unit test-integration test
help: Makefile
@echo
@echo "\n Choose a command run in "$(PROJECT_NAME)", or just run 'make' for install\n"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
.PHONY: help