-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
165 lines (152 loc) · 5.8 KB
/
makefile
File metadata and controls
165 lines (152 loc) · 5.8 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
# Variables
REMOTE_REPO ?=
COMMIT_MSG ?= "Update project"
# Default target
all: help
# Help target
push: check-remote
@set -e; \
CURRENT_BRANCH=$$(git symbolic-ref --short HEAD); \
echo "🚀 启动自动化发布流程..."; \
echo "▸ 当前工作分支: \033[1;34m$$CURRENT_BRANCH\033[0m"; \
\
echo "🔄 正在提交未保存的变更..."; \
git add . || { echo "❌ 添加文件失败"; exit 1; }; \
if git diff-index --quiet HEAD --; then \
echo "🟢 工作区干净,无待提交变更"; \
else \
git commit -m "🔖 [自动提交] 版本发布前预处理" || { echo "❌ 提交失败"; exit 1; }; \
echo "✅ 变更已提交(提交消息:🔖 [自动提交] 版本发布前预处理)"; \
fi; \
\
echo "🆙 生成新版本标签..."; \
$(MAKE) bump-version || { echo "❌ 版本标签生成失败"; exit 1; }; \
\
echo "📡 同步代码至GitHub..."; \
git push origin $$CURRENT_BRANCH --follow-tags || { echo "❌ 代码/标签推送失败"; exit 1; }; \
\
echo "\n✅ 发布流程完成!以下步骤将自动进行:"; \
echo " 1. GitHub Actions 将触发构建流程(约1-2分钟)"; \
echo " 2. GoReleaser 将生成多平台二进制文件"; \
echo " 3. 新版本文档将自动发布到 GitHub Releases\n"; \
echo "🔗 实时进度查看: https://github.com/package-register/go-genius/actions"; \
echo "🔗 发布结果查看: https://github.com/package-register/go-genius/releases"
check-remote:
@echo "🔍 检查远程仓库配置..."; \
if git remote | grep -q origin; then \
echo "✓ 已配置远程仓库: \033[1;34m$$(git remote get-url origin)\033[0m"; \
else \
echo "❌ 错误:未配置远程仓库"; \
echo "请先执行以下命令配置仓库地址:"; \
echo " \033[1;32mmake add-remote \033[0m<仓库URL>"; \
echo "或通过交互模式配置:\033[1;32mmake add-remote\033[0m"; \
exit 1; \
fi
help:
@echo "\033[1;32mMakefile Usage:\033[0m"
@echo " \033[1;32mmake add-remote\033[0m - 配置/更新Git远程仓库"
@echo " \033[1;32mmake commit\033[0m - 提交变更并选择提交信息"
@echo " \033[1;32mmake push\033[0m - 自动提交、创建新版本并推送到远程仓库"
@echo " \033[1;32mmake bump-version\033[0m - 创建新的语义化版本标签"
@echo " \033[1;32mmake test\033[0m - 运行所有测试"
@echo " \033[1;32mmake clean\033[0m - 清理生成文件"
# Add/update remote repository
add-remote:
@# 捕获并验证URL参数
@$(eval RAW_ARGS := $(filter-out $@,$(MAKECMDGOALS)))
@$(eval REMOTE_REPO := $(shell echo '$(RAW_ARGS)' | grep -Eo '(git@|https?://)[a-zA-Z0-9./:@_-]+'))
@if [ -n "$(REMOTE_REPO)" ]; then \
if git remote | grep -q origin; then \
git remote set-url origin $(REMOTE_REPO) >/dev/null; \
echo "✓ Remote origin updated to: $(REMOTE_REPO)"; \
else \
git remote add origin $(REMOTE_REPO) >/dev/null; \
echo "✓ Remote origin added: $(REMOTE_REPO)"; \
fi; \
exit 0; \
fi; \
@if [ -n "$(RAW_ARGS)" ]; then \
echo "⚠️ Invalid repository URL: '$(RAW_ARGS)'"; \
echo "Valid formats: git@... or https://..."; \
exit 1; \
fi; \
@# 交互模式
@if git remote | grep -q origin; then \
current_url=$$(git remote get-url origin); \
read -p "Current remote: $$current_url\nUpdate? [y/N]: " confirm; \
if [ "$$confirm" = "y" ] || [ "$$confirm" = "Y" ]; then \
read -p "Enter new URL: " REMOTE_REPO; \
git remote set-url origin "$$REMOTE_REPO" >/dev/null; \
echo "✓ Remote URL updated"; \
else \
echo "ℹ️ Keeping existing URL"; \
fi; \
else \
read -p "Enter repository URL: " REMOTE_REPO; \
git remote add origin "$$REMOTE_REPO" >/dev/null; \
echo "✓ Remote origin added"; \
fi;
# Commit changes with a message (include emoji)
commit:
@if [ -z "$$(git status --porcelain)" ]; then \
echo "No changes to commit. Exiting."; \
exit 0; \
fi; \
echo "Select a commit message:"; \
echo "1. 🚀 Initial commit"; \
echo "2. ✨ Add new feature"; \
echo "3. 🐛 Fix bug"; \
echo "4. 📝 Update documentation"; \
echo "5. 🔧 Refactor code"; \
echo "6. 👍 Other"; \
read -rp "Enter your choice (1-6): " choice; \
choice=$$(echo "$$choice" | tr -cd '0-9'); \
if [ -z "$$choice" ]; then \
echo "Invalid input. Exiting."; \
exit 1; \
elif [ "$$choice" -eq 1 ]; then \
COMMIT_MSG="🚀 Initial commit"; \
elif [ "$$choice" -eq 2 ]; then \
COMMIT_MSG="✨ Add new feature"; \
elif [ "$$choice" -eq 3 ]; then \
COMMIT_MSG="🐛 Fix bug"; \
elif [ "$$choice" -eq 4 ]; then \
COMMIT_MSG="📝 Update documentation"; \
elif [ "$$choice" -eq 5 ]; then \
COMMIT_MSG="🔧 Refactor code"; \
elif [ "$$choice" -eq 6 ]; then \
read -rp "Enter custom commit message: " COMMIT_MSG; \
else \
echo "Invalid choice. Exiting."; \
exit 1; \
fi; \
git add .; \
if git commit -m "$$COMMIT_MSG"; then \
echo "Committed changes with message: $$COMMIT_MSG"; \
else \
echo "Commit failed (no changes to commit)."; \
fi
# Bump version number
bump-version:
@LATEST_TAG=$$(git describe --tags --abbrev=0 2>/dev/null); \
if [ -z "$$LATEST_TAG" ]; then \
NEW_VERSION="v0.1.0"; \
else \
NEW_VERSION=$$(echo $$LATEST_TAG | awk -F. '{major=substr($$1,2); print "v"major"."$$2"."($$3+1)}'); \
fi; \
git tag -a $$NEW_VERSION -m "Release $$NEW_VERSION"; \
echo "New version tag $$NEW_VERSION created"
build:
@echo "Building binaries..."
@goreleaser build --snapshot --clean
# Run all tests
test:
@go test ./...
@echo "All tests completed."
# Clean generated files
clean:
@go clean -testcache
@rm -f $(shell find . -name "*.out")
@rm -f $(shell find . -name "*.test")
@rm -f $(shell find . -name "VERSION")
@echo "Cleaned up generated files."