-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix: use gh pr checkout to handle fork PRs in license-check workflow #1709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes the license-check workflow to properly handle pull requests from forks. The previous implementation used ref: ${{ github.head_ref }} which fails for fork PRs because github.head_ref is empty in that context. The new approach uses gh pr checkout which correctly handles both same-repository and fork PRs.
Key Changes:
- Removed problematic
ref: ${{ github.head_ref }}from the checkout step - Added new step using
gh pr checkoutto properly check out PR branches from any source - Added explanatory comment documenting the purpose of the new approach
| - name: Check out PR branch | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: gh pr checkout ${{ github.event.pull_request.number }} |
Copilot
AI
Dec 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gh pr checkout command requires the GitHub CLI to be available in the runner. While ubuntu-latest runners typically have gh pre-installed, this dependency is implicit and could break if the runner image changes. Consider adding a comment documenting this requirement, or add an explicit step to ensure gh is available (e.g., using actions/github-cli-setup or verifying with gh --version).
| with: | ||
| ref: ${{ github.head_ref }} | ||
|
|
||
| # Check out the actual PR branch so we can push changes back if needed |
Copilot
AI
Dec 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 29 accurately describes the purpose of this step. However, it could be more specific about the scenarios this handles. Consider expanding it to:
"Check out the actual PR branch so we can push changes back if needed. This uses 'gh pr checkout' which properly handles both same-repo and fork PRs, unlike the previous 'ref: github.head_ref' approach which fails for fork PRs."
This provides better context for future maintainers about why this approach was chosen.
| # Check out the actual PR branch so we can push changes back if needed | |
| # Check out the actual PR branch so we can push changes back if needed. This uses | |
| # 'gh pr checkout' which properly handles both same-repo and fork PRs, unlike the | |
| # previous 'ref: github.head_ref' approach which fails for fork PRs. |
Summary
The license-check workflow failed on fork PRs because
ref: ${{ github.head_ref }}attempts to checkout a branch that only exists in the fork, not the base repo.Why
Fork PRs like #1702 fail at checkout with "couldn't find remote ref" because
actions/checkoutdefaults to the base repository context.What changed
ref: ${{ github.head_ref }}from checkout stepgh pr checkoutstep to handle both fork and same-repo PRs correctlyMCP impact
Security / limits
Tool renaming
Lint & tests
./script/lint./script/testDocs
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.