From 1b987247e5b1011234e7ae0ed596e91a67fc8073 Mon Sep 17 00:00:00 2001 From: Gaubee Date: Mon, 26 Jan 2026 22:50:22 +0800 Subject: [PATCH] fix: make gh-pages deploy idempotent --- .github/workflows/cd.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 96dc40d00..a63e98335 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -393,9 +393,13 @@ jobs: git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add -A - git commit -m "Deploy to GitHub Pages - ${{ github.sha }}" - git push -f "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" HEAD:gh-pages - echo "Deployed to gh-pages branch" + if git diff --cached --quiet; then + echo "No changes to deploy" + else + git commit -m "Deploy to GitHub Pages - ${{ github.sha }}" + git push -f "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" HEAD:gh-pages + echo "Deployed to gh-pages branch" + fi # 直接在 build job 中创建 release,避免跨 job 传递 artifact(self-hosted 下载很慢) # 使用重试逻辑处理网络不稳定问题 @@ -874,9 +878,13 @@ jobs: git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add -A - git commit -m "Deploy to GitHub Pages - ${{ github.sha }}" - git push -f "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" HEAD:gh-pages - echo "Deployed to gh-pages branch" + if git diff --cached --quiet; then + echo "No changes to deploy" + else + git commit -m "Deploy to GitHub Pages - ${{ github.sha }}" + git push -f "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" HEAD:gh-pages + echo "Deployed to gh-pages branch" + fi - name: Upload release artifacts if: steps.channel.outputs.channel == 'stable'