From a70f62bc76a56fb35b3f96d4fb10b4b60b8ea8cf Mon Sep 17 00:00:00 2001 From: Vaica <94612053+zqlit@users.noreply.github.com> Date: Sat, 27 Jun 2026 19:36:51 +0800 Subject: [PATCH] Update deploy.yml --- .github/workflows/deploy.yml | 39 ++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 92699067..8a1afdab 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -63,6 +63,27 @@ 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 + 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 + fi + - name: Summary run: | echo "## 🔍 前置检查完成" >> $GITHUB_STEP_SUMMARY @@ -176,7 +197,6 @@ jobs: name: hugo-public path: public/ retention-days: 1 - compression-level: 0 - name: Push Image Optimizations continue-on-error: true @@ -265,7 +285,7 @@ jobs: if: steps.check.outputs.deployed == 'true' uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 - name: Download build artifact if: steps.check.outputs.deployed == 'true' @@ -485,7 +505,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 permissions: - contents: read + contents: write needs: [pre-check, build, deploy-edgeone, deploy-upyun] if: always() && needs.build.result == 'success' && needs.deploy-edgeone.result == 'success' && needs.deploy-upyun.result == 'success' @@ -497,7 +517,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 - name: Setup Node uses: actions/setup-node@v4 @@ -807,6 +827,17 @@ jobs: echo "| UpYun | ${{ needs.deploy-upyun.outputs.deployed == 'true' && '✅ 已部署' || '⏭️ 跳过(无变化)' }} |" >> $GITHUB_STEP_SUMMARY echo "| CDN 刷新 | ${{ steps.deploy-status.outputs.any_deployed == 'true' && '✅ 已刷新' || '⏭️ 跳过' }} |" >> $GITHUB_STEP_SUMMARY + - name: Clean up build artifact + uses: actions/delete-artifact@v4 + with: + name: hugo-public + + - name: Clean up old caches + continue-on-error: true + run: | + gh extension install actions/gh-actions-cache || true + gh actions-cache delete --all --confirm || true + # ============================================================ # Job 6: Failure Notification (失败通知) # ============================================================