UPDATE: Change as little as possible, keeping fork and standard PR handling identical. Do not add approvals for safe functions, like PR validation (conventional commits).
[FEATURE] Add Fork PR Support with Manual Approval
🎯 Problem Statement
Currently, our GitHub Actions workflows only support pull requests from the same repository. Fork PRs cannot run workflows because:
- No access to secrets: Fork PRs don't have access to repository secrets by default (GitHub security feature)
- Limited permissions: Fork PRs have restricted permissions for security reasons
- Workflow limitations: Our current workflows use
pull_request trigger which doesn't work for forks
This prevents contributors from:
- Using Background Agents on their forks (Cursor, GitHub Copilot, etc.)
- Getting full CI/CD validation on their fork PRs
- Testing deployments before merging
💡 Proposed Solution
Implement dual-trigger workflow support that:
- Same-repo PRs: Continue using
pull_request trigger (no approval needed, immediate execution)
- Fork PRs: Use
pull_request_target trigger with environment protection (requires manual approval)
Key Features
- ✅ Security: Fork PRs require explicit approval before running
- ✅ Full functionality: After approval, fork PRs get same workflows as same-repo PRs
- ✅ Transparency: Clear separation and logging of fork vs same-repo PRs
- ✅ Flexibility: Approvers can quickly approve trusted forks (e.g., your own fork)
📋 Implementation Details
Workflow Changes Required
Update the following workflows to support both same-repo and fork PRs:
1. .github/workflows/pr-open.yml
- Add
pull_request_target trigger
- Add
check-fork job to detect fork PRs
- Add conditional logic to jobs:
- Same-repo PRs: Run via
pull_request trigger (no approval)
- Fork PRs: Run via
pull_request_target trigger (requires approval)
- Add
environment: fork-pr-approval to fork PR jobs
- Ensure fork code is checked out correctly using
github.event.pull_request.head.sha
2. .github/workflows/analysis.yml
- Add
pull_request_target trigger
- Add
check-fork job
- Add conditional logic and environment protection for fork PRs
- Update checkout steps to handle fork code
3. .github/workflows/pr-validate.yml
- Add
pull_request_target trigger
- Add
check-fork job
- Add conditional logic and environment protection for fork PRs
Environment Setup Required
Create a GitHub Environment named fork-pr-approval:
- Navigate to:
Settings → Environments → New environment
- Name:
fork-pr-approval
- Configuration:
- Required reviewers: Add yourself and other trusted approvers
- Wait timer: Optional (0 minutes recommended)
- Deployment branches: All branches (or restrict as needed)
- Save environment
Detection Logic
Fork detection uses:
```yaml
github.event.pull_request.head.repo.full_name != github.repository
```
Conditional Execution
Jobs will run based on:
- Same-repo PRs:
github.event_name == 'pull_request' && is_fork == 'false'
- Fork PRs:
github.event_name == 'pull_request_target' && is_fork == 'true'
Code Checkout
For fork PRs via pull_request_target, explicitly checkout the fork's code:
```yaml
- uses: actions/checkout@v6
if: github.event_name == 'pull_request_target'
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
```
🔒 Security Considerations
Why pull_request_target?
- Runs in the base repository context (has access to secrets)
- Requires environment protection (manual approval)
- Checks out fork code explicitly (controlled)
Security Benefits
- No automatic execution: Fork PRs cannot run workflows without approval
- Explicit approval: Required reviewers must approve before workflows run
- Audit trail: All approvals are logged in GitHub
- Controlled access: Secrets only available after approval
Best Practices
- ✅ Always use environment protection for fork PRs
- ✅ Explicitly checkout fork code (don't trust default checkout)
- ✅ Review fork PR code before approving
- ✅ Limit required reviewers to trusted team members
🧪 Testing Plan
Test Cases
-
Same-repo PR (should work as before)
-
Fork PR (new functionality)
-
Fork PR rejection
Validation Checklist
📚 References
✅ Acceptance Criteria
🚀 Implementation Priority
Priority: Medium
Effort: ~2-3 hours
Impact: Enables fork-based contributions and Background Agent workflows
📝 Notes
- This feature enables Background Agents (Cursor, GitHub Copilot) to work on forks
- Useful for contributors who can't install GitHub Apps on organization repos
- Maintains security through environment protection
- No breaking changes to existing same-repo PR workflows
UPDATE: Change as little as possible, keeping fork and standard PR handling identical. Do not add approvals for safe functions, like PR validation (conventional commits).
[FEATURE] Add Fork PR Support with Manual Approval
🎯 Problem Statement
Currently, our GitHub Actions workflows only support pull requests from the same repository. Fork PRs cannot run workflows because:
pull_requesttrigger which doesn't work for forksThis prevents contributors from:
💡 Proposed Solution
Implement dual-trigger workflow support that:
pull_requesttrigger (no approval needed, immediate execution)pull_request_targettrigger with environment protection (requires manual approval)Key Features
📋 Implementation Details
Workflow Changes Required
Update the following workflows to support both same-repo and fork PRs:
1.
.github/workflows/pr-open.ymlpull_request_targettriggercheck-forkjob to detect fork PRspull_requesttrigger (no approval)pull_request_targettrigger (requires approval)environment: fork-pr-approvalto fork PR jobsgithub.event.pull_request.head.sha2.
.github/workflows/analysis.ymlpull_request_targettriggercheck-forkjob3.
.github/workflows/pr-validate.ymlpull_request_targettriggercheck-forkjobEnvironment Setup Required
Create a GitHub Environment named
fork-pr-approval:Settings → Environments → New environmentfork-pr-approvalDetection Logic
Fork detection uses:
```yaml
github.event.pull_request.head.repo.full_name != github.repository
```
Conditional Execution
Jobs will run based on:
github.event_name == 'pull_request' && is_fork == 'false'github.event_name == 'pull_request_target' && is_fork == 'true'Code Checkout
For fork PRs via
pull_request_target, explicitly checkout the fork's code:```yaml
if: github.event_name == 'pull_request_target'
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
```
🔒 Security Considerations
Why
pull_request_target?Security Benefits
Best Practices
🧪 Testing Plan
Test Cases
Same-repo PR (should work as before)
Fork PR (new functionality)
Fork PR rejection
Validation Checklist
📚 References
✅ Acceptance Criteria
pr-open.yml,analysis.yml,pr-validate.yml) support fork PRsfork-pr-approvalis created and configured🚀 Implementation Priority
Priority: Medium
Effort: ~2-3 hours
Impact: Enables fork-based contributions and Background Agent workflows
📝 Notes