diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 8110b37..4d3d3ad 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -45,5 +45,23 @@ jobs: git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' git add README*.md - git diff --quiet && git diff --staged --quiet || git commit -m "docs: auto-update README [skip ci]" - git push + # 没有变更就直接退出,别浪费 attempt 次数 + if git diff --quiet && git diff --staged --quiet; then + echo "No README changes to commit." + exit 0 + fi + git commit -m "docs: auto-update README [skip ci]" + + # 推回 main 时处理 push race:并发 run 或人工 push 都可能抢先到 remote, + # 这里最多重试 5 次,每次失败就 rebase 到最新 main 再试。 + for i in 1 2 3 4 5; do + if git push; then + echo "Pushed on attempt $i" + exit 0 + fi + echo "Push rejected on attempt $i; rebasing onto latest main and retrying..." + git pull --rebase origin main + sleep $((i * 2)) + done + echo "Push still failing after 5 attempts" >&2 + exit 1