Skip to content

Fix lint workflow to checkout PR branch instead of base branch#5084

Merged
ahpook merged 2 commits intoahpook/rubocop-wtffrom
copilot/fix-rubocop-checkout-branch
Mar 20, 2026
Merged

Fix lint workflow to checkout PR branch instead of base branch#5084
ahpook merged 2 commits intoahpook/rubocop-wtffrom
copilot/fix-rubocop-checkout-branch

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

The lint.yml workflow uses pull_request_target, which causes actions/checkout to check out the base branch (main) by default—not the PR branch. Rubocop then lints main, misses PR fixes, and fails on already-resolved issues.

Change

Added explicit ref to the checkout step:

- uses: actions/checkout@v6.0.1
  with:
    ref: ${{ github.event.pull_request.head.ref || github.ref }}
  • pull_request_target → checks out the PR's head branch
  • workflow_dispatch / merge_group → falls back to github.ref (default behavior)

Uses head.ref (branch name) rather than head.sha because the workflow pushes auto-corrected commits back to the PR branch, which requires a named ref.


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

The lint.yml workflow uses pull_request_target trigger, which causes
actions/checkout to check out the base branch (main) by default.
This means rubocop runs against main's code, not the PR's changes.

Add ref parameter to checkout the PR's head branch, with fallback to
github.ref for workflow_dispatch and merge_group triggers.

Co-authored-by: ahpook <56753+ahpook@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/explore/sessions/f08905db-e076-48a4-8c19-6b4acc2c537c
Copilot AI changed the title [WIP] Fix rubocop to run on PR branch instead of main Fix lint workflow to checkout PR branch instead of base branch Mar 20, 2026
Copilot AI requested a review from ahpook March 20, 2026 19:31
@ahpook ahpook marked this pull request as ready for review March 20, 2026 19:38
@ahpook ahpook requested a review from a team as a code owner March 20, 2026 19:38
Copilot AI review requested due to automatic review settings March 20, 2026 19:38
@ahpook ahpook merged commit 00b6570 into ahpook/rubocop-wtf Mar 20, 2026
2 checks passed
@ahpook ahpook deleted the copilot/fix-rubocop-checkout-branch branch March 20, 2026 19:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the lint GitHub Actions workflow so that, when triggered via pull_request_target, it checks out the PR’s head branch rather than the base branch—ensuring RuboCop runs against the proposed changes and can auto-correct them on the PR branch.

Changes:

  • Add an explicit ref to actions/checkout to prefer github.event.pull_request.head.ref with a fallback to github.ref.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to +18
- uses: actions/checkout@v6.0.1
with:
ref: ${{ github.event.pull_request.head.ref || github.ref }}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking out the PR head branch under pull_request_target while the workflow has contents: write and runs Bundler/RuboCop means untrusted PR code can execute with a write-capable GITHUB_TOKEN (repo-compromise risk). It will also fail for fork PRs because head.ref refers to a branch in the fork, but actions/checkout defaults to the base repo unless repository: is set.

Consider gating this job/step to same-repo PRs only (e.g., if: github.event.pull_request.head.repo.full_name == github.repository) and using a separate read-only lint workflow for forks; or otherwise avoid pull_request_target + write permissions when running PR code.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants