-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (126 loc) · 4.42 KB
/
Makefile
File metadata and controls
142 lines (126 loc) · 4.42 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
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
GOHOSTOS:=$(shell go env GOHOSTOS)
GOPATH:=$(shell go env GOPATH)
VERSION?=$(shell git describe --tags --always || echo "dev")
# 定义查找proto文件的函数
define find_proto_files
$(if $(filter windows,$(GOHOSTOS)),\
$(if $(filter MINGW64,$(MSYSTEM)),\
$(shell find $(1) -name *.proto),\
$(shell $(subst \,/,$(subst cmd\git.exe,bin\bash.exe,$(shell where git))) -c "find $(1) -name *.proto")\
),\
$(shell find $(1) -name *.proto)\
)
endef
# 使用函数简化proto文件查找
INTERNAL_PROTO_FILES := $(call find_proto_files,internal)
API_PROTO_FILES := $(call find_proto_files,api)
.PHONY: init
# init env
init:
go install github.com/spf13/cobra-cli@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
go install github.com/google/wire/cmd/wire@latest
.PHONY: config
# generate internal proto
config:
protoc --proto_path=./internal \
--proto_path=./third_party \
--go_out=paths=source_relative:./internal \
$(INTERNAL_PROTO_FILES)
.PHONY: api
# generate api proto
api:
protoc --proto_path=./api \
--proto_path=./third_party \
--go_out=paths=source_relative:./api \
--grpc-gateway_out=paths=source_relative:./api \
--go-grpc_out=paths=source_relative:./api \
--openapi_out=fq_schema_naming=true,default_response=false:. \
$(API_PROTO_FILES)
debug:
dlv debug --headless --listen :8082 --api-version 2 --accept-multiclient . -- server
.PHONY: build
# build
build:
mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...
.PHONY: sync-frontend
# 同步前端代码
sync-frontend:
@echo "Starting to sync frontend code..."
@if [ ! -d "web" ]; then \
mkdir -p web; \
fi;
@echo "Getting the latest release version of the frontend..."
@LATEST_RELEASE=$$(curl -s https://api.github.com/repos/toheart/goanalysis-web/releases/latest | grep "tag_name" | cut -d '"' -f 4); \
if [ -z "$$LATEST_RELEASE" ]; then \
echo "Failed to get the latest release version of the frontend, exiting with error" \
exit 1; \
else \
echo "Obtained the latest release version of the frontend: $$LATEST_RELEASE"; \
DOWNLOAD_URL=$$(curl -s https://api.github.com/repos/toheart/goanalysis-web/releases/latest | grep "browser_download_url.*zip" | cut -d '"' -f 4); \
if [ -z "$$DOWNLOAD_URL" ]; then \
echo "download source code failed, exiting with error"; \
exit 1; \
else \
echo "Downloading release package: $$DOWNLOAD_URL"; \
curl -sL "$$DOWNLOAD_URL" -o dist.zip; \
fi; \
rm -rf dist_temp ;\
unzip -q dist.zip -d dist_temp && cp -r dist_temp/* web/;\
rm -rf dist_temp dist.zip; \
fi;
@echo "Frontend code sync completed."
.PHONY: package-linux
# 打包Linux版本
package-linux: sync-frontend
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.Version=$(VERSION)" -o goanalysis ./
mkdir -p release
mv ./goanalysis ./release/goanalysis-linux-$(VERSION)
.PHONY: package-windows
# 打包Windows版本
package-windows: sync-frontend
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.Version=$(VERSION)" -o goanalysis.exe ./
mkdir -p release
mv ./goanalysis.exe ./release/goanalysis-windows-$(VERSION).exe
.PHONY: docker
# 构建Docker镜像
docker:
@FRONTEND_VERSION=$$(curl -s https://api.github.com/repos/toheart/goanalysis-web/releases/latest | grep "tag_name" | cut -d '"' -f 4 || echo "unknown"); \
echo "使用前端版本: $$FRONTEND_VERSION"; \
docker build -t ghcr.io/toheart/goanalysis:$(VERSION) \
--build-arg VERSION=$(VERSION) \
--build-arg FRONTEND_VERSION=$$FRONTEND_VERSION .
.PHONY: generate
# generate
generate:
go generate ./...
go mod tidy
wire:
cd ./cmd/commands && wire && cd ../..
.PHONY: all
# generate all
all:
make api;
make config;
make generate;
# 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, ":")); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help