Switch loop guard to author-based to survive interleaving auto-commits (#753)

Co-authored-by: Glenn Jocher <[email protected]>
This commit is contained in:
Murat Raimbekov
2026-05-29 17:29:38 +08:00
committed by GitHub
co-authored by Glenn Jocher
parent 2dcc577208
commit 8112829f33
+10 -9
View File
@@ -339,21 +339,22 @@ runs:
# Commit Changes ---------------------------------------------------------------------------------------------------
- name: Commit and Push Changes
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && (github.event.action == 'opened' || github.event.action == 'synchronize')
# Skip when the triggering push came from the bot itself (a prior Auto-format push, or a sibling
# auto-commit workflow sharing the same token such as Auto-update Docs). github.actor is set by GitHub
# from the pushing token and cannot be spoofed via git config, so this breaks recursive auto-commit loops
# even when sibling bot commits or merge commits interleave between Auto-format pushes. Human pushes have a
# different actor and are always formatted. Default-GITHUB_TOKEN pushes never re-trigger workflows, so only
# PAT-authored bot pushes (actor == github_username) can recurse here.
if: |
(github.event_name == 'pull_request' || github.event_name == 'pull_request_target') &&
(github.event.action == 'opened' || github.event.action == 'synchronize') &&
github.actor != inputs.github_username
env:
GITHUB_USERNAME: ${{ inputs.github_username }}
GITHUB_EMAIL: ${{ inputs.github_email }}
run: |
echo "::group::Commit and Push Changes"
COMMIT_MSG="Auto-format by https://ultralytics.com/actions"
# Check if last two commits were both auto-format to prevent recursive loops
LAST_TWO=$(git log -2 --pretty=format:'%s' 2>/dev/null || echo "")
MATCH_COUNT=$(printf '%s\n' "$LAST_TWO" | grep -Fxc "$COMMIT_MSG" || true)
if [ "$MATCH_COUNT" -ge 2 ]; then
echo "Skipping commit: last two commits were auto-format"
echo "::endgroup::"
exit 0
fi
git config --global user.name "$GITHUB_USERNAME"
git config --global user.email "$GITHUB_EMAIL"
git add .