ci(trunk): upload impacted targets with fork-aware auth so fork PRs can enter the merge queue - #3429
Merged
Conversation
Fork PRs never entered the Trunk parallel merge queue and had to be merged by hand (e.g. #2819). Trunk needs an impacted-targets upload to place a PR into a lane, and the upload authenticates with the org API token — which GitHub withholds from fork `pull_request` runs. Add a dedicated workflow that uploads to /v1/setImpactedTargets on every PR, using x-api-token on internal PRs and x-forked-workflow-run-id (from github.run_id) on fork PRs, per Trunk's guidance. Reports "ALL" targets for correctness; refining to a computed target list is left as a documented TODO. Stays on the `pull_request` trigger (never pull_request_target) so no secret is ever exposed to fork code. Generated-By: PostHog Code Task-Id: 295c0ed1-48f3-4bd4-9d0e-dba8d17031ca
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
Contributor
|
Reviews (1): Last reviewed commit: "ci(trunk): upload impacted targets with ..." | Re-trigger Greptile |
tatoalo
approved these changes
Jul 14, 2026
Fork PRs frequently share a source branch name (many are opened from `main`), so keying the concurrency group on github.head_ref would put two such PRs in one group where cancel-in-progress lets one cancel the other's upload — leaving that head SHA without the impacted-targets upload it needs to enter the queue. Key on github.event.pull_request.number instead. Generated-By: PostHog Code Task-Id: 295c0ed1-48f3-4bd4-9d0e-dba8d17031ca
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.
Problem
Fork PRs can't be merged through the Trunk parallel merge queue and have to be merged by hand — e.g. #2819, which Trunk logged as "😎 Merged manually" and landed via GitHub auto-squash, with no
Trunk Merge Queuecheck ever running.Trunk needs an impacted-targets upload to place a PR into a queue lane. That upload authenticates with the org API token (
x-api-token=secrets.TRUNK_API_TOKEN), but GitHub withholds repo secrets frompull_requestruns originating in a fork, so fork PRs can never make that call. The repo had no impacted-targets upload at all (only the flaky-testanalytics-uploader).Per the Trunk team: "add a
x-forked-workflow-run-idheader to the request to upload impacted targets for your parallel queue from forked PRs."Change
New workflow
.github/workflows/trunk-impacted-targets.ymlthat POSTs to/v1/setImpactedTargetson every PR:x-api-token: ${{ secrets.TRUNK_API_TOKEN }}x-forked-workflow-run-id: ${{ github.run_id }}(no secret required)Details:
e2ejob (head.repo.full_name != github.repository).repo{host,owner,name},pr{number,sha},targetBranch,impactedTargets), built withjqfrom env-passed context (no untrusted PR data interpolated into the shell). Uses the PR head SHA so it matches the run'shead_shafor Trunk's fork verification.impactedTargets: "ALL"— always correct (never under-reports), gets forks into the queue; a computed target list for real parallelism is left as a documented TODO in the file.continue-on-error) with retries — a silent upload failure is exactly what kept fork PRs out of the queue.pull_requesttrigger, neverpull_request_target, so no secret is exposed to fork code ("pwn request").Ref: https://docs.trunk.io/merge-queue/optimizations/parallel-queues/api#handling-forked-pull-requests
Verification
on/jobs/concurrency/permissionsas intended.jqpayload is schema-correct (pr.numberis a JSON number) and the auth header switches correctly between fork/internal.Created with PostHog Code