Skip to content

[devops] Fix apidiff GitHub comment step failing on git ancestry check Fixes #26107#26144

Open
rolfbjarne wants to merge 1 commit into
mainfrom
dev/rolf/issue-26107-ci-api-diff-publish-github-comment-for-d1e9e3
Open

[devops] Fix apidiff GitHub comment step failing on git ancestry check Fixes #26107#26144
rolfbjarne wants to merge 1 commit into
mainfrom
dev/rolf/issue-26107-ci-api-diff-publish-github-comment-for-d1e9e3

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

The "Publish GitHub comment for change detection" step in the apidiff pipeline intermittently failed (marking builds partiallySucceeded) with:

Error checking if current commit is latest in PR: Failed to determine whether '<commit>' is an ancestor of 'origin/<target_branch>'.

Root cause

The git helpers Test-GitIsAncestor (git merge-base --is-ancestor) and Get-GitCommitParents (git rev-list) in GitHub.psm1 leave a non-zero $LASTEXITCODE behind. IsCurrentCommitLatestInPR catches the thrown exception and returns true (so the comment is still computed), but the leaked native git exit code propagates to the end of the Azure DevOps pwsh inline script (which ends with exit $LASTEXITCODE), so the step is reported as failed.

This happens on the Windows apidiff agents when origin/<target_branch> isn't available in the shallow clone (merge-base exits with a non-0/1 code), and also in the ordinary "not an ancestor" (exit 1) case.

Fix

  • Capture the git exit code and reset $LASTEXITCODE to 0 in both helpers so it never leaks out and fails the enclosing task.
  • Fix a pre-existing bug: git rev-list --parents -n 1 -- $Commit placed -- before the commit, so git treated it as a pathspec and always failed with usage exit 129 — meaning merge-parent detection never actually worked. Removed the erroneous --.
  • Added Pester tests covering both helpers, verifying the return value and that $LASTEXITCODE stays 0 across the ancestor, non-ancestor and unresolvable-ref cases.

Fixes #26107

🤖 Pull request created by Copilot

The 'Publish GitHub comment for change detection' pwsh step in the apidiff
pipeline could fail (marking the build partiallySucceeded) with:

    Error checking if current commit is latest in PR: Failed to determine
    whether '<commit>' is an ancestor of 'origin/<target_branch>'.

Root cause: the git helper functions Test-GitIsAncestor (git merge-base
--is-ancestor) and Get-GitCommitParents (git rev-list) leave a non-zero
$LASTEXITCODE behind. IsCurrentCommitLatestInPR catches the thrown
exception and returns true (so the comment is still computed), but the
leaked native exit code propagates to the end of the Azure DevOps pwsh
inline script (which ends with 'exit $LASTEXITCODE'), failing the step.
This happens on the Windows apidiff agents when origin/<target_branch>
isn't available in the shallow clone (merge-base exits with a non-0/1
code), and also in the ordinary 'not an ancestor' (exit 1) case.

Fix: capture the git exit code and reset $LASTEXITCODE to 0 in both
helpers so it never leaks out.

Also fix a pre-existing bug: 'git rev-list --parents -n 1 -- $Commit'
placed '--' before the commit, so git treated it as a pathspec and always
failed with usage exit 129, meaning merge-parent detection never worked.
Removed the erroneous '--'.

Added Pester tests covering both helpers, verifying the return value and
that $LASTEXITCODE stays 0 across the ancestor, non-ancestor and
unresolvable-ref cases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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 fixes intermittent failures in the API diff pipeline’s “Publish GitHub comment for change detection” step by preventing native git exit codes from leaking out of PowerShell helper functions (which could otherwise cause the Azure DevOps pwsh task to exit non-zero).

Changes:

  • Fix Get-GitCommitParents to call git rev-list correctly (removes an erroneous -- that made the command fail) and ensure $LASTEXITCODE is reset after invocation.
  • Fix Test-GitIsAncestor to capture the git merge-base --is-ancestor exit code and reset $LASTEXITCODE so it can’t propagate to the enclosing task.
  • Add Pester coverage for both helpers, including “success”, “failure”, and “unresolvable ref” scenarios, and assertions that $LASTEXITCODE remains 0.

Reviewed changes

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

File Description
tools/devops/automation/scripts/GitHub.psm1 Fixes git helper implementations to avoid leaking native exit codes and corrects rev-list invocation.
tools/devops/automation/scripts/GitHub.Tests.ps1 Adds Pester tests validating helper return values and verifying $LASTEXITCODE is not leaked.

Comment thread tools/devops/automation/scripts/GitHub.Tests.ps1
Comment thread tools/devops/automation/scripts/GitHub.Tests.ps1
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #1fd6119] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 203 tests passed 🎉

Tests counts

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 19 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 19 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 1fd611914a973a3efd935e92aae627a9579664da [PR build]

@rolfbjarne
rolfbjarne marked this pull request as ready for review July 17, 2026 14:36
@rolfbjarne
rolfbjarne enabled auto-merge (squash) July 17, 2026 14:37
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 1fd611914a973a3efd935e92aae627a9579664da [PR build]

Sign up for free to 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.

[CI] API diff: 'Publish GitHub comment for change detection' fails with git ancestry error

4 participants