fix(ci): 修复定时构建「无新提交则跳过」逻辑失效
Deploy to Production / pre-check (push) Successful in 42s
Deploy to Production / build (push) Canceled after 11m47s
Deploy to Production / deploy-edgeone (push) Canceled after 0s
Deploy to Production / deploy-upyun (push) Canceled after 0s
Deploy to Production / finalize (push) Canceled after 0s
Deploy to Production / notify-failure (push) Canceled after 0s
Deploy to Production / pre-check (push) Successful in 42s
Deploy to Production / build (push) Canceled after 11m47s
Deploy to Production / deploy-edgeone (push) Canceled after 0s
Deploy to Production / deploy-upyun (push) Canceled after 0s
Deploy to Production / finalize (push) Canceled after 0s
Deploy to Production / notify-failure (push) Canceled after 0s
根因:pre-check job 的 outputs.can_deploy 绑定在 steps.repo-check 上, 而该步骤是无条件写 true;真正写 can_deploy=false 的是 steps.cron-check, 它写进自己步骤的 outputs,从未被 job 级 output 采用。 于是 build 的 if: needs.pre-check.outputs.can_deploy == 'true' 恒为真。 证据(run 8, event=schedule): - 日志 cron-check 已打印「距离上次提交: 9 小时 / 超过 1 小时没有新提交,跳过定时构建」 - 但随后 build 的 if 表达式求值 'steps.repo-check.outputs.can_deploy' 结果为 true,build 照常执行 后果:每天北京 09:00 无条件全量构建(build ~17min + finalize ~12.5min), 2 核服务器被白占约 32 分钟/天。线上不受影响(build hash 未变, COS/EdgeOne/UpYun 上传与部署均正确 skip)。 改动: - 合并 repo-check 与 cron-check 为单一步骤 decide,统一计算并输出 can_deploy - pre-check.outputs.can_deploy 改指向 steps.decide.outputs.can_deploy - 去掉原 cron-check 的 exit 0(避免步骤提前中断导致 output 丢失)
This commit is contained in:
1 parent
83d87ddeaf
commit
6838934fa5
1 file changed
+26
-19
@@ -23,7 +23,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 2
|
||||
outputs:
|
||||
can_deploy: ${{ steps.repo-check.outputs.can_deploy }}
|
||||
can_deploy: ${{ steps.decide.outputs.can_deploy }}
|
||||
duration: ${{ steps.end-pre-check.outputs.duration }}
|
||||
|
||||
steps:
|
||||
@@ -63,27 +63,34 @@ jobs:
|
||||
echo "⚠️ 提交信息格式建议: feat/fix/chore/docs/style/refactor/test: description"
|
||||
fi
|
||||
|
||||
- name: Check for new commits (only for cron)
|
||||
if: github.event_name == 'schedule'
|
||||
id: cron-check
|
||||
- name: Decide whether to deploy
|
||||
id: decide
|
||||
run: |
|
||||
LAST_COMMIT_TIME=$(git log -1 --format=%ct)
|
||||
CURRENT_TIME=$(date +%s)
|
||||
DIFF_HOURS=$(( (CURRENT_TIME - LAST_COMMIT_TIME) / 3600 ))
|
||||
|
||||
echo "⏰ 最后一次提交时间: $(date -d @$LAST_COMMIT_TIME)"
|
||||
echo "⏰ 当前时间: $(date)"
|
||||
echo "⏰ 距离上次提交: $DIFF_HOURS 小时"
|
||||
|
||||
if [ "$DIFF_HOURS" -lt 1 ]; then
|
||||
echo "✅ 最近有提交,继续构建"
|
||||
echo "can_deploy=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "⏭️ 超过 1 小时没有新提交,跳过定时构建"
|
||||
echo "can_deploy=false" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
# 基础决策来自仓库校验
|
||||
CAN_DEPLOY="${{ steps.repo-check.outputs.can_deploy }}"
|
||||
echo "📌 仓库校验结果: can_deploy=${CAN_DEPLOY}"
|
||||
|
||||
# 定时触发:若 1 小时内无新提交则跳过,避免重复构建
|
||||
if [ "${{ github.event_name }}" = "schedule" ]; then
|
||||
LAST_COMMIT_TIME=$(git log -1 --format=%ct)
|
||||
CURRENT_TIME=$(date +%s)
|
||||
DIFF_HOURS=$(( (CURRENT_TIME - LAST_COMMIT_TIME) / 3600 ))
|
||||
|
||||
echo "⏰ 最后一次提交时间: $(date -d @$LAST_COMMIT_TIME)"
|
||||
echo "⏰ 当前时间: $(date)"
|
||||
echo "⏰ 距离上次提交: ${DIFF_HOURS} 小时"
|
||||
|
||||
if [ "$DIFF_HOURS" -ge 1 ]; then
|
||||
echo "⏭️ 超过 1 小时没有新提交,跳过定时构建"
|
||||
CAN_DEPLOY="false"
|
||||
else
|
||||
echo "✅ 最近有提交,继续构建"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "can_deploy=${CAN_DEPLOY}" >> $GITHUB_OUTPUT
|
||||
echo "## 🚦 部署决策: can_deploy=${CAN_DEPLOY}" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "## 🔍 前置检查完成" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
Reference in new issue
Block a user