Skip to content

Use pull_request_target so cherry-pick workflow runs from main - #159

Merged
kriszyp merged 1 commit into
mainfrom
use-pull-request-target
May 18, 2026
Merged

Use pull_request_target so cherry-pick workflow runs from main#159
kriszyp merged 1 commit into
mainfrom
use-pull-request-target

Conversation

@kriszyp

@kriszyp kriszyp commented May 18, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #157. Labeling #154 with patch produced no workflow run.

Root cause: for pull_request events, GitHub loads the workflow definition from the PR head ref, not from main. PR #154's branch (fix/replication-protocol-close-retry) was created before the pre-merge cherry-pick workflow landed, so it carries the OLD cherry-pick-patch.yml that only triggers on pull_request closed and issues labeled. The new pull_request labeled trigger only exists on main, so the label change on #154 was silently ignored.

Fix

Switch the trigger from pull_request to pull_request_target. With pull_request_target, GitHub loads the workflow definition from the base ref (main) regardless of what's on the PR head, so any open PR — even those branched before the new flow landed — picks up the current workflow.

Security note

pull_request_target runs with a write-scope token against the base ref, which is normally dangerous because it can execute PR-controlled code. This workflow is safe because:

  1. actions/checkout is pinned to ref: main (from Pin cherry-pick workflow checkout to main #157), so the PR's tree is never the source of any executed code.
  2. Only git fetch / git cherry-pick touch PR commits — no npm install, no PR-controlled scripts run inside this workflow.
  3. The dispatched test workflows (integration-tests.yaml) run separately, on the cherry-pick branch, with their own token scope.

I'd appreciate a once-over on the security reasoning before merging.

After merge

For PR #154 specifically: unlabel and re-label patch to fire the workflow against the updated trigger.

🤖 Generated by Claude Opus 4.7 (1M context).

For pull_request events, GitHub loads the workflow definition from the
PR head ref. PRs branched off main before the pre-merge cherry-pick
workflow landed still carry the OLD workflow (which only triggered on
pull_request closed and issues labeled), so labeling those PRs with
patch does nothing — the new label trigger only exists on main.

Switch to pull_request_target: the workflow is loaded from the base
ref (main) regardless of what's on the PR head. Token has write scope
under pull_request_target, but this workflow already checks out main
(ref: main) and only runs git against PR commits — no npm install or
PR-controlled scripts are executed, so the usual pull_request_target
risk doesn't apply here.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kriszyp
kriszyp requested review from a team as code owners May 18, 2026 20:07
@claude

claude Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Reviewed; no blockers found.

@kriszyp
kriszyp merged commit 33786d4 into main May 18, 2026
22 of 23 checks passed
@kriszyp
kriszyp deleted the use-pull-request-target branch May 18, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant