Skip to content

fix: skip auto-fix when HEAD is not the commit that triggered the workflow - #529

Merged
2bndy5 merged 1 commit into
mainfrom
claude/project-thread-y4qppu
Nov 13, 2026
Merged

2bndy5 merged 1 commit into
mainfrom
claude/project-thread-y4qppu

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Problem

On events that carry no pull request (issue_comment, workflow_run, schedule, workflow_dispatch), the auto-fix step pushes HEAD to GITHUB_REF_NAME, which is usually the default branch. It only compared HEAD with the expected commit when the event had a pull request.

So a workflow like "comment /format on a PR" that checks out the pull request's head and runs the action with auto-fix: true pushes that pull request's commits, plus the formatting commit, straight to the default branch (when the token is allowed to push there).

Change

When the event has no pull request, auto-fix only commits if HEAD is GITHUB_SHA, the commit that triggered the workflow. Otherwise it is skipped with a warning, like the existing check for the pull request head:

HEAD is c656c49…, not fed9662…, the commit that triggered this workflow, so no formatting commit was made. Pushing it would add the checked out commits to <branch>.

push and pull_request workflows are not affected: there the checked out commit is already the expected one. A scheduled or manually started run that formats the branch it runs for keeps working too.

One behavior change to be aware of: if an earlier step of the job makes its own commit before this action runs, auto-fix is now skipped (before, both commits were pushed).

The auto-fix input description and the auto-fix section of the permissions page say the same.

Testing

Run on real runners in cpp-linter/test-cpp-linter-action (branch claude/project-thread-y4qppu, temporary workflow). The stand-in for "a pull request's head is checked out" is an extra empty commit made after actions/checkout, so HEAD is one commit ahead of GITHUB_SHA.

Case Action Result
HEAD ahead of GITHUB_SHA v2.24.1 the stand-in commit and the formatting commit were pushed to the branch (run)
HEAD ahead of GITHUB_SHA this branch skipped with the warning, branch not moved (run)
HEAD is GITHUB_SHA (plain push) this branch formatting commit pushed as before (run)

The v3.0.0-rc0 branch has the same lines; #530 is the same change for it.

…kflow

On events without a pull request (issue_comment, workflow_run, schedule,
workflow_dispatch) the auto-fix commit is pushed to GITHUB_REF_NAME, which
is usually the default branch. If the workflow checked out another commit
there, such as a pull request's head, the push put that commit and its
ancestors on the default branch along with the formatting commit.

Only commit when HEAD is GITHUB_SHA on those events, and skip with a
warning otherwise.
@shenxianpeng
shenxianpeng requested a review from a team as a code owner November 13, 2026 06:06
@shenxianpeng
shenxianpeng requested review from 2bndy5 and removed request for a team November 13, 2026 06:06
@github-actions github-actions Bot added bug Something isn't working documentation Improvements or additions to documentation labels Nov 13, 2026
@shenxianpeng shenxianpeng removed the documentation Improvements or additions to documentation label Nov 13, 2026 — with Claude
@shenxianpeng shenxianpeng self-assigned this Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v16.0.6) reports: 2 file(s) not formatted
  • docs/examples/demo/demo.cpp
  • docs/examples/demo/demo.hpp
clang-tidy (v16.0.6) reports: 7 concern(s)

✨ Powered by cpp-linter -- ⭐ Star • ❤️ Sponsor • 💬 Feedback

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The auto-commit step now checks HEAD against the pull-request head SHA or, for events without a pull-request head SHA, GITHUB_SHA. Documentation describes when auto-fix is skipped.

Changes

Auto-fix Commit Validation

Layer / File(s) Summary
Commit SHA validation
action.yml, docs/permissions.md
The auto-commit step checks HEAD against the applicable SHA and skips committing with a warning on mismatch. The documentation also states that pull requests from forks are skipped.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to 6a379

Auto-fix now skips with a warning when the checked-out commit is not the one that triggered the workflow. This prevents unintended pushes of other commits to the branch. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: auto-fix is skipped when HEAD is not the commit that triggered the workflow. The raw summary shows action.yml and docs/permissions.md changes that add a HEAD-versus-GI…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: auto-fix is skipped when HEAD is not the commit that triggered the workflow. The raw summary shows action.yml and docs/permissions.md changes that add a HEAD-versus-GITHUB_SHA guard for non-pull-request events, which matches the title. The title is 74 characters, which is within a reasonable length for a single-sentence title, and it uses a conventional commit prefix with specific wording.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f4287cde-9ea1-49d2-b73e-76756a40a39e
Commits

Reviewing files that changed from the base of the PR and between 536a397 and 6a379b1.

Files selected for processing: 2

  • action.yml
  • docs/permissions.md

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@2bndy5
2bndy5 merged commit 365e676 into main Nov 13, 2026
51 checks passed
@2bndy5
2bndy5 deleted the claude/project-thread-y4qppu branch November 13, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants