Repository navigation
fix: skip auto-fix when HEAD is not the commit that triggered the workflow - #529
Conversation
…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.
Cpp-Linter Report
|
|
No actionable comments were generated in the recent review. WalkthroughThe auto-commit step now checks ChangesAuto-fix Commit Validation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk:
|
Problem
On events that carry no pull request (
issue_comment,workflow_run,schedule,workflow_dispatch), the auto-fix step pushesHEADtoGITHUB_REF_NAME, which is usually the default branch. It only comparedHEADwith the expected commit when the event had a pull request.So a workflow like "comment
/formaton a PR" that checks out the pull request's head and runs the action withauto-fix: truepushes 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
HEADisGITHUB_SHA, the commit that triggered the workflow. Otherwise it is skipped with a warning, like the existing check for the pull request head:pushandpull_requestworkflows 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-fixinput 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 afteractions/checkout, soHEADis one commit ahead ofGITHUB_SHA.HEADahead ofGITHUB_SHAv2.24.1HEADahead ofGITHUB_SHAHEADisGITHUB_SHA(plain push)The
v3.0.0-rc0branch has the same lines; #530 is the same change for it.