fix(ci): retry README auto-commit push on race (rebase + up to 5 attempts)

This commit is contained in:
Jared Liu 2026-04-20 21:31:26 +08:00
parent c5d9161e35
commit 22e7b5934e

View file

@ -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