From 8112829f33c6a31176ae7efa909b85ad92612673 Mon Sep 17 00:00:00 2001 From: Murat Raimbekov Date: Fri, 29 May 2026 15:29:38 +0600 Subject: [PATCH] Switch loop guard to author-based to survive interleaving auto-commits (#753) Co-authored-by: Glenn Jocher --- action.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 0e9d766..57871a4 100644 --- a/action.yml +++ b/action.yml @@ -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 .