@sokeai/cli 1.0.1 → 1.0.3
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.
- package/package.json +1 -1
- package/scripts/e2e-test.sh +207 -0
- package/scripts/push.sh +107 -0
- package/scripts/release.sh +15 -5
package/package.json
CHANGED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# soke-cli 端到端测试脚本
|
|
4
|
+
# 测试所有命令是否能正常执行
|
|
5
|
+
# 支持按模块测试: ./e2e-test.sh [module_name]
|
|
6
|
+
|
|
7
|
+
# 注意:不使用 set -e,让所有测试都能运行完
|
|
8
|
+
|
|
9
|
+
# 颜色输出
|
|
10
|
+
RED='\033[0;31m'
|
|
11
|
+
GREEN='\033[0;32m'
|
|
12
|
+
YELLOW='\033[1;33m'
|
|
13
|
+
BLUE='\033[0;34m'
|
|
14
|
+
NC='\033[0m'
|
|
15
|
+
|
|
16
|
+
# 测试结果统计
|
|
17
|
+
TOTAL_TESTS=0
|
|
18
|
+
PASSED_TESTS=0
|
|
19
|
+
FAILED_TESTS=0
|
|
20
|
+
FAILED_COMMANDS=()
|
|
21
|
+
|
|
22
|
+
# 获取版本号
|
|
23
|
+
VERSION=$(node -p "require('./package.json').version")
|
|
24
|
+
|
|
25
|
+
# 获取要测试的模块(如果指定)
|
|
26
|
+
TEST_MODULE=$1
|
|
27
|
+
|
|
28
|
+
echo -e "${BLUE}========================================${NC}"
|
|
29
|
+
if [ -z "$TEST_MODULE" ]; then
|
|
30
|
+
echo -e "${BLUE} soke-cli E2E 测试 v${VERSION}${NC}"
|
|
31
|
+
else
|
|
32
|
+
echo -e "${BLUE} soke-cli E2E 测试 - ${TEST_MODULE} 模块${NC}"
|
|
33
|
+
fi
|
|
34
|
+
echo -e "${BLUE}========================================${NC}"
|
|
35
|
+
echo ""
|
|
36
|
+
|
|
37
|
+
# 检查是否已编译
|
|
38
|
+
if [ ! -f "./soke-cli" ]; then
|
|
39
|
+
echo -e "${YELLOW}未找到编译文件,开始编译...${NC}"
|
|
40
|
+
go build -o soke-cli main.go
|
|
41
|
+
echo -e "${GREEN}✓ 编译完成${NC}"
|
|
42
|
+
echo ""
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# 检查是否已登录
|
|
46
|
+
echo -e "${YELLOW}检查登录状态...${NC}"
|
|
47
|
+
if ! ./soke-cli config show &>/dev/null; then
|
|
48
|
+
echo -e "${RED}错误: 未配置或未登录${NC}"
|
|
49
|
+
echo "请先运行: ./soke-cli config init && ./soke-cli auth login"
|
|
50
|
+
exit 1
|
|
51
|
+
fi
|
|
52
|
+
echo -e "${GREEN}✓ 已登录${NC}"
|
|
53
|
+
echo ""
|
|
54
|
+
|
|
55
|
+
# 测试函数
|
|
56
|
+
test_command() {
|
|
57
|
+
local module=$1
|
|
58
|
+
local command=$2
|
|
59
|
+
local args=$3
|
|
60
|
+
local description=$4
|
|
61
|
+
|
|
62
|
+
TOTAL_TESTS=$((TOTAL_TESTS + 1))
|
|
63
|
+
|
|
64
|
+
echo -n "测试 [$module $command]: $description ... "
|
|
65
|
+
|
|
66
|
+
if ./soke-cli $module $command $args &>/dev/null; then
|
|
67
|
+
echo -e "${GREEN}✓ 通过${NC}"
|
|
68
|
+
PASSED_TESTS=$((PASSED_TESTS + 1))
|
|
69
|
+
return 0
|
|
70
|
+
else
|
|
71
|
+
echo -e "${RED}✗ 失败${NC}"
|
|
72
|
+
FAILED_TESTS=$((FAILED_TESTS + 1))
|
|
73
|
+
FAILED_COMMANDS+=("$module $command $args")
|
|
74
|
+
return 1
|
|
75
|
+
fi
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
# 判断是否应该运行某个模块的测试
|
|
79
|
+
should_test_module() {
|
|
80
|
+
local module=$1
|
|
81
|
+
if [ -z "$TEST_MODULE" ]; then
|
|
82
|
+
return 0 # 没有指定模块,测试所有
|
|
83
|
+
elif [ "$TEST_MODULE" = "$module" ]; then
|
|
84
|
+
return 0 # 指定的模块匹配
|
|
85
|
+
else
|
|
86
|
+
return 1 # 不匹配,跳过
|
|
87
|
+
fi
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
echo -e "${BLUE}开始测试...${NC}"
|
|
91
|
+
echo ""
|
|
92
|
+
|
|
93
|
+
# ==================== Contact 模块 ====================
|
|
94
|
+
if should_test_module "contact"; then
|
|
95
|
+
echo -e "${YELLOW}[Contact 模块]${NC}"
|
|
96
|
+
test_command "contact" "+list-departments" "" "获取部门列表"
|
|
97
|
+
test_command "contact" "+get-department" "--dept-id 1" "获取部门详情"
|
|
98
|
+
test_command "contact" "+list-department-users" "--dept-id 1" "获取部门用户列表"
|
|
99
|
+
test_command "contact" "+list-lectors" "" "获取讲师列表"
|
|
100
|
+
test_command "contact" "+list-groups" "--start-time 1672502400000 --end-time 1704038400000" "获取用户组列表"
|
|
101
|
+
test_command "contact" "+search-user" "--dept-user-name 测试" "搜索用户"
|
|
102
|
+
echo ""
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
# ==================== Course 模块 ====================
|
|
106
|
+
if should_test_module "course"; then
|
|
107
|
+
echo -e "${YELLOW}[Course 模块]${NC}"
|
|
108
|
+
test_command "course" "+list-courses" "--start-time 1672502400000 --end-time 1704038400000" "获取课程列表"
|
|
109
|
+
test_command "course" "+list-categories" "" "获取课程分类"
|
|
110
|
+
test_command "course" "+list-lessons" "--course-id F4025496-6566-4ACD-8CD4-06E3D55BBA79" "获取课程章节"
|
|
111
|
+
echo ""
|
|
112
|
+
fi
|
|
113
|
+
|
|
114
|
+
# ==================== Exam 模块 ====================
|
|
115
|
+
if should_test_module "exam"; then
|
|
116
|
+
echo -e "${YELLOW}[Exam 模块]${NC}"
|
|
117
|
+
test_command "exam" "+list-exams" "--start-time 1672502400000 --end-time 1704038400000" "获取考试列表"
|
|
118
|
+
test_command "exam" "+list-categories" "" "获取考试分类"
|
|
119
|
+
echo ""
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
# ==================== Certificate 模块 ====================
|
|
123
|
+
if should_test_module "certificate"; then
|
|
124
|
+
echo -e "${YELLOW}[Certificate 模块]${NC}"
|
|
125
|
+
test_command "certificate" "+list-certificates" "--start-time 1672502400000 --end-time 1704038400000" "获取证书列表"
|
|
126
|
+
test_command "certificate" "+list-categories" "" "获取证书分类"
|
|
127
|
+
echo ""
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
# ==================== Credit 模块 ====================
|
|
131
|
+
if should_test_module "credit"; then
|
|
132
|
+
echo -e "${YELLOW}[Credit 模块]${NC}"
|
|
133
|
+
test_command "credit" "+list-logs" "--start-time 1672502400000 --end-time 1704038400000" "获取学分日志"
|
|
134
|
+
echo ""
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
# ==================== Point 模块 ====================
|
|
138
|
+
if should_test_module "point"; then
|
|
139
|
+
echo -e "${YELLOW}[Point 模块]${NC}"
|
|
140
|
+
test_command "point" "+list-logs" "--start-time 1672502400000 --end-time 1704038400000" "获取积分日志"
|
|
141
|
+
echo ""
|
|
142
|
+
fi
|
|
143
|
+
|
|
144
|
+
# ==================== Training 模块 ====================
|
|
145
|
+
if should_test_module "training"; then
|
|
146
|
+
echo -e "${YELLOW}[Training 模块]${NC}"
|
|
147
|
+
test_command "training" "+list-trainings" "--start-time 1672502400000 --end-time 1704038400000" "获取培训列表"
|
|
148
|
+
test_command "training" "+list-categories" "" "获取培训分类"
|
|
149
|
+
echo ""
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
# ==================== Learning Map 模块 ====================
|
|
153
|
+
if should_test_module "learning-map"; then
|
|
154
|
+
echo -e "${YELLOW}[Learning Map 模块]${NC}"
|
|
155
|
+
test_command "learning-map" "+list-maps" "--start-time 1672502400000 --end-time 1704038400000" "获取学习地图列表"
|
|
156
|
+
test_command "learning-map" "+list-categories" "" "获取学习地图分类"
|
|
157
|
+
echo ""
|
|
158
|
+
fi
|
|
159
|
+
|
|
160
|
+
# ==================== News 模块 ====================
|
|
161
|
+
if should_test_module "news"; then
|
|
162
|
+
echo -e "${YELLOW}[News 模块]${NC}"
|
|
163
|
+
test_command "news" "+list-news" "" "获取新闻列表"
|
|
164
|
+
test_command "news" "+list-categories" "" "获取新闻分类"
|
|
165
|
+
echo ""
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
# ==================== Clock 模块 ====================
|
|
169
|
+
if should_test_module "clock"; then
|
|
170
|
+
echo -e "${YELLOW}[Clock 模块]${NC}"
|
|
171
|
+
test_command "clock" "list-learnings" "--page 1 --page-size 10" "获取作业列表"
|
|
172
|
+
echo ""
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
# ==================== File 模块 ====================
|
|
176
|
+
if should_test_module "file"; then
|
|
177
|
+
echo -e "${YELLOW}[File 模块]${NC}"
|
|
178
|
+
test_command "file" "list-files" "" "获取素材库列表"
|
|
179
|
+
test_command "file" "list-categories" "" "获取素材库分类"
|
|
180
|
+
echo ""
|
|
181
|
+
fi
|
|
182
|
+
|
|
183
|
+
# ==================== 测试结果汇总 ====================
|
|
184
|
+
echo ""
|
|
185
|
+
echo -e "${BLUE}========================================${NC}"
|
|
186
|
+
echo -e "${BLUE} 测试结果汇总${NC}"
|
|
187
|
+
echo -e "${BLUE}========================================${NC}"
|
|
188
|
+
echo ""
|
|
189
|
+
echo -e "总测试数: ${BLUE}${TOTAL_TESTS}${NC}"
|
|
190
|
+
echo -e "通过: ${GREEN}${PASSED_TESTS}${NC}"
|
|
191
|
+
echo -e "失败: ${RED}${FAILED_TESTS}${NC}"
|
|
192
|
+
echo ""
|
|
193
|
+
|
|
194
|
+
if [ ${FAILED_TESTS} -gt 0 ]; then
|
|
195
|
+
echo -e "${RED}失败的命令:${NC}"
|
|
196
|
+
for cmd in "${FAILED_COMMANDS[@]}"; do
|
|
197
|
+
echo -e " ${RED}✗${NC} ./soke-cli $cmd"
|
|
198
|
+
done
|
|
199
|
+
echo ""
|
|
200
|
+
echo -e "${RED}测试失败! 请修复以上问题后再发布。${NC}"
|
|
201
|
+
exit 1
|
|
202
|
+
else
|
|
203
|
+
echo -e "${GREEN}========================================${NC}"
|
|
204
|
+
echo -e "${GREEN} 所有测试通过! ✓${NC}"
|
|
205
|
+
echo -e "${GREEN}========================================${NC}"
|
|
206
|
+
exit 0
|
|
207
|
+
fi
|
package/scripts/push.sh
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# 授客CLI双远程仓库推送脚本
|
|
4
|
+
# 用途:将代码同时推送到 GitHub 和 Aliyun 远程仓库
|
|
5
|
+
|
|
6
|
+
set -e # 遇到错误立即退出
|
|
7
|
+
|
|
8
|
+
# 颜色定义
|
|
9
|
+
RED='\033[0;31m'
|
|
10
|
+
GREEN='\033[0;32m'
|
|
11
|
+
YELLOW='\033[1;33m'
|
|
12
|
+
NC='\033[0m' # No Color
|
|
13
|
+
|
|
14
|
+
# 打印带颜色的信息
|
|
15
|
+
print_info() {
|
|
16
|
+
echo -e "${GREEN}[信息]${NC} $1"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
print_warning() {
|
|
20
|
+
echo -e "${YELLOW}[警告]${NC} $1"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
print_error() {
|
|
24
|
+
echo -e "${RED}[错误]${NC} $1"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# 获取当前分支名
|
|
28
|
+
CURRENT_BRANCH=$(git branch --show-current)
|
|
29
|
+
|
|
30
|
+
# 显示当前分支并确认
|
|
31
|
+
echo ""
|
|
32
|
+
print_info "当前所在分支: ${GREEN}${CURRENT_BRANCH}${NC}"
|
|
33
|
+
echo ""
|
|
34
|
+
read -p "是否在当前分支提交代码?(y/n): " confirm
|
|
35
|
+
|
|
36
|
+
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
|
|
37
|
+
print_warning "用户取消操作,脚本退出"
|
|
38
|
+
exit 0
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# 执行 git add .
|
|
42
|
+
print_info "正在暂存所有更改..."
|
|
43
|
+
git add .
|
|
44
|
+
|
|
45
|
+
# 检查是否有需要提交的更改
|
|
46
|
+
if git diff --cached --quiet; then
|
|
47
|
+
print_warning "没有需要提交的更改"
|
|
48
|
+
exit 0
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
# 提示输入 commit 信息
|
|
52
|
+
echo ""
|
|
53
|
+
read -p "请输入 commit 信息: " commit_info
|
|
54
|
+
|
|
55
|
+
if [[ -z "$commit_info" ]]; then
|
|
56
|
+
print_error "commit 信息不能为空"
|
|
57
|
+
exit 1
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
# 执行 commit
|
|
61
|
+
print_info "正在提交代码..."
|
|
62
|
+
git commit -m "$commit_info"
|
|
63
|
+
|
|
64
|
+
# 保存当前分支名(用于后续合并)
|
|
65
|
+
FEATURE_BRANCH=$CURRENT_BRANCH
|
|
66
|
+
|
|
67
|
+
# 切换到 master 分支
|
|
68
|
+
print_info "切换到 master 分支..."
|
|
69
|
+
git checkout master
|
|
70
|
+
|
|
71
|
+
# 合并功能分支到 master
|
|
72
|
+
print_info "合并 ${FEATURE_BRANCH} 到 master..."
|
|
73
|
+
git merge $FEATURE_BRANCH
|
|
74
|
+
|
|
75
|
+
# 推送到 origin (Aliyun) 的 master 分支
|
|
76
|
+
print_info "推送到 Aliyun 远程仓库 (origin master)..."
|
|
77
|
+
git push origin master
|
|
78
|
+
|
|
79
|
+
# 推送到 github 的 master 分支
|
|
80
|
+
print_info "推送到 GitHub 远程仓库 (github master)..."
|
|
81
|
+
git push github master
|
|
82
|
+
|
|
83
|
+
# 切换到 main 分支
|
|
84
|
+
print_info "切换到 main 分支..."
|
|
85
|
+
git checkout main
|
|
86
|
+
|
|
87
|
+
# 合并 master 到 main
|
|
88
|
+
print_info "合并 master 到 main..."
|
|
89
|
+
git merge master
|
|
90
|
+
|
|
91
|
+
# 推送到 github 的 main 分支
|
|
92
|
+
print_info "推送到 GitHub 远程仓库 (github main)..."
|
|
93
|
+
git push github main
|
|
94
|
+
|
|
95
|
+
# 切换回原分支
|
|
96
|
+
print_info "切换回原分支 ${FEATURE_BRANCH}..."
|
|
97
|
+
git checkout $FEATURE_BRANCH
|
|
98
|
+
|
|
99
|
+
echo ""
|
|
100
|
+
print_info "✅ 代码推送完成!"
|
|
101
|
+
echo ""
|
|
102
|
+
print_info "推送摘要:"
|
|
103
|
+
echo " - 功能分支: ${FEATURE_BRANCH}"
|
|
104
|
+
echo " - Commit 信息: ${commit_info}"
|
|
105
|
+
echo " - Aliyun (origin): master 分支已更新"
|
|
106
|
+
echo " - GitHub (github): master 和 main 分支已更新"
|
|
107
|
+
echo ""
|
package/scripts/release.sh
CHANGED
|
@@ -75,14 +75,24 @@ check_tag() {
|
|
|
75
75
|
|
|
76
76
|
# 运行测试
|
|
77
77
|
run_tests() {
|
|
78
|
-
echo -e "${YELLOW}
|
|
78
|
+
echo -e "${YELLOW}运行单元测试...${NC}"
|
|
79
79
|
|
|
80
80
|
if ! go test ./...; then
|
|
81
|
-
echo -e "${RED}错误:
|
|
81
|
+
echo -e "${RED}错误: 单元测试失败${NC}"
|
|
82
82
|
exit 1
|
|
83
83
|
fi
|
|
84
84
|
|
|
85
|
-
echo -e "${GREEN}✓
|
|
85
|
+
echo -e "${GREEN}✓ 单元测试通过${NC}"
|
|
86
|
+
echo ""
|
|
87
|
+
|
|
88
|
+
echo -e "${YELLOW}运行端到端测试...${NC}"
|
|
89
|
+
|
|
90
|
+
if ! ./scripts/e2e-test.sh; then
|
|
91
|
+
echo -e "${RED}错误: 端到端测试失败${NC}"
|
|
92
|
+
exit 1
|
|
93
|
+
fi
|
|
94
|
+
|
|
95
|
+
echo -e "${GREEN}✓ 端到端测试通过${NC}"
|
|
86
96
|
echo ""
|
|
87
97
|
}
|
|
88
98
|
|
|
@@ -189,8 +199,8 @@ main() {
|
|
|
189
199
|
echo -e "NPM: ${BLUE}https://www.npmjs.com/package/@sokeai/cli${NC}"
|
|
190
200
|
echo -e "GitHub: ${BLUE}https://github.com/sokeai/soke-cli/releases/tag/v${VERSION}${NC}"
|
|
191
201
|
echo ""
|
|
192
|
-
echo "
|
|
193
|
-
echo -e "${YELLOW}npm install -g @sokeai/cli${NC}"
|
|
202
|
+
echo "安装或升级到最新版本:"
|
|
203
|
+
echo -e "${YELLOW}npm install -g @sokeai/cli@latest${NC}"
|
|
194
204
|
}
|
|
195
205
|
|
|
196
206
|
# 确认发布
|