forked from gocronx-team/gocron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
344 lines (299 loc) · 9.09 KB
/
makefile
File metadata and controls
344 lines (299 loc) · 9.09 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
GO111MODULE=on
# 版本信息
VERSION ?= $(shell git describe --tags --always --dirty)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
BUILD_DATE ?= $(shell date '+%Y-%m-%d %H:%M:%S')
LDFLAGS = -w -X 'main.AppVersion=$(VERSION)' -X 'main.BuildDate=$(BUILD_DATE)' -X 'main.GitCommit=$(GIT_COMMIT)'
# 构建目录
BIN_DIR = bin
PACKAGE_DIR = packages
# 默认目标
.DEFAULT_GOAL := build
# 本地构建
.PHONY: build
build: gocron node
.PHONY: build-race
build-race: enable-race build
.PHONY: run
run: build kill
./$(BIN_DIR)/gocron-node &
./$(BIN_DIR)/gocron web -e dev
.PHONY: run-with-packages
run-with-packages: build-web package-all kill
./$(BIN_DIR)/gocron-node &
./$(BIN_DIR)/gocron web -e dev
.PHONY: run-race
run-race: enable-race run
.PHONY: kill
kill:
-killall gocron-node
.PHONY: gocron
gocron:
@mkdir -p $(BIN_DIR)
go build $(RACE) -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/gocron ./cmd/gocron
.PHONY: node
node:
@mkdir -p $(BIN_DIR)
CGO_ENABLED=0 go build $(RACE) -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/gocron-node ./cmd/node
.PHONY: test
test:
go test $(RACE) ./...
.PHONY: test-race
test-race: enable-race test
.PHONY: enable-race
enable-race:
$(eval RACE = -race)
# 多平台打包
.PHONY: package
package: build-web
@echo "Building packages for current platform..."
bash ./package.sh
.PHONY: package-linux
package-linux: build-web
@echo "Building packages for Linux..."
bash ./package.sh -p linux -a "amd64,arm64"
.PHONY: package-linux-nosqlite
package-linux-nosqlite: build-web
@echo "Building Linux packages without SQLite..."
CGO_ENABLED=0 bash ./package.sh -p linux -a "amd64,arm64"
.PHONY: package-darwin
package-darwin: build-web
@echo "Building packages for macOS..."
bash ./package.sh -p darwin -a "amd64,arm64"
.PHONY: package-windows
package-windows: build-web
@echo "Building packages for Windows..."
bash ./package.sh -p windows -a "amd64"
.PHONY: package-all
package-all: build-web
@echo "Building packages for all platforms..."
bash ./package.sh -p "linux,darwin" -a "amd64,arm64"
bash ./package.sh -p "windows" -a "amd64"
# 前端构建
.PHONY: build-vue
build-vue:
@echo "Installing Vue dependencies..."
@if [ -f web/vue/pnpm-lock.yaml ]; then \
echo "Using pnpm..."; \
cd web/vue && pnpm install; \
elif [ -f web/vue/yarn.lock ]; then \
echo "Using yarn..."; \
cd web/vue && yarn install; \
else \
echo "Using npm..."; \
cd web/vue && npm install; \
fi
@echo "Building Vue frontend..."
@if [ -f web/vue/pnpm-lock.yaml ]; then \
cd web/vue && pnpm run build; \
elif [ -f web/vue/yarn.lock ]; then \
cd web/vue && yarn run build; \
else \
cd web/vue && npm run build; \
fi
@echo "✅ Vue build complete! Files will be embedded during Go build."
.PHONY: install-vue
install-vue:
@echo "Installing Vue dependencies..."
@if [ -f web/vue/pnpm-lock.yaml ]; then \
cd web/vue && pnpm install; \
elif [ -f web/vue/yarn.lock ]; then \
cd web/vue && yarn install; \
else \
cd web/vue && npm install; \
fi
.PHONY: run-vue
run-vue:
@echo "Starting Vue dev server..."
@if [ -f web/vue/pnpm-lock.yaml ]; then \
cd web/vue && pnpm run dev; \
elif [ -f web/vue/yarn.lock ]; then \
cd web/vue && yarn run dev; \
else \
cd web/vue && npm run dev; \
fi
.PHONY: build-web
build-web: build-vue
@echo "Web build complete!"
# 代码质量检查
.PHONY: check
check: fmt vet test
@echo "✅ All checks passed!"
.PHONY: lint
lint:
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run || echo "⚠️ Linter found issues (non-blocking)"; \
else \
echo "⚠️ golangci-lint not installed, skipping..."; \
echo " Install: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
.PHONY: fmt
fmt:
@echo "Formatting code..."
@find . -name '*.go' -exec gofmt -w {} \;
.PHONY: fmt-check
fmt-check:
@echo "Checking code formatting..."
@unformatted=$$(gofmt -l .); \
if [ -n "$$unformatted" ]; then \
echo "❌ Code not formatted:" && echo "$$unformatted" && echo "Run 'make fmt' to fix" && exit 1; \
fi
@echo "✅ Code formatting OK"
.PHONY: vet
vet:
@echo "Running go vet..."
@go vet ./...
@echo "✅ go vet passed"
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
@go test -cover -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "✅ Coverage report generated: coverage.html"
.PHONY: security
security:
@echo "Running security checks..."
@if command -v gosec >/dev/null 2>&1; then \
gosec ./... || echo "⚠️ Security issues found (non-blocking)"; \
else \
echo "⚠️ gosec not installed, skipping..."; \
echo " Install: go install github.com/securego/gosec/v2/cmd/gosec@latest"; \
fi
# 预发布检查(完整检查)
.PHONY: pre-release
pre-release: clean
@echo "=========================================="
@echo "Running pre-release checks..."
@echo "=========================================="
@$(MAKE) fmt-check
@$(MAKE) vet
@$(MAKE) test
@echo ""
@echo "=========================================="
@echo "✅ All pre-release checks passed!"
@echo "=========================================="
@echo ""
@echo "Optional checks (run manually if needed):"
@echo " make lint - Code quality linter"
@echo " make security - Security vulnerability scan"
# 清理
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
-rm -rf $(BIN_DIR)
-rm -rf $(PACKAGE_DIR)
-rm -rf gocron-package
-rm -rf gocron-node-package
-rm -rf gocron-build
-rm -rf gocron-node-build
-rm -f coverage.out coverage.html
.PHONY: clean-web
clean-web:
@echo "Cleaning web build artifacts..."
-rm -rf web/vue/dist
-rm -rf web/public/static
-rm -f web/public/index.html
# 开发工具
.PHONY: dev-deps
dev-deps:
@echo "Installing development dependencies..."
go install github.com/cosmtrek/air@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest
# 版本管理
.PHONY: version
version:
@echo "Current version: $(VERSION)"
@echo "Recent releases:"
@git tag -l "v*.*.*" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | sort -V | tail -5
.PHONY: release
release:
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION is required. Usage: make release VERSION=v1.3.18"; \
exit 1; \
fi
@echo "Creating release $(VERSION)..."
@if git rev-parse $(VERSION) >/dev/null 2>&1; then \
echo "Error: Tag $(VERSION) already exists!"; \
exit 1; \
fi
@git tag -a $(VERSION) -m "Release $(VERSION)"
@git push origin $(VERSION)
@echo "✅ Release $(VERSION) created and pushed successfully!"
.PHONY: release-patch
release-patch:
@echo "Creating patch release..."
@$(MAKE) release VERSION=$$($(MAKE) next-patch)
.PHONY: release-minor
release-minor:
@echo "Creating minor release..."
@$(MAKE) release VERSION=$$($(MAKE) next-minor)
.PHONY: release-major
release-major:
@echo "Creating major release..."
@$(MAKE) release VERSION=$$($(MAKE) next-major)
.PHONY: next-patch
next-patch:
@latest=$$(git tag -l "v*.*.*" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | sort -V | tail -1); \
if [ -z "$$latest" ]; then \
echo "v1.0.0"; \
else \
echo $$latest | sed 's/^v//' | awk -F. '{printf "v%d.%d.%d", $$1, $$2, $$3+1}'; \
fi
.PHONY: next-minor
next-minor:
@latest=$$(git tag -l "v*.*.*" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | sort -V | tail -1); \
if [ -z "$$latest" ]; then \
echo "v1.0.0"; \
else \
echo $$latest | sed 's/^v//' | awk -F. '{printf "v%d.%d.0", $$1, $$2+1}'; \
fi
.PHONY: next-major
next-major:
@latest=$$(git tag -l "v*.*.*" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | sort -V | tail -1); \
if [ -z "$$latest" ]; then \
echo "v1.0.0"; \
else \
echo $$latest | sed 's/^v//' | awk -F. '{printf "v%d.0.0", $$1+1}'; \
fi
.PHONY: delete-tag
delete-tag:
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION is required. Usage: make delete-tag VERSION=v1.3.18"; \
exit 1; \
fi
@echo "Deleting tag $(VERSION)..."
@git tag -d $(VERSION)
@git push origin :refs/tags/$(VERSION)
@echo "✅ Tag $(VERSION) deleted locally and remotely"
# 帮助信息
.PHONY: help
help:
@echo "Available targets:"
@echo ""
@echo "Build:"
@echo " build - Build gocron and gocron-node for current platform"
@echo " run - Build and run in development mode"
@echo " test - Run tests"
@echo " package-all - Build packages for all platforms"
@echo ""
@echo "Code Quality:"
@echo " check - Run fmt + vet + test"
@echo " pre-release - Run all checks before release"
@echo " fmt - Format code"
@echo " fmt-check - Check code formatting"
@echo " vet - Run go vet"
@echo " lint - Run linter (golangci-lint)"
@echo " test-coverage - Run tests with coverage report"
@echo " security - Run security checks (gosec)"
@echo ""
@echo "Version Management:"
@echo " version - Show current version"
@echo " release - Create release tag (VERSION=v1.3.18)"
@echo " release-patch - Auto increment patch version"
@echo ""
@echo "Development:"
@echo " dev-deps - Install development dependencies"
@echo " clean - Clean build artifacts"
@echo " help - Show this help message"