Repository navigation
Generate baseline-update PRs for internal branches - #7051
Conversation
The baseline-update PR tool previously only knew how to push to GitHub, so `internal/release` builds silently skipped PR creation entirely. The tool now targets the AzDO repo when running on `internal/release/*` branches, while public branches (`main`, `release/*`) continue to use GitHub.
## Implementation
- Replace Octokit with DarcLib's `IRemoteGitRepo` abstraction.
- Use a deterministic head branch name (`pr-baseline-{pipeline}-{sanitized-target}-{hash}`) so PR lookup can work via DarcLib's branch-only `SearchPullRequestsAsync` (DarcLib doesn't expose search-by-title).
- Pipeline YAML: two-level template (wrapper handles branch routing + token selection; runner invokes the tool with a single `GIT_TOKEN` env var). Public branches use `BotAccount-dotnet-sb-bot-pat`; `internal/release` uses a federated-identity-backed AzDO token. The two paths are gated by mutually-exclusive branch conditions so the wrong-provider secret is never in env scope.
## Differences vs. the prior Octokit-based implementation
- Provider: GitHub-only -> GitHub + AzDO.
- Head branch name: timestamp-based (new branch per run) -> deterministic per pipeline + target branch. Means existing open baseline PRs created by the prior tool will NOT be matched by the new branch-based lookup -- see "Deploy step" below.
- Pre-push merge: the Octokit tool merged target into the PR branch before pushing. DarcLib's `IRemoteGitRepo` abstraction doesn't expose a server-side merge primitive, and adding per-provider escapes for it isn't justified for this use case. Consequence: a long-lived baseline PR may show "behind target" in the PR UI.
There was a problem hiding this comment.
Pull request overview
This PR updates the CreateBaselineUpdatePR tooling and pipeline wiring so baseline-update PRs are created for both public branches (GitHub) and internal/release/* branches (Azure DevOps), using DarcLib’s IRemoteGitRepo abstraction and deterministic head-branch naming for PR discovery.
Changes:
- Replaced Octokit-based PR creation with DarcLib-based Git operations supporting both GitHub and Azure DevOps repos.
- Added a provider-agnostic
GitClientwrapper plus concrete GitHub/AzDO implementations for PR URL construction. - Refactored AzDO pipeline templates to route by branch (public vs
internal/release/*) and to provide a singleGIT_TOKENenv var to the tool.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| eng/tools/CreateBaselineUpdatePR/Program.cs | Switches CLI token handling to a generic --token/GIT_TOKEN flow and constructs the DarcLib-backed GitClient. |
| eng/tools/CreateBaselineUpdatePR/PRCreator.cs | Replaces Octokit logic with DarcLib operations, deterministic head branch naming, and a diff-based commit model. |
| eng/tools/CreateBaselineUpdatePR/GitHubGitClient.cs | Adds GitHub-specific GitClient implementation and PR URL helpers. |
| eng/tools/CreateBaselineUpdatePR/GitClient.cs | Introduces provider-agnostic wrapper and factory for GitHub vs AzDO. |
| eng/tools/CreateBaselineUpdatePR/CreateBaselineUpdatePR.csproj | Removes Octokit dependency and adds DarcLib. |
| eng/tools/CreateBaselineUpdatePR/AzureDevOpsGitClient.cs | Adds Azure DevOps-specific GitClient implementation and PR URL helpers. |
| eng/pipelines/templates/steps/run-baseline-update-pr-tool.yml | New runner template that invokes the tool and supplies GIT_TOKEN. |
| eng/pipelines/templates/steps/create-baseline-update-pr.yml | Routes to GitHub vs AzDO based on branch and selects the appropriate token mechanism. |
| eng/pipelines/templates/stages/vmr-license-scan.yml | Expands PR publishing condition to include internal/release/* branches and updates template parameters. |
| eng/pipelines/templates/jobs/sdk-diff-tests.yml | Always invokes the baseline PR template when publishTestResultsPr is enabled (branch routing handled inside the wrapper template). |
| eng/pipelines/templates/jobs/reproducibility-test.yml | Same as above for reproducibility jobs. |
| eng/dependabot/Directory.Packages.props | Removes the now-unused Octokit version pin from the dependabot-managed set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Switch the token validation from IsNullOrEmpty to IsNullOrWhiteSpace so a token consisting solely of whitespace (e.g. an unexpanded variable that expanded to spaces) is rejected with the explicit ArgumentException at startup instead of producing a confusing auth failure later. Co-authored-by: Copilot <[email protected]>
Make the prefix-stripping StartsWith check explicit about its intent by passing StringComparison.Ordinal. File paths are case-sensitive byte sequences (especially on Linux/macOS where the tool actually runs) and should never participate in culture-sensitive collation. Co-authored-by: Copilot <[email protected]>
The baseline key (e.g. a NuGet id or file name fragment) is matched against repository-relative paths, which are exact byte sequences. Add StringComparison.Ordinal so the lookup is unambiguously culture-insensitive and slightly faster. Co-authored-by: Copilot <[email protected]>
UpdateFile() locates the existing tree entry by file-name fragment. Path matching here should be culture-insensitive, so make the StringComparison explicit with Ordinal. Co-authored-by: Copilot <[email protected]>
The try/catch around DeleteBranchAsync swallowed errors and continued, but the subsequent CreateBranchAsync no-ops on an existing ref (both GitHub's POST git/refs and DarcLib's AzDO client treat an existing ref as success). The post-create DoesBranchExistAsync probe then passed against the stale branch and the next CommitFilesWithNoCloningAsync committed on top of leftover content from the previous PR. Drop the catch so deletion failures surface as a pipeline failure instead of producing a quietly-incorrect PR. Co-authored-by: Copilot <[email protected]>
ellahathaway
left a comment
There was a problem hiding this comment.
Review: 2 findings (1 potential bug, 1 observability gap).
|
/backport to release/10.0.1xx |
|
Started backporting to |
|
@ellahathaway backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Generate baseline-update PRs for internal branches
.git/rebase-apply/patch:897: trailing whitespace.
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
A eng/dependabot/Directory.Packages.props
A eng/pipelines/templates/jobs/reproducibility-test.yml
M eng/pipelines/templates/steps/create-baseline-update-pr.yml
M eng/tools/CreateBaselineUpdatePR/CreateBaselineUpdatePR.csproj
M eng/tools/CreateBaselineUpdatePR/PRCreator.cs
M eng/tools/CreateBaselineUpdatePR/Program.cs
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): eng/dependabot/Directory.Packages.props deleted in HEAD and modified in Generate baseline-update PRs for internal branches. Version Generate baseline-update PRs for internal branches of eng/dependabot/Directory.Packages.props left in tree.
CONFLICT (modify/delete): eng/pipelines/templates/jobs/reproducibility-test.yml deleted in HEAD and modified in Generate baseline-update PRs for internal branches. Version Generate baseline-update PRs for internal branches of eng/pipelines/templates/jobs/reproducibility-test.yml left in tree.
Auto-merging eng/pipelines/templates/steps/create-baseline-update-pr.yml
Auto-merging eng/tools/CreateBaselineUpdatePR/CreateBaselineUpdatePR.csproj
Auto-merging eng/tools/CreateBaselineUpdatePR/PRCreator.cs
CONFLICT (content): Merge conflict in eng/tools/CreateBaselineUpdatePR/PRCreator.cs
Auto-merging eng/tools/CreateBaselineUpdatePR/Program.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Generate baseline-update PRs for internal branches
Error: The process '/usr/bin/git' failed with exit code 128 |
The baseline-update PR tool previously only knew how to push to GitHub, so
internal/releasebuilds silently skipped PR creation entirely. The tool now targets the AzDO repo when running oninternal/release/*branches, while public branches (main,release/*) continue to use GitHub.Implementation
Replace Octokit with DarcLib's
IRemoteGitRepoabstraction.Use a deterministic head branch name (
pr-baseline-{pipeline}-{sanitized-target}-{hash}) so PR lookup can work via DarcLib's branch-onlySearchPullRequestsAsync(DarcLib doesn't expose search-by-title).Pipeline YAML: two-level template (wrapper handles branch routing + token selection; runner invokes the tool with a single
GIT_TOKENenv var). Public branches useBotAccount-dotnet-sb-bot-pat;internal/releaseuses a federated-identity-backed AzDO token. The two paths are gated by mutually-exclusive branch conditions so the wrong-provider secret is never in env scope.Differences vs. the prior Octokit-based implementation
Provider: GitHub-only -> GitHub + AzDO.
Head branch name: timestamp-based (new branch per run) -> deterministic per pipeline + target branch. Means existing open baseline PRs created by the prior tool will NOT be matched by the new branch-based lookup -- see "Deploy step" below.
Pre-push merge: the Octokit tool merged target into the PR branch before pushing. DarcLib's
IRemoteGitRepoabstraction doesn't expose a server-side merge primitive, and adding per-provider escapes for it isn't justified for this use case. Consequence: a long-lived baseline PR may show "behind target" in the PR UI.Fixes dotnet/source-build#5352