ccman 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,268 @@
1
+ #!/bin/bash
2
+
3
+ # 脚本4: 发布状态监控模块
4
+ # 功能: 监控GitHub Actions、NPM发布、GitHub Release状态
5
+
6
+ set -e
7
+
8
+ # 颜色定义
9
+ GREEN='\033[0;32m'
10
+ YELLOW='\033[1;33m'
11
+ RED='\033[0;31m'
12
+ BLUE='\033[0;34m'
13
+ CYAN='\033[0;36m'
14
+ NC='\033[0m'
15
+
16
+ print_success() { echo -e "${GREEN}✅ $1${NC}"; }
17
+ print_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
18
+ print_error() { echo -e "${RED}❌ $1${NC}"; }
19
+ print_info() { echo -e "${BLUE}ℹ️ $1${NC}"; }
20
+ print_check() { echo -e "${CYAN}🔍 $1${NC}"; }
21
+
22
+ # 配置
23
+ REPO_OWNER="2ue"
24
+ REPO_NAME="ccm"
25
+ PACKAGE_NAME="ccman"
26
+ MAX_WAIT_MINUTES=5
27
+ CHECK_INTERVAL=15 # 秒
28
+
29
+ # 获取版本信息
30
+ get_version_info() {
31
+ if [ ! -f "package.json" ]; then
32
+ print_error "package.json 未找到"
33
+ exit 1
34
+ fi
35
+
36
+ local version=$(node -p "require('./package.json').version" 2>/dev/null || echo "")
37
+ if [ -z "$version" ]; then
38
+ print_error "无法读取版本号"
39
+ exit 1
40
+ fi
41
+
42
+ echo "$version"
43
+ }
44
+
45
+ # 获取最新commit ID
46
+ get_latest_commit() {
47
+ git rev-parse HEAD 2>/dev/null || echo "unknown"
48
+ }
49
+
50
+ # 输出监控链接
51
+ show_monitoring_links() {
52
+ local version=$1
53
+ local commit_id=$2
54
+ local tag_name="v$version"
55
+
56
+ print_info "📊 监控链接:"
57
+ echo " 🔗 GitHub Actions: https://github.com/${REPO_OWNER}/${REPO_NAME}/actions"
58
+ echo " 🔗 GitHub Actions (Commit): https://github.com/${REPO_OWNER}/${REPO_NAME}/commit/${commit_id}/checks"
59
+ echo " 🔗 NPM Package: https://www.npmjs.com/package/${PACKAGE_NAME}"
60
+ echo " 🔗 NPM Version: https://www.npmjs.com/package/${PACKAGE_NAME}/v/${version}"
61
+ echo " 🔗 GitHub Releases: https://github.com/${REPO_OWNER}/${REPO_NAME}/releases"
62
+ echo " 🔗 GitHub Release: https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/tag/${tag_name}"
63
+ echo ""
64
+ }
65
+
66
+ # 检查GitHub Actions状态
67
+ check_github_actions() {
68
+ local max_attempts=$((MAX_WAIT_MINUTES * 60 / CHECK_INTERVAL))
69
+ local attempt=0
70
+
71
+ print_check "监控 GitHub Actions 状态..."
72
+
73
+ while [ $attempt -lt $max_attempts ]; do
74
+ # 检查最新的workflow运行状态
75
+ local api_response=$(curl -s "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/runs?per_page=1" 2>/dev/null || echo "")
76
+
77
+ if [ -n "$api_response" ]; then
78
+ local run_status=$(echo "$api_response" | grep -o '"status":"[^"]*"' | head -1 | cut -d'"' -f4 2>/dev/null || echo "unknown")
79
+ local run_conclusion=$(echo "$api_response" | grep -o '"conclusion":"[^"]*"' | head -1 | cut -d'"' -f4 2>/dev/null || echo "null")
80
+
81
+ case "$run_status" in
82
+ "completed")
83
+ if [ "$run_conclusion" = "success" ]; then
84
+ print_success "GitHub Actions 构建成功! ✨"
85
+ return 0
86
+ else
87
+ print_error "GitHub Actions 构建失败: $run_conclusion ❌"
88
+ return 1
89
+ fi
90
+ ;;
91
+ "in_progress")
92
+ echo -ne "\r${CYAN}🔄 GitHub Actions 运行中... (${attempt}/${max_attempts}) - 状态: $run_status${NC}"
93
+ ;;
94
+ "queued")
95
+ echo -ne "\r${YELLOW}⏳ GitHub Actions 排队中... (${attempt}/${max_attempts})${NC}"
96
+ ;;
97
+ *)
98
+ echo -ne "\r${YELLOW}⏳ 等待 GitHub Actions 启动... (${attempt}/${max_attempts})${NC}"
99
+ ;;
100
+ esac
101
+ else
102
+ echo -ne "\r${YELLOW}⏳ 连接 GitHub API... (${attempt}/${max_attempts})${NC}"
103
+ fi
104
+
105
+ sleep $CHECK_INTERVAL
106
+ ((attempt++))
107
+ done
108
+
109
+ echo # 换行
110
+ print_warning "GitHub Actions 检查超时 (${MAX_WAIT_MINUTES}分钟)"
111
+ return 2
112
+ }
113
+
114
+ # 检查NPM包发布状态
115
+ check_npm_package() {
116
+ local version=$1
117
+ local max_attempts=$((MAX_WAIT_MINUTES * 60 / CHECK_INTERVAL))
118
+ local attempt=0
119
+
120
+ print_check "监控 NPM 包发布状态..."
121
+
122
+ while [ $attempt -lt $max_attempts ]; do
123
+ # 检查NPM包版本
124
+ local npm_response=$(curl -s "https://registry.npmjs.org/${PACKAGE_NAME}" 2>/dev/null || echo "")
125
+
126
+ if [ -n "$npm_response" ]; then
127
+ # 检查是否包含目标版本
128
+ if echo "$npm_response" | grep -q "\"$version\""; then
129
+ print_success "NPM 包 v$version 发布成功! 📦"
130
+ return 0
131
+ fi
132
+ fi
133
+
134
+ echo -ne "\r${CYAN}📦 等待 NPM 包发布... (${attempt}/${max_attempts})${NC}"
135
+ sleep $CHECK_INTERVAL
136
+ ((attempt++))
137
+ done
138
+
139
+ echo # 换行
140
+ print_warning "NPM 包检查超时 (${MAX_WAIT_MINUTES}分钟)"
141
+ return 2
142
+ }
143
+
144
+ # 检查GitHub Release状态
145
+ check_github_release() {
146
+ local version=$1
147
+ local tag_name="v$version"
148
+ local max_attempts=$((MAX_WAIT_MINUTES * 60 / CHECK_INTERVAL))
149
+ local attempt=0
150
+
151
+ print_check "监控 GitHub Release 状态..."
152
+
153
+ while [ $attempt -lt $max_attempts ]; do
154
+ # 检查GitHub Release
155
+ local release_response=$(curl -s "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${tag_name}" 2>/dev/null || echo "")
156
+
157
+ if [ -n "$release_response" ] && ! echo "$release_response" | grep -q '"message":"Not Found"'; then
158
+ # 检查release状态
159
+ local release_draft=$(echo "$release_response" | grep -o '"draft":[^,}]*' | cut -d':' -f2 2>/dev/null || echo "true")
160
+
161
+ if [ "$release_draft" = "false" ]; then
162
+ print_success "GitHub Release v$version 创建成功! 🎉"
163
+ return 0
164
+ else
165
+ echo -ne "\r${YELLOW}📝 GitHub Release 为草稿状态... (${attempt}/${max_attempts})${NC}"
166
+ fi
167
+ else
168
+ echo -ne "\r${CYAN}🎯 等待 GitHub Release 创建... (${attempt}/${max_attempts})${NC}"
169
+ fi
170
+
171
+ sleep $CHECK_INTERVAL
172
+ ((attempt++))
173
+ done
174
+
175
+ echo # 换行
176
+ print_warning "GitHub Release 检查超时 (${MAX_WAIT_MINUTES}分钟)"
177
+ return 2
178
+ }
179
+
180
+ # 状态图标映射函数
181
+ get_status_icon() {
182
+ case $1 in
183
+ 0) echo "✅" ;;
184
+ 1) echo "❌" ;;
185
+ 2) echo "⏳" ;;
186
+ *) echo "❓" ;;
187
+ esac
188
+ }
189
+
190
+ # 生成发布总结
191
+ generate_summary() {
192
+ local version=$1
193
+ local actions_status=$2
194
+ local npm_status=$3
195
+ local release_status=$4
196
+
197
+ echo ""
198
+ echo "📋 发布监控总结"
199
+ echo "================"
200
+
201
+ echo " 版本: v$version"
202
+ echo " GitHub Actions: $(get_status_icon $actions_status)"
203
+ echo " NPM 包发布: $(get_status_icon $npm_status)"
204
+ echo " GitHub Release: $(get_status_icon $release_status)"
205
+ echo ""
206
+
207
+ # 整体状态判断
208
+ if [ $actions_status -eq 0 ] && [ $npm_status -eq 0 ] && [ $release_status -eq 0 ]; then
209
+ print_success "🎉 发布完全成功!所有组件都已正常发布"
210
+ return 0
211
+ elif [ $actions_status -eq 1 ]; then
212
+ print_error "❌ 发布失败:GitHub Actions 构建失败"
213
+ return 1
214
+ elif [ $actions_status -eq 2 ] || [ $npm_status -eq 2 ] || [ $release_status -eq 2 ]; then
215
+ print_warning "⏳ 发布可能仍在进行中,建议稍后手动检查"
216
+ return 2
217
+ else
218
+ print_warning "⚠️ 发布部分成功,请检查失败的组件"
219
+ return 3
220
+ fi
221
+ }
222
+
223
+ # 主函数: 监控发布状态
224
+ monitor_release() {
225
+ local version=$(get_version_info)
226
+ local commit_id=$(get_latest_commit)
227
+
228
+ echo "📊 CCM 发布状态监控器"
229
+ echo "===================="
230
+ print_info "版本: v$version"
231
+ print_info "提交: ${commit_id:0:8}"
232
+ print_info "超时: ${MAX_WAIT_MINUTES} 分钟"
233
+ echo ""
234
+
235
+ # 显示监控链接
236
+ show_monitoring_links "$version" "$commit_id"
237
+
238
+ # 检查curl是否可用
239
+ if ! command -v curl &> /dev/null; then
240
+ print_error "curl 未安装,无法进行状态检查"
241
+ print_info "请手动访问上述链接检查发布状态"
242
+ return 1
243
+ fi
244
+
245
+ # 并行监控各个状态
246
+ print_info "开始监控发布状态... (最长等待 ${MAX_WAIT_MINUTES} 分钟)"
247
+ echo ""
248
+
249
+ # 检查GitHub Actions
250
+ check_github_actions
251
+ local actions_status=$?
252
+
253
+ # 检查NPM包发布
254
+ check_npm_package "$version"
255
+ local npm_status=$?
256
+
257
+ # 检查GitHub Release
258
+ check_github_release "$version"
259
+ local release_status=$?
260
+
261
+ # 生成总结报告
262
+ generate_summary "$version" $actions_status $npm_status $release_status
263
+ }
264
+
265
+ # 如果直接运行此脚本
266
+ if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
267
+ monitor_release "$@"
268
+ fi
@@ -0,0 +1,265 @@
1
+ #!/bin/bash
2
+
3
+ # 脚本2: 版本提升模块
4
+ # 功能: 智能选择和执行版本号升级
5
+
6
+ set -e
7
+
8
+ # 颜色定义
9
+ GREEN='\033[0;32m'
10
+ YELLOW='\033[1;33m'
11
+ RED='\033[0;31m'
12
+ BLUE='\033[0;34m'
13
+ NC='\033[0m'
14
+
15
+ print_success() { echo -e "${GREEN}✅ $1${NC}"; }
16
+ print_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
17
+ print_error() { echo -e "${RED}❌ $1${NC}"; }
18
+ print_info() { echo -e "${BLUE}ℹ️ $1${NC}"; }
19
+
20
+ # 获取当前版本
21
+ get_current_version() {
22
+ if [ ! -f "package.json" ]; then
23
+ print_error "package.json 未找到"
24
+ exit 1
25
+ fi
26
+
27
+ current_version=$(node -p "require('./package.json').version" 2>/dev/null || echo "")
28
+ if [ -z "$current_version" ]; then
29
+ print_error "无法读取当前版本号"
30
+ exit 1
31
+ fi
32
+
33
+ echo "$current_version"
34
+ }
35
+
36
+ # 计算版本预览
37
+ calculate_version_preview() {
38
+ local version_type=$1
39
+ local preview=$(pnpm version $version_type --dry-run 2>/dev/null)
40
+ if [ $? -eq 0 ] && [ -n "$preview" ]; then
41
+ echo "$preview" | sed 's/^v//' 2>/dev/null || echo "计算失败"
42
+ else
43
+ echo "计算失败"
44
+ fi
45
+ }
46
+
47
+ # 分析git提交推荐版本类型
48
+ analyze_commit_history() {
49
+ local commits=$(git log --oneline -10 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "")
50
+ local suggested_type="patch"
51
+
52
+ if [[ $commits == *"breaking"* ]] || [[ $commits == *"major"* ]]; then
53
+ suggested_type="major"
54
+ elif [[ $commits == *"feat"* ]] || [[ $commits == *"feature"* ]] || [[ $commits == *"add"* ]]; then
55
+ suggested_type="minor"
56
+ fi
57
+
58
+ echo "$suggested_type"
59
+ }
60
+
61
+ # 主函数: 版本选择和升级
62
+ version_bump() {
63
+ local current_version=$(get_current_version)
64
+ local version_type=${1:-""}
65
+
66
+ # 安静模式检测:如果被其他脚本调用,则静默运行
67
+ if [ "$0" != "${BASH_SOURCE[0]}" ] || [ "$version_type" = "test" ]; then
68
+ # 静默模式:只返回结果,不显示菜单
69
+ if [ -n "$version_type" ] && [ "$version_type" != "test" ]; then
70
+ execute_version_bump_quiet "$version_type" "$current_version"
71
+ return $?
72
+ else
73
+ # 测试模式,只返回当前版本
74
+ echo "$current_version"
75
+ return 0
76
+ fi
77
+ fi
78
+
79
+ echo "📦 CCM 版本管理器"
80
+ echo "=================="
81
+ print_info "当前版本: $current_version"
82
+ echo ""
83
+
84
+ # 如果已指定版本类型,直接执行
85
+ if [ -n "$version_type" ] && [ "$version_type" != "test" ]; then
86
+ execute_version_bump "$version_type" "$current_version"
87
+ return $?
88
+ fi
89
+
90
+ # 获取智能推荐
91
+ local suggested_type=$(analyze_commit_history)
92
+
93
+ # 显示版本选择菜单
94
+ show_version_menu "$current_version" "$suggested_type"
95
+
96
+ # 获取用户选择
97
+ read -p "请选择版本升级类型 (1-5, 回车默认选择推荐): " choice
98
+
99
+ # 处理用户选择
100
+ case ${choice:-""} in
101
+ 1|"")
102
+ if [ "$suggested_type" == "patch" ]; then
103
+ version_type="patch"
104
+ elif [ "$suggested_type" == "minor" ]; then
105
+ version_type="minor"
106
+ else
107
+ version_type="major"
108
+ fi
109
+ ;;
110
+ 2) version_type="patch" ;;
111
+ 3) version_type="minor" ;;
112
+ 4) version_type="major" ;;
113
+ 5) handle_custom_version ;;
114
+ *)
115
+ print_error "无效选择"
116
+ exit 1
117
+ ;;
118
+ esac
119
+
120
+ # 确认升级
121
+ confirm_version_bump "$version_type" "$current_version"
122
+
123
+ # 执行升级
124
+ execute_version_bump "$version_type" "$current_version"
125
+ }
126
+
127
+ # 显示版本选择菜单
128
+ show_version_menu() {
129
+ local current_version=$1
130
+ local suggested_type=$2
131
+
132
+ print_info "版本升级选项:"
133
+ echo ""
134
+
135
+ # 计算各版本预览
136
+ local patch_version=$(calculate_version_preview "patch")
137
+ local minor_version=$(calculate_version_preview "minor")
138
+ local major_version=$(calculate_version_preview "major")
139
+
140
+ # 显示推荐标记
141
+ local patch_mark=""
142
+ local minor_mark=""
143
+ local major_mark=""
144
+
145
+ case $suggested_type in
146
+ "patch") patch_mark="✨ [推荐] " ;;
147
+ "minor") minor_mark="✨ [推荐] " ;;
148
+ "major") major_mark="✨ [推荐] " ;;
149
+ esac
150
+
151
+ echo "1) ${patch_mark}🔧 Patch (修订版本) $current_version → $patch_version"
152
+ echo " └─ 适用于: bug修复、小改进"
153
+ echo ""
154
+ echo "2) ${minor_mark}✨ Minor (次版本) $current_version → $minor_version"
155
+ echo " └─ 适用于: 新功能、向后兼容改动"
156
+ echo ""
157
+ echo "3) ${major_mark}🚀 Major (主版本) $current_version → $major_version"
158
+ echo " └─ 适用于: 破坏性更改、重大重构"
159
+ echo ""
160
+ echo "4) 📝 Custom (自定义版本)"
161
+ echo " └─ 手动输入版本号"
162
+ echo ""
163
+
164
+ # 显示推荐原因
165
+ case $suggested_type in
166
+ "major")
167
+ print_warning "💡 检测到破坏性更改提交,建议主版本升级"
168
+ ;;
169
+ "minor")
170
+ print_warning "💡 检测到新功能提交,建议次版本升级"
171
+ ;;
172
+ "patch")
173
+ print_info "💡 建议修订版本升级"
174
+ ;;
175
+ esac
176
+ echo ""
177
+ }
178
+
179
+ # 处理自定义版本
180
+ handle_custom_version() {
181
+ read -p "请输入自定义版本号 (格式: x.y.z): " custom_version
182
+
183
+ # 验证版本号格式
184
+ if [[ ! $custom_version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+(\.[0-9]+)?)?$ ]]; then
185
+ print_error "版本号格式不正确,应为 x.y.z 格式"
186
+ exit 1
187
+ fi
188
+
189
+ version_type="$custom_version"
190
+ }
191
+
192
+ # 确认版本升级
193
+ confirm_version_bump() {
194
+ local version_type=$1
195
+ local current_version=$2
196
+
197
+ if [[ "$version_type" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
198
+ local new_version="$version_type"
199
+ else
200
+ local new_version=$(calculate_version_preview "$version_type")
201
+ fi
202
+
203
+ echo ""
204
+ print_info "即将执行版本升级: $current_version → $new_version"
205
+ read -p "确认升级版本? (Y/n): " -n 1 -r
206
+ echo
207
+
208
+ if [[ $REPLY =~ ^[Nn]$ ]]; then
209
+ print_warning "版本升级已取消"
210
+ exit 0
211
+ fi
212
+ }
213
+
214
+ # 执行版本升级(静默模式)
215
+ execute_version_bump_quiet() {
216
+ local version_type=$1
217
+ local current_version=$2
218
+
219
+ # 执行版本升级
220
+ if [[ "$version_type" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
221
+ # 自定义版本
222
+ new_version=$(pnpm version "$version_type" --no-git-tag-version 2>/dev/null)
223
+ else
224
+ # 标准版本类型
225
+ new_version=$(pnpm version "$version_type" --no-git-tag-version 2>/dev/null)
226
+ fi
227
+
228
+ if [ $? -eq 0 ]; then
229
+ new_version=${new_version#v}
230
+ echo "$new_version" # 输出新版本号供其他脚本使用
231
+ else
232
+ exit 1
233
+ fi
234
+ }
235
+
236
+ # 执行版本升级(交互模式)
237
+ execute_version_bump() {
238
+ local version_type=$1
239
+ local current_version=$2
240
+
241
+ print_info "执行版本升级..."
242
+
243
+ # 执行版本升级
244
+ if [[ "$version_type" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
245
+ # 自定义版本
246
+ new_version=$(pnpm version "$version_type" --no-git-tag-version 2>/dev/null)
247
+ else
248
+ # 标准版本类型
249
+ new_version=$(pnpm version "$version_type" --no-git-tag-version 2>/dev/null)
250
+ fi
251
+
252
+ if [ $? -eq 0 ]; then
253
+ new_version=${new_version#v}
254
+ print_success "版本升级成功: $current_version → $new_version"
255
+ echo "$new_version" # 输出新版本号供其他脚本使用
256
+ else
257
+ print_error "版本升级失败"
258
+ exit 1
259
+ fi
260
+ }
261
+
262
+ # 如果直接运行此脚本
263
+ if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
264
+ version_bump "$@"
265
+ fi
@@ -97,4 +97,4 @@ echo " GitHub Actions: https://github.com/2ue/ccm/actions"
97
97
  echo " GitHub Release: https://github.com/2ue/ccm/releases/tag/v$new_version"
98
98
  echo ""
99
99
  print_info "📦 NPM 包将在 GitHub Actions 完成后发布:"
100
- echo " https://www.npmjs.com/package/ccm"
100
+ echo " https://www.npmjs.com/package/ccman"
@@ -392,10 +392,10 @@ show_release_summary() {
392
392
  print_info "🔗 相关链接:"
393
393
  echo " GitHub Release: https://github.com/2ue/ccm/releases/tag/$tag_name"
394
394
  echo " GitHub Actions: https://github.com/2ue/ccm/actions"
395
- echo " NPM 包 (稍后发布): https://www.npmjs.com/package/ccm"
395
+ echo " NPM 包 (稍后发布): https://www.npmjs.com/package/ccman"
396
396
  echo ""
397
397
  print_info "📦 安装命令 (发布完成后):"
398
- echo " npm install -g ccm@$new_version"
398
+ echo " npm install -g ccman@$new_version"
399
399
  echo ""
400
400
  }
401
401