ci: run Chromatic on authorized fork PRs, skip unauthorized ones#383
Open
mkitti wants to merge 1 commit into
Open
ci: run Chromatic on authorized fork PRs, skip unauthorized ones#383mkitti wants to merge 1 commit into
mkitti wants to merge 1 commit into
Conversation
A plain pull_request event withholds repository secrets from forks, so CHROMATIC_PROJECT_TOKEN was empty for fork PRs and Chromatic failed. Switch the trigger to pull_request_target so the token is available, and gate the job: it runs for pushes, manual dispatch, same-repo PRs, and fork PRs whose author is a trusted collaborator (OWNER/MEMBER/ COLLABORATOR). PRs from unauthorized forks fall through the condition and the job is skipped (neutral) instead of failing. The checkout now pins the PR head commit from the contributor's fork. Also move the CHROMATIC_* env vars from the checkout step (where the Chromatic action could not read them) to the job, and fix the CHROMATIC_SHA push fallback to use github.sha rather than github.ref. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Chromatic GitHub Actions workflow to support fork-based pull requests by switching to pull_request_target, adding an authorization gate to skip untrusted fork PRs, and checking out the PR head SHA so authorized forks build the contributor’s actual code while still having access to CHROMATIC_PROJECT_TOKEN.
Changes:
- Switch workflow trigger from
pull_requesttopull_request_targetto allow secrets on fork PRs. - Add a job-level
if:gate usingauthor_associationand same-repo checks to skip unauthorized fork PRs. - Move
CHROMATIC_*variables to job-levelenvand fix SHA selection; update checkout to use PR head repository + SHA.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+19
to
+23
| # Run for pushes/manual dispatch and for same-repository PRs. For PRs from a | ||
| # fork, only run when the author is a trusted collaborator (OWNER, MEMBER, or | ||
| # COLLABORATOR) so the secret is exposed only to users who already have write | ||
| # access. PRs from unauthorized forks fall through this condition and the job | ||
| # is skipped (neutral) rather than failing. |
Comment on lines
39
to
+43
| fetch-depth: 0 | ||
| ref: ${{ github.event.pull_request.head.ref }} | ||
| env: | ||
| CHROMATIC_BRANCH: ${{ github.event.pull_request.head.ref || github.ref_name }} | ||
| CHROMATIC_SHA: ${{ github.event.pull_request.head.sha || github.ref }} | ||
| CHROMATIC_SLUG: ${{ github.repository }} | ||
| # For fork PRs, check out the contributor's head commit from their fork. | ||
| # Falls back to the base repository for pushes and same-repo PRs. | ||
| repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} | ||
| ref: ${{ github.event.pull_request.head.sha || github.sha }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make Chromatic work for fork PRs
A plain
pull_requestevent withholds repository secrets from forks, soCHROMATIC_PROJECT_TOKENis empty for pull requests opened from a fork and the Chromatic job fails. This reworks the workflow so fork PRs are handled deliberately.Changes
pull_request_targetso theCHROMATIC_PROJECT_TOKENsecret is available even for fork PRs.if:) — the job runs for pushes, manual dispatch, same-repo PRs, and fork PRs whose author is a trusted collaborator (OWNER/MEMBER/COLLABORATOR, viaauthor_association). PRs from unauthorized forks fall through the condition and the job is skipped (neutral) rather than failing.repository: head.repo.full_name,ref: head.sha), so authorized fork PRs build the actual fork branch. Falls back to the base repo for pushes/same-repo PRs.CHROMATIC_*env vars were attached to the checkout step (where the Chromatic action could not read them) — moved to job-levelenv— and theCHROMATIC_SHApush fallback usedgithub.ref(a ref name) instead ofgithub.sha.Security note
pull_request_targetruns with secrets in scope, and this workflow checks out the PR head. Theif:gate is the mitigation: untrusted fork code is never reached because the job is skipped for non-collaborator authors, and collaborators already have write access to the repo. Authorization usesauthor_association(no extra API call); noteMEMBERis a slightly loose proxy for repo write access.🤖 Generated with Claude Code