fix(compiler): use push-to-pull-request-branch target-repo for safe_outputs checkout#22244
fix(compiler): use push-to-pull-request-branch target-repo for safe_outputs checkout#22244
Conversation
…utputs checkout In buildSharedPRCheckoutSteps, only create-pull-request.target-repo was used to determine the checkout repository. When only push-to-pull-request-branch is configured with target-repo (as in smoke-update-cross-repo-pr), the safe_outputs job checked out github/gh-aw and set origin to github/gh-aw. Then push_to_pull_request_branch.cjs failed with exit code 128 trying to git fetch origin pr-branch from the wrong repo. Fix: add PushToPullRequestBranch.TargetRepoSlug as a fallback in the checkout target resolution chain. Recompile smoke-update-cross-repo-pr. Fixes #288 (smoke-update-cross-repo-pr 100% failure rate) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/gh-aw/sessions/81b48fe1-e860-480a-a840-8bfe6a5acd08
|
@copilot use a checkout manager instance in the compiler to handle multiple checkouts as needed in safe-outputs |
…target resolution Add GetPrimaryTargetRepo() and GenerateSafeOutputsCheckoutStep() to CheckoutManager. Add buildSafeOutputsCheckoutManager() to Compiler, which encapsulates the target-repo priority chain (create-pr > push-to-pr-branch > trial > default) using CheckoutManager. Refactor buildSharedPRCheckoutSteps to delegate checkout step generation and REPO_NAME resolution to the manager instance. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/gh-aw/sessions/15ee0c87-aef0-49b2-a00d-5cb3779f77c3
Done in f28614c. Refactored
|
|
@copilot the fallback startegy does not make sense. Each safe output should register the checkout they need and let the checkout manager handle it. |
…out registration Each safe output (create-pull-request, push-to-pull-request-branch) now independently registers its checkout requirement with CheckoutManager. CheckoutManager deduplicates registrations with the same (repository, path) key, so two outputs targeting the same cross-repo destination produce one checkout step. Trial-mode fallback only applies when no safe output has registered a cross-repo checkout. Add test for same-repo deduplication case. Rename existing "takes precedence" test to reflect the registration-order semantics. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/gh-aw/sessions/793077a6-1487-47a3-8a4a-a7ec33d2ff4c
Done in 1ba7f8a. Replaced the
|
There was a problem hiding this comment.
Pull request overview
Fixes safe_outputs cross-repo failures by ensuring the checkout step uses the correct target-repo when only push-to-pull-request-branch is configured, via a shared CheckoutManager that deduplicates checkout requirements.
Changes:
- Add
buildSafeOutputsCheckoutManagerto register per-safe-output checkout requirements and drive shared PR checkout/git-remote behavior. - Extend
CheckoutManagerwithGetPrimaryTargetRepo()andGenerateSafeOutputsCheckoutStep()and delegate safe-outputs checkout generation to it. - Add/extend tests for push-to-pull-request-branch cross-repo checkout and same/different-target registration behavior; recompile the smoke workflow lockfile.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/workflow/compiler_safe_outputs_steps.go | Builds a CheckoutManager from safe-output configs and delegates safe_outputs checkout + REPO_NAME selection to it. |
| pkg/workflow/checkout_manager.go | Adds helper methods to select the primary target repo and generate the safe_outputs checkout YAML step. |
| pkg/workflow/compiler_safe_outputs_steps_test.go | Adds test cases for cross-repo checkout via push-to-pull-request-branch and target repo selection behavior. |
| .github/workflows/smoke-update-cross-repo-pr.lock.yml | Regenerated workflow output showing correct repository: and REPO_NAME for the cross-repo case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| checkContains: []string{ | ||
| // Deduplication: same repo registered by both outputs → exactly one checkout | ||
| "repository: githubnext/gh-aw-side-repo", | ||
| `REPO_NAME: "githubnext/gh-aw-side-repo"`, | ||
| }, |
There was a problem hiding this comment.
The new "deduplicated to one checkout" case only asserts that the generated YAML contains the repository/REPO_NAME strings, but it doesn’t verify that only one checkout step (or only one repository: line) was emitted. As written, it would still pass if two identical checkout steps were generated. Consider asserting the count (e.g., strings.Count(stepsContent, "- name: Checkout repository") == 1 or counting repository: githubnext/gh-aw-side-repo).
| // CheckoutManager deduplicates registrations that share the same repository, | ||
| // so two outputs targeting the same repo result in a single checkout step. |
There was a problem hiding this comment.
Doc comment mismatch: buildSafeOutputsCheckoutManager says the manager “deduplicates registrations that share the same repository”, but CheckoutManager deduplication is keyed on (repository, path). Updating the comment to reflect (repository, path) (and that safe_outputs registrations currently always use the workspace root path) would avoid confusion for future readers.
| // CheckoutManager deduplicates registrations that share the same repository, | |
| // so two outputs targeting the same repo result in a single checkout step. | |
| // CheckoutManager deduplicates registrations that share the same (repository, path) | |
| // pair, and safe_outputs currently always use the workspace root path as the | |
| // checkout path. As a result, two outputs targeting the same repo result in a | |
| // single checkout step. |
|
@copilot review changes for consistency, clarity, |
…nt assertion - Update buildSafeOutputsCheckoutManager doc comment: "same repository" → "(repository, path) pair" to match CheckoutManager's actual deduplication key - Add checkCounts field to TestBuildSharedPRCheckoutSteps struct so tests can assert exact occurrence counts, not just presence - Use checkCounts in the same-target-repo deduplication test to verify exactly one "repository:" line is emitted when both outputs register the same repo Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/gh-aw/sessions/02c6726f-1025-4e71-901b-03950a7e296b
Done in 55e39e1. Two consistency/clarity fixes:
|
smoke-update-cross-repo-prhas a 100% scheduled failure rate because thesafe_outputsjob checks out the wrong repository when onlypush-to-pull-request-branch(notcreate-pull-request) is configured with atarget-repo.Root cause
buildSharedPRCheckoutStepsonly readCreatePullRequests.TargetRepoSlugwhen determining which repo to check out. With justpush-to-pull-request-branchconfigured:github/gh-aw(the workflow repo, norepository:param)Configure Git credentialssetorigin→github/gh-awpush_to_pull_request_branch.cjsthen didgit fetch origin pr-branchand got exit code 128 — the branch only exists ingithubnext/gh-aw-side-repoFix
Each PR safe output (
create-pull-request,push-to-pull-request-branch) now independently registers its target-repo checkout requirement with aCheckoutManager. The manager deduplicates registrations that share the same(repository, path)key, so two outputs targeting the same cross-repo destination produce a single checkout step.The generated
safe_outputsjob forsmoke-update-cross-repo-prnow correctly emits:Changes
pkg/workflow/compiler_safe_outputs_steps.go—buildSafeOutputsCheckoutManagerreplaces the old priority chain with independent per-safe-output registration; each output appends itsCheckoutConfigdirectly;CheckoutManagerhandles deduplicationpkg/workflow/checkout_manager.go— addedGetPrimaryTargetRepo()andGenerateSafeOutputsCheckoutStep()methods;buildSharedPRCheckoutStepsdelegates checkout step generation andREPO_NAMEresolution to the managerpkg/workflow/compiler_safe_outputs_steps_test.go— added test cases: cross-repo checkout viapush-to-pull-request-branchalone; same-repo deduplication when both outputs register the same target; different target-repos uses the first-registered (create-pr) repo.github/workflows/smoke-update-cross-repo-pr.lock.yml— recompiled💬 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.