Skip to content

fix: cross-repo dispatch-workflow uses caller's GITHUB_REF instead of target repo's ref - #20790

Merged
pelikhan merged 3 commits into
mainfrom
copilot/fix-dispatch-workflow-ref
Mar 13, 2026
Merged

fix: cross-repo dispatch-workflow uses caller's GITHUB_REF instead of target repo's ref#20790
pelikhan merged 3 commits into
mainfrom
copilot/fix-dispatch-workflow-ref

Conversation

CopilotAI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

In workflow_call relay scenarios, dispatch-workflow was dispatching with the caller'sGITHUB_REF as the target ref — a ref meaningless on the target repository. The compiler already correctly injects target-repo for cross-repo relay, but there was no equivalent injection for the dispatch ref, and GITHUB_REF being set prevented the getDefaultBranchRef() fallback from ever running.

Changes

Runtime (actions/setup/js/dispatch_workflow.cjs)

  • Added config["target-ref"] as the highest priority in ref resolution, checked before GITHUB_HEAD_REF/GITHUB_REF, so compiler-injected refs always win for cross-repo dispatch.

Compiler (pkg/workflow/compiler_safe_outputs_config.go)

  • Extended the workflow_call injection block to also inject target-ref: ${{ needs.activation.outputs.target_ref }} alongside the existing target-repo injection.
  • Added safeOutputsWithDispatchTargetRef helper (mirrors safeOutputsWithDispatchTargetRepo).
  • Added target-ref to the dispatch_workflow handler config builder.

Config struct (pkg/workflow/dispatch_workflow.go)

  • Added TargetRef string (yaml:"target-ref") to DispatchWorkflowConfig, with explicit parsing from the config map (enabling manual override in frontmatter as well).

JSON Schema (pkg/parser/schemas/main_workflow_schema.json)

  • Added target-repo (previously missing despite additionalProperties: false) and target-ref to the dispatch-workflow object schema with descriptive documentation.

Specification (docs/src/content/docs/reference/safe-outputs-specification.md)

  • Added target-ref to the dispatch_workflow Configuration Parameters.
  • Added a note explaining workflow_call relay auto-injection of both target-repo and target-ref.

New ref resolution precedence in dispatch_workflow.cjs:

if(config["target-ref"]){ref=config["target-ref"];// cross-repo relay: compiler-injected}elseif(process.env.GITHUB_HEAD_REF){ref=`refs/heads/${process.env.GITHUB_HEAD_REF}`;// PR context}elseif(process.env.GITHUB_REF||context.ref){ref=process.env.GITHUB_REF||context.ref;// push/workflow_dispatch}else{ref=awaitgetDefaultBranchRef();// last resort}

Three new test cases cover: target-ref taking precedence over GITHUB_REF, same-repo dispatch still using GITHUB_REF, and target-ref taking precedence over GITHUB_HEAD_REF in PR context.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

… instead of target ref
When a compiled workflow uses `dispatch-workflow` with a `workflow_call` relay pattern,
the dispatcher was using the caller's GITHUB_REF (which is meaningless on the target repo)
instead of the target repository's intended ref.
Changes:
- Add `TargetRef` field to `DispatchWorkflowConfig` (parsed from `target-ref` config key)
- Compiler now injects `${{ needs.activation.outputs.target_ref }}` as `target-ref`
alongside the existing `target-repo` injection for `workflow_call` relay workflows
- Add `safeOutputsWithDispatchTargetRef` helper mirroring `safeOutputsWithDispatchTargetRepo`
- `dispatch_workflow.cjs` now checks `config['target-ref']` first in the ref resolution
block, taking priority over caller's GITHUB_HEAD_REF and GITHUB_REF
- Three new test cases for the cross-repo target-ref scenarios
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
CopilotAI changed the title [WIP] Fix dispatch-workflow to use target repo's default branchfix: cross-repo dispatch-workflow uses caller's GITHUB_REF instead of target repo's refMar 13, 2026
CopilotAI requested a review from pelikhanMarch 13, 2026 13:15
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot update json schema and spec

@github-actions

Copy link
Copy Markdown
Contributor

Hey @Copilot 👋 — great work on the dispatch-workflow cross-repo ref fix! Correctly routing the target ref for workflow_call relay scenarios is a subtle but important correctness fix, and the implementation is clean.

The PR is well-structured, focused, and comes with thorough test coverage. All three new test cases (target-ref over GITHUB_REF, same-repo dispatch unchanged, target-ref over GITHUB_HEAD_REF) cover the key edge cases well. The description clearly explains the root cause, the ref-resolution precedence change, and which files were touched — exactly the level of detail maintainers need.

Checklist summary:

CheckResult
On-topic✅ yes
Follows process✅ yes (Copilot agent + core team assignee)
Focused✅ yes
New dependencies✅ no
Has tests✅ yes (3 new cases in dispatch_workflow.test.cjs)
Has description✅ yes
Lines changed112

Verdict: 🟢 Aligned — looks ready for maintainer review.

Generated by Contribution Check ·

- Add target-repo and target-ref properties to dispatch-workflow in
pkg/parser/schemas/main_workflow_schema.json (target-repo was missing
from the schema despite additionalProperties: false)
- Update docs/src/content/docs/reference/safe-outputs-specification.md
to document the new target-ref parameter and the workflow_call relay
auto-injection behaviour
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

CopilotAI commented Mar 13, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot update json schema and spec

Done in 297a650:

  • pkg/parser/schemas/main_workflow_schema.json: Added target-repo (which was missing despite additionalProperties: false) and target-ref to the dispatch-workflow object schema.
  • docs/src/content/docs/reference/safe-outputs-specification.md: Added target-ref to the Configuration Parameters section and a note explaining the workflow_call relay auto-injection behaviour.

CopilotAI requested a review from pelikhanMarch 13, 2026 13:33
@pelikhan
pelikhan marked this pull request as ready for review March 13, 2026 13:34
CopilotAI review requested due to automatic review settings March 13, 2026 13:34

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes cross-repo dispatch-workflow in workflow_call relay scenarios by ensuring the dispatched workflow uses a ref that exists in the target repository (not the caller’s GITHUB_REF).

Changes:

  • Runtime: add config["target-ref"] as highest-priority ref source during dispatch ref resolution.
  • Compiler: inject target-ref for workflow_call relays and include it in the handler-manager config payload.
  • Docs/schema/tests: document target-ref, extend JSON schema, and add runtime tests covering precedence.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
actions/setup/js/dispatch_workflow.cjsPrefers target-ref over PR/push refs when dispatching.
actions/setup/js/dispatch_workflow.test.cjsAdds tests validating new ref precedence behavior.
pkg/workflow/compiler_safe_outputs_config.goEmits target-ref in handler config and injects it for workflow_call relays.
pkg/workflow/dispatch_workflow.goAdds TargetRef to config and parses target-ref from frontmatter.
pkg/parser/schemas/main_workflow_schema.jsonAdds target-repo/target-ref to the dispatch-workflow schema definition.
docs/src/content/docs/reference/safe-outputs-specification.mdDocuments target-ref and auto-injection behavior for relay flows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

if targetRef, ok := configMap["target-ref"].(string); ok && targetRef != "" {
dispatchWorkflowConfig.TargetRef = targetRef
}

Comment on lines +742 to +746
}
if safeOutputs.DispatchWorkflow.TargetRef == "" {
safeOutputs = safeOutputsWithDispatchTargetRef(safeOutputs, "${{ needs.activation.outputs.target_ref }}")
compilerSafeOutputsConfigLog.Print("Injecting target_ref into dispatch_workflow config for workflow_call relay")
}
@pelikhan
pelikhan merged commit a6ff9c1 into mainMar 13, 2026
85 checks passed
@pelikhan
pelikhan deleted the copilot/fix-dispatch-workflow-ref branch March 13, 2026 13:41
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dispatch-workflow uses caller's GITHUB_REF for cross-repo dispatch instead of target repo's default branch

3 participants

@pelikhan