Use pull_request_target event in PR workflow to support fork CI with secrets #59
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openrn/react-native-logging-tools#59
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Checklist
has not been requested before
exist
Feature Description
Update the
.forgejo/workflows/pr.yamlworkflow to use thepull_request_targetevent instead ofpull_request, and adapt the checkoutsteps to correctly check out the PR contributor's code.
Problem Statement
The current
pull_requestevent does not have access to repository secrets whentriggered by a fork PR. This means optional steps like the Sonar analysis are
silently skipped for fork contributions, providing incomplete CI feedback and
reducing code quality visibility for external contributors.
Proposed Solution
Switch the workflow trigger from
pull_requesttopull_request_target:to secrets for all PRs, including forks.
actions/checkout@v4steps must be updated to explicitly check out the PRhead commit using
ref: ${{ github.event.pull_request.head.sha }}, so thecontributor's actual code is tested rather than the base branch.
Use Case
A contributor forks the repository and opens a PR. With
pull_request, Sonaranalysis is skipped because
SONAR_TOKENis not accessible. Withpull_request_targetand the adapted checkout, the full CI pipeline — includingSonar — runs on the contributor's code.
Alternatives Considered
pull_requestand document that Sonar won't run on forks: Acceptablebut provides inconsistent CI experience and misses code quality reporting for
external contributions.
refs/pull/N/mergeinstead of the head SHA for checkout: This checksout the merged result rather than the exact PR commit, introducing ambiguity.
Using the head SHA is more precise and aligns with Forgejo recommendations.
Examples
Implementation Ideas
.forgejo/workflows/pr.yaml: change event trigger and addref:to allcheckout steps.
Additional Context
This is a Forgejo CI environment. The
pull_request_targetevent behavessimilarly to GitHub Actions'
pull_request_target. See Forgejo Actionsdocumentation for details.