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
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 2
|
timeout-minutes: 2
|
||||||
outputs:
|
outputs:
|
||||||
can_deploy: ${{ steps.repo-check.outputs.can_deploy }}
|
can_deploy: ${{ steps.decide.outputs.can_deploy }}
|
||||||
duration: ${{ steps.end-pre-check.outputs.duration }}
|
duration: ${{ steps.end-pre-check.outputs.duration }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -63,27 +63,34 @@ jobs:
|
|||||||
echo "⚠️ 提交信息格式建议: feat/fix/chore/docs/style/refactor/test: description"
|
echo "⚠️ 提交信息格式建议: feat/fix/chore/docs/style/refactor/test: description"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Check for new commits (only for cron)
|
- name: Decide whether to deploy
|
||||||
if: github.event_name == 'schedule'
|
id: decide
|
||||||
id: cron-check
|
|
||||||
run: |
|
run: |
|
||||||
LAST_COMMIT_TIME=$(git log -1 --format=%ct)
|
# 基础决策来自仓库校验
|
||||||
CURRENT_TIME=$(date +%s)
|
CAN_DEPLOY="${{ steps.repo-check.outputs.can_deploy }}"
|
||||||
DIFF_HOURS=$(( (CURRENT_TIME - LAST_COMMIT_TIME) / 3600 ))
|
echo "📌 仓库校验结果: can_deploy=${CAN_DEPLOY}"
|
||||||
|
|
||||||
echo "⏰ 最后一次提交时间: $(date -d @$LAST_COMMIT_TIME)"
|
# 定时触发:若 1 小时内无新提交则跳过,避免重复构建
|
||||||
echo "⏰ 当前时间: $(date)"
|
if [ "${{ github.event_name }}" = "schedule" ]; then
|
||||||
echo "⏰ 距离上次提交: $DIFF_HOURS 小时"
|
LAST_COMMIT_TIME=$(git log -1 --format=%ct)
|
||||||
|
CURRENT_TIME=$(date +%s)
|
||||||
if [ "$DIFF_HOURS" -lt 1 ]; then
|
DIFF_HOURS=$(( (CURRENT_TIME - LAST_COMMIT_TIME) / 3600 ))
|
||||||
echo "✅ 最近有提交,继续构建"
|
|
||||||
echo "can_deploy=true" >> $GITHUB_OUTPUT
|
echo "⏰ 最后一次提交时间: $(date -d @$LAST_COMMIT_TIME)"
|
||||||
else
|
echo "⏰ 当前时间: $(date)"
|
||||||
echo "⏭️ 超过 1 小时没有新提交,跳过定时构建"
|
echo "⏰ 距离上次提交: ${DIFF_HOURS} 小时"
|
||||||
echo "can_deploy=false" >> $GITHUB_OUTPUT
|
|
||||||
exit 0
|
if [ "$DIFF_HOURS" -ge 1 ]; then
|
||||||
|
echo "⏭️ 超过 1 小时没有新提交,跳过定时构建"
|
||||||
|
CAN_DEPLOY="false"
|
||||||
|
else
|
||||||
|
echo "✅ 最近有提交,继续构建"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "can_deploy=${CAN_DEPLOY}" >> $GITHUB_OUTPUT
|
||||||
|
echo "## 🚦 部署决策: can_deploy=${CAN_DEPLOY}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
- name: Summary
|
- name: Summary
|
||||||
run: |
|
run: |
|
||||||
echo "## 🔍 前置检查完成" >> $GITHUB_STEP_SUMMARY
|
echo "## 🔍 前置检查完成" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|||||||
Reference in new issue
Block a user