Skip to content

Conversation

@DayuanJiang
Copy link
Owner

Summary

  • Fix auto-format workflow failing for fork PRs
  • Use github.event.pull_request.head.sha instead of github.head_ref for checkout (works for forks)
  • For fork PRs: fail with helpful message if formatting is needed (can't push to forks)
  • For same-repo PRs: auto-commit and push as before
  • Simplified push logic: push directly from detached HEAD with git push origin HEAD:<branch>

Problem

The workflow was failing for fork-based PRs (like PR #413) because:

  1. It tried to checkout github.head_ref (branch name) which only exists in the fork, not the main repo
  2. Even if checkout worked, GITHUB_TOKEN can't push to forks

Solution

  • Checkout by SHA instead of branch name (works for any PR)
  • Detect fork PRs and fail gracefully with instructions for contributors
  • Keep auto-format behavior for same-repo PRs

- Use head.sha instead of head_ref for checkout (works for forks)
- For fork PRs: fail with helpful message if formatting needed
- For same-repo PRs: auto-commit and push as before
@DayuanJiang DayuanJiang merged commit 067d309 into main Dec 26, 2025
4 of 5 checks passed
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.

2 participants