forked from haierkeys/fast-note-sync-service
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
178 lines (139 loc) · 5.46 KB
/
Copy pathMakefile
File metadata and controls
178 lines (139 loc) · 5.46 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Docker 登录示例
# docker login --username=xxxxxx registry.cn-shanghai.aliyuncs.com
# 环境变量(可选)
# include .env
# export $(shell sed 's/=.*//' .env)
# -------------------------
# 项目 / 镜像 配置
# -------------------------
REPO = $(eval REPO := $$(shell go list -f '{{.ImportPath}}' .))$(value REPO)
DockerHubUser = haierkeys
DockerHubName = fast-note-sync-service
ReleaseTagPre = release-v
DevelopTagPre = develop-v
P_NAME = fast-note-sync
P_BIN = fast-note-sync-service
# -------------------------
# Git / 构建信息
# -------------------------
GitTag = $(shell git describe --tags --abbrev=0)
GitVersion = $(shell git log -1 --format=%h)
GitVersionDesc = $(shell git log -1 --format=%s)
BuildTime = $(shell date +%FT%T%z)
# LDFLAGS: 注入版本信息到二进制
# 获取提交信息,并处理掉换行符(用 @@@ 占位)以便安全地注入到 ldflags
COMMIT_MSG_CLEAN = $(shell echo "$(COMMIT_MSG)" | tr '\n' '^' | sed 's/\^/@@@/g' | sed 's/"/\\"/g' | sed "s/'/’/g")
Changelog ?= $(COMMIT_MSG_CLEAN)
LDFLAGS = -ldflags '-X ${REPO}/internal/app.Version=$(GitTag) -X "${REPO}/internal/app.GitTag=$(GitVersion)" -X ${REPO}/internal/app.BuildTime=$(BuildTime) -X "${REPO}/internal/app.Changelog=$(Changelog)"'
# go 命令封装
gob = go build ${LDFLAGS}
gor = go run ${LDFLAGS}
# 编译相关
CGO = CGO_ENABLED=0
rootDir = $(shell pwd)
buildDir = $(rootDir)/build
# -------------------------
# PHONY 目标
# -------------------------
.PHONY: all build-all run test clean \
push-online push-dev \
build-macos-amd64 build-macos-arm64 build-linux-amd64 \
build-linux-arm64 build-linux-arm build-windows-amd64 gox-linux gox-all \
docs fmt update air dev ver gen sup proto
# 默认目标
all: test build-all
# -------------------------
# 简单目标
# -------------------------
sup:
node scripts/process_support_csv.js
node scripts/process_support.mjs --model Qwen/Qwen3.6-35B-A3B
sup-md:
test:
go test $$(go list ./... | grep -v -E 'internal/service/mocks|internal/domain/mocks|internal/dto|internal/model|internal/query|internal/config|internal/app|/docs|internal/middleware|cmd')
dev:
air -c ./scripts/.air.toml
air:
air -c ./scripts/.air.toml
fmt:
go fmt ./...
update:
go get -u ./...
# 更新版本脚本调用
ver:
@node ./scripts/update-version.js $(filter-out $@,$(MAKECMDGOALS))
# 捕获 ver 后面的参数,防止 make 将其视为目标
%:
@:
proto:
protoc --go_out=. --go_opt=paths=source_relative internal/proto/v1/sync.proto
gen: proto
go run -v ./cmd/gorm_gen/gen.go -type sqlite -dsn storage/database/db_full.sqlite3
go run -v ./cmd/model_gen/gen.go
docs:
go run github.com/swaggo/swag/cmd/swag@latest init -g main.go -o ./docs --parseDependency --parseInternal
# 运行
run:
# $(call checkStatic)
$(call init)
$(gor) -v $(rootDir)
clean:
rm -rf $(buildDir)
# -------------------------
# 构建集合
# -------------------------
build-all:
# $(call checkStatic)
$(MAKE) build-macos-amd64
$(MAKE) build-macos-arm64
$(MAKE) build-linux-amd64
$(MAKE) build-linux-arm64
$(MAKE) build-linux-arm
$(MAKE) build-windows-amd64
# macOS
build-macos-amd64:
$(CGO) GOOS=darwin GOARCH=amd64 $(gob) -o $(buildDir)/darwin_amd64/${P_BIN} $(bin) -v $(rootDir)
build-macos-arm64:
$(CGO) GOOS=darwin GOARCH=arm64 $(gob) -o $(buildDir)/darwin_arm64/${P_BIN} -v $(rootDir)
# Linux
build-linux-amd64:
# CGO_ENABLED=1 CC=musl-gcc GOOS=linux GOARCH=amd64 $(gob) -o $(buildDir)/linux_amd64/${P_BIN} -v $(rootDir)
$(CGO) GOOS=linux GOARCH=amd64 $(gob) -o $(buildDir)/linux_amd64/${P_BIN} -v $(rootDir)
build-linux-arm64:
$(CGO) GOOS=linux GOARCH=arm64 $(gob) -o $(buildDir)/linux_arm64/${P_BIN} -v $(rootDir)
build-linux-arm:
$(CGO) GOOS=linux GOARCH=arm GOARM=7 $(gob) -o $(buildDir)/linux_arm/${P_BIN} -v $(rootDir)
# Windows
build-windows-amd64:
# CGO_ENABLED=0 CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="x86_64-w64-mingw32-gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -lssp" $(gob) -o $(bin).exe -v $(rootDir)
$(CGO) GOOS=windows GOARCH=amd64 $(gob) -o $(buildDir)/windows_amd64/${P_BIN}.exe -v $(rootDir)
# gox 辅助
gox-linux:
$(CGO) GOARM=7 gox ${LDFLAGS} -osarch="linux/amd64 linux/arm64 linux/arm" -output="$(buildDir)/{{.OS}}_{{.Arch}}/${P_BIN}"
gox-all:
$(CGO) GOARM=7 gox ${LDFLAGS} -osarch="darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 linux/arm windows/amd64" -output="$(buildDir)/{{.OS}}_{{.Arch}}/${P_BIN}"
# -------------------------
# Docker 发布
# -------------------------
push-online: build-linux
$(call dockerImageClean)
docker build --platform linux/amd64 -t $(DockerHubUser)/$(DockerHubName):latest -f docker/Dockerfile .
docker tag $(DockerHubUser)/$(DockerHubName):latest $(DockerHubUser)/$(DockerHubName):$(ReleaseTagPre)$(GitTag)
docker push $(DockerHubUser)/$(DockerHubName):$(ReleaseTagPre)$(GitTag)
docker push $(DockerHubUser)/$(DockerHubName):latest
push-dev: build-linux
$(call dockerImageClean)
docker build --platform linux/amd64 -t $(DockerHubUser)/$(DockerHubName):dev-latest -f docker/Dockerfile .
docker tag $(DockerHubUser)/$(DockerHubName):dev-latest $(DockerHubUser)/$(DockerHubName):$(DevelopTagPre)$(GitTag)
docker push $(DockerHubUser)/$(DockerHubName):$(DevelopTagPre)$(GitTag)
docker push $(DockerHubUser)/$(DockerHubName):dev-latest
# -------------------------
# 代码片段(定义)
# -------------------------
define dockerImageClean
@echo "docker Image Clean"
bash docker_image_clean.sh
endef
define init
@echo "Build Init"
endef