A public repository runs tests with a pull_request workflow. The workflow should post the test results as a comment on each pull request, but on pull requests from forks the comment step fails with a 403 error. Maintainers must not let code from a fork run with a write-capable token or with repository secrets. What should they do?
Choose one.
Event choice for pull requests from forks: pull_request, pull_request_target and workflow_run.
On pull_request runs from forks, the GITHUB_TOKEN is read-only and secrets are withheld, so a write action fails. pull_request_target runs in the base repository's context with write access and secrets, which is unsafe if it builds or runs the fork's code. The standard split is: test untrusted code on pull_request, save results as an artifact, and let a workflow_run workflow (which runs in the base repository's context) download them and post the comment without executing fork code.
- Explain the 403: fork pull request runs get a read-only token.
- Note the constraint: fork code must not run with write access or secrets.
- Reject pull_request_target with a head checkout (runs fork code with write access).
- Separate untrusted testing from the privileged comment step with workflow_run.
Exam tip: Run fork code under pull_request; do privileged follow-up in a workflow_run workflow that only handles artifacts.
GitHub Actions Triggers, Events, Caching, Artifacts and Outputs (GH-200) — the lesson that teaches this.