Skip to content

Generate baseline-update PRs for internal branches - #7051

Merged
mthalman merged 6 commits into
mainfrom
dev/mthalman/issue5352
Jun 5, 2026
Merged

mthalman merged 6 commits into
mainfrom
dev/mthalman/issue5352

Conversation

@mthalman

@mthalman mthalman commented Jun 4, 2026

Copy link
Copy Markdown
Member

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.

Fixes dotnet/source-build#5352

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.
Copilot AI review requested due to automatic review settings June 4, 2026 15:48
@mthalman
mthalman requested review from a team as code owners June 4, 2026 15:48

Copilot AI 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

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 GitClient wrapper 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 single GIT_TOKEN env 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.

mthalman and others added 4 commits June 4, 2026 12:22
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]>

Copilot AI 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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

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]>

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot stopped reviewing on behalf of mthalman due to an error June 4, 2026 19:05
Copilot stopped reviewing on behalf of mthalman due to an error June 4, 2026 19:26

@ellahathaway ellahathaway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review: 2 findings (1 potential bug, 1 observability gap).

@mthalman
mthalman requested a review from ellahathaway June 5, 2026 14:47
@mthalman
mthalman merged commit 3ab08f7 into main Jun 5, 2026
11 of 13 checks passed
@mthalman
mthalman deleted the dev/mthalman/issue5352 branch June 5, 2026 15:56
@ellahathaway

Copy link
Copy Markdown
Member

/backport to release/10.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.1xx (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@ellahathaway backporting to release/10.0.1xx failed, the patch most likely resulted in conflicts. Please backport manually!

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

Link to workflow output

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.

Generated baseline update PRs for internal branches

3 participants