Skip to content

Commit f8a5d39

Browse files
committed
fix(workflow): 优化自动更新参数处理逻辑
- 将手动触发输入参数合并为 update_mode 选项,支持 auto、force、skip 三种模式 - 用 switch-case 替代原有多个布尔开关判断,简化逻辑 - auto 模式执行内容哈希检查决定是否跳过更新 - force 模式强制跳过哈希检查执行更新 - skip 模式直接跳过所有更新操作 - 保持计划任务触发时的默认哈希差异检测逻辑不变
1 parent 642b5b2 commit f8a5d39

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

.github/workflows/auto-update.yml

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ on:
1111
- cron: '30 2 * * *'
1212
workflow_dispatch: # 允许手动触发
1313
inputs:
14-
skip_update:
15-
description: Skip update check and force skip all operations
14+
update_mode:
15+
description: 'Update mode: auto (check hash), force (skip hash check), skip (no update)'
1616
required: false
17-
default: 'false'
18-
type: boolean
19-
force_update:
20-
description: Force update even if no changes detected
21-
required: false
22-
default: 'false'
23-
type: boolean
17+
default: auto
18+
type: choice
19+
options:
20+
- auto
21+
- force
22+
- skip
2423

2524
jobs:
2625
auto-update:
@@ -59,25 +58,29 @@ jobs:
5958
# 检查触发方式和用户输入参数
6059
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
6160
echo "Manual trigger detected"
61+
UPDATE_MODE="${{ github.event.inputs.update_mode }}"
6262
63-
# 检查用户是否选择跳过更新
64-
if [ "${{ github.event.inputs.skip_update }}" = "true" ]; then
65-
echo "User chose to skip update check, skipping all operations"
66-
echo "skip=true" >> $GITHUB_OUTPUT
67-
elif [ "${{ github.event.inputs.force_update }}" = "true" ]; then
68-
echo "User chose to force update, skipping hash check"
69-
echo "skip=false" >> $GITHUB_OUTPUT
70-
else
71-
echo "User chose default behavior, checking for updates..."
72-
# 使用TypeScript脚本进行哈希差异检查,避免shell参数过长问题
73-
if pnpm run diff-hash; then
74-
echo "No update needed, content hash is the same"
63+
case "$UPDATE_MODE" in
64+
"skip")
65+
echo "User chose to skip all operations"
7566
echo "skip=true" >> $GITHUB_OUTPUT
76-
else
77-
echo "Update needed, content hash is different or error occurred"
67+
;;
68+
"force")
69+
echo "User chose to force update, skipping hash check"
7870
echo "skip=false" >> $GITHUB_OUTPUT
79-
fi
80-
fi
71+
;;
72+
"auto"|*)
73+
echo "User chose auto mode, checking for updates..."
74+
# 使用TypeScript脚本进行哈希差异检查,避免shell参数过长问题
75+
if pnpm run diff-hash; then
76+
echo "No update needed, content hash is the same"
77+
echo "skip=true" >> $GITHUB_OUTPUT
78+
else
79+
echo "Update needed, content hash is different or error occurred"
80+
echo "skip=false" >> $GITHUB_OUTPUT
81+
fi
82+
;;
83+
esac
8184
else
8285
echo "Scheduled trigger detected, checking for updates..."
8386
# 使用TypeScript脚本进行哈希差异检查,避免shell参数过长问题

0 commit comments

Comments
 (0)