A PR from a fork needs to run tests but must not get repo secrets. How do you set up triggers?
IntermediateScenarioGitHub Actions
Answer
Situation read → pull_request vs pull_request_target.
What I'd do →
- Use
pull_requestfor tests: forks get a read-only token and no secrets. - If you must comment on the PR, use a second workflow on
workflow_runthat reads artifacts produced by the first, and treat them as untrusted data. - Never check out and run PR head code in a
pull_request_targetworkflow.
Why → pull_request_target runs with secrets and a write token on the base repo; running fork code there is a known compromise path.
Interview tip → Two-workflow pattern for fork comments.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is the difference between `pull_request` and `pull_request_target`?AdvancedWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow do you pass data between steps and between jobs?IntermediateHow does a build matrix work?Intermediate