-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (99 loc) · 3.05 KB
/
Copy pathMakefile
File metadata and controls
116 lines (99 loc) · 3.05 KB
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
GOCMD=GO111MODULE=on CGO_ENABLED=0 go
GOBUILD=${GOCMD} build
.PHONY: init
# Initialize environment
init:
pre-commit install
go install github.com/google/go-licenses@latest
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6
go install github.com/google/wire/cmd/wire@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install github.com/envoyproxy/protoc-gen-validate@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
.PHONY: generate
# Generate all
generate: proto api wire
.PHONY: version
# Show the generated version
version:
@find app -type d -depth 1 -print | xargs -L 1 bash -c 'echo "version: $$0" && cd "$$0" && $(MAKE) version'
.PHONY: wire
# Generate wire
wire:
@find app -type d -depth 1 -print | xargs -L 1 bash -c 'echo "wire: $$0" && cd "$$0" && $(MAKE) wire'
.PHONY: proto
# Generate internal proto pb.go files.
proto:
buf generate
.PHONY: api
# Generate api/client and api/server pb.go files.
api:
buf generate --template=buf.gen.client.yaml
buf generate --template=buf.gen.server.yaml
.PHONY: build
# Build app execute file. Use app=app_name to build specific service.
build:
@if [ -z "$(app)" ]; then \
find app -type d -depth 1 -print | xargs -L 1 bash -c 'echo "build: $$0" && cd "$$0" && $(MAKE) build'; \
else \
echo "build: app/$(app)" && cd app/$(app) && $(MAKE) build; \
fi
.PHONY: run
# Start all project services and tail log.
run: start log
.PHONY: start
# Start all app services. Use app=app_name to start specific service.
start: stop build
@if [ -z "$(app)" ]; then \
find app -type d -depth 1 -print | xargs -L 1 bash -c 'echo "start: $$0" && cd "$$0" && $(MAKE) start'; \
else \
echo "start: app/$(app)" && cd app/$(app) && $(MAKE) start; \
fi
.PHONY: stop
# Stop all app services. Use app=app_name to stop specific service.
stop:
@if [ -z "$(app)" ]; then \
find app -type d -depth 1 -print | xargs -L 1 bash -c 'echo "stop: $$0" && cd "$$0" && $(MAKE) stop'; \
else \
echo "stop: app/$(app)" && cd app/$(app) && $(MAKE) stop; \
fi
.PHONY: log
# Tail app service log file
log:
echo "log: app/gate" && cd app/gate && tail -20f bin/debug.log
.PHONY: test
# Run tests and show coverage.
test:
go test -race -cover ./...
.PHONY: vet
# Run go vet.
vet:
go vet ./...
.PHONY: license-check
# Run license check.
license-check:
go-licenses check ./...
.PHONY: lint
# Run lint.
lint:
golangci-lint run ./...
# Show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help