Skip to content

Commit 3969355

Browse files
committed
Use Version.Details.xml as primary VMR snapshot source
Version.Details.xml's <Source Sha=...> is the authoritative record of which VMR commit a product repo branch is based on. Previously the script treated it as a fallback after commit message parsing. Now it's checked first, with commit messages as secondary confirmation. This correctly handles: - Manual backflow (darc vmr backflow pushed directly) - Normal codeflow (Maestro-managed) - Conflicted PRs (VD.xml reflects pre-codeflow state) - Forward flow PRs (skips VD.xml, uses commit messages) Tested against sdk#52727 (manual backflow) and sdk#52885 (conflicted).
1 parent a9ea742 commit 3969355

File tree

1 file changed

+50
-36
lines changed

1 file changed

+50
-36
lines changed

.github/skills/vmr-codeflow-status/scripts/Get-CodeflowStatus.ps1

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -402,69 +402,79 @@ $freshnessRepoLabel = if ($isForwardFlow) { $sourceRepo } else { "VMR" }
402402
# Pre-load PR commits for use in validation and later analysis
403403
$prCommits = $pr.commits
404404

405-
# --- Step 2b: Cross-reference PR body snapshot against actual branch commits ---
405+
# --- Step 2b: Determine actual VMR snapshot on the PR branch ---
406+
# Priority: 1) Version.Details.xml (ground truth), 2) commit messages, 3) PR body
406407
$branchVmrCommit = $null
408+
$commitMsgVmrCommit = $null
409+
$versionDetailsVmrCommit = $null
410+
411+
# First: check eng/Version.Details.xml on the PR branch (authoritative source)
412+
if (-not $isForwardFlow) {
413+
$vdContent = Invoke-GitHubApi "/repos/$Repository/contents/eng/Version.Details.xml?ref=$([System.Uri]::EscapeDataString($pr.headRefName))" -Raw
414+
if ($vdContent -and $vdContent -match '<Source\s+[^>]*Sha="([a-fA-F0-9]+)"') {
415+
$versionDetailsVmrCommit = $Matches[1]
416+
$branchVmrCommit = $versionDetailsVmrCommit
417+
}
418+
}
419+
420+
# Second: scan commit messages for "Backflow from" / "Forward flow from" SHAs
407421
if ($prCommits) {
408-
# Look through PR branch commits (newest first) for "Backflow from" or "Forward flow from" messages
409-
# containing the actual VMR/source SHA that was used to create the branch content
410422
$reversedCommits = @($prCommits)
411423
[Array]::Reverse($reversedCommits)
412424
foreach ($c in $reversedCommits) {
413425
$msg = $c.messageHeadline
414-
# Backflow commits: "Backflow from https://github.com/dotnet/dotnet / <sha> build <id>"
415426
if ($msg -match '(?:Backflow|Forward flow) from .+ / ([a-fA-F0-9]+)') {
416-
$branchVmrCommit = $Matches[1]
417-
# Keep scanning — we want the most recent (last in original order = first in reversed)
427+
$commitMsgVmrCommit = $Matches[1]
418428
break
419429
}
420430
}
431+
# For forward flow (no Version.Details.xml source), commit messages are primary
432+
if (-not $branchVmrCommit -and $commitMsgVmrCommit) {
433+
$branchVmrCommit = $commitMsgVmrCommit
434+
}
421435
}
422436

423437
if ($branchVmrCommit -or $vmrCommit) {
424438
Write-Section "Snapshot Validation"
425439
$usedBranchSnapshot = $false
426-
if ($branchVmrCommit -and $vmrCommit) {
427-
$bodyShort = Get-ShortSha $vmrCommit
428-
$branchShort = $branchVmrCommit # already short from commit message
429-
if ($vmrCommit.StartsWith($branchVmrCommit) -or $branchVmrCommit.StartsWith($vmrCommit)) {
430-
Write-Host " ✅ PR body snapshot ($bodyShort) matches branch commit ($branchShort)" -ForegroundColor Green
431-
}
432-
else {
433-
Write-Host " ⚠️ MISMATCH: PR body claims $(Get-ShortSha $vmrCommit) but branch commit references $branchVmrCommit" -ForegroundColor Red
434-
Write-Host " The PR body may be stale — using branch commit ($branchVmrCommit) for freshness check" -ForegroundColor Yellow
435-
# Resolve the short SHA from the branch commit to a full SHA for accurate comparison
436-
$resolvedCommit = Invoke-GitHubApi "/repos/$freshnessRepo/commits/$branchVmrCommit"
437-
if ($resolvedCommit) {
438-
$vmrCommit = $resolvedCommit.sha
439-
$usedBranchSnapshot = $true
440+
441+
if ($branchVmrCommit) {
442+
# We have a branch-derived snapshot (from Version.Details.xml or commit message)
443+
$branchShort = Get-ShortSha $branchVmrCommit
444+
$sourceLabel = if ($versionDetailsVmrCommit -and $branchVmrCommit -eq $versionDetailsVmrCommit) { "Version.Details.xml" } else { "branch commit" }
445+
446+
if ($vmrCommit) {
447+
$bodyShort = Get-ShortSha $vmrCommit
448+
if ($vmrCommit.StartsWith($branchVmrCommit) -or $branchVmrCommit.StartsWith($vmrCommit)) {
449+
Write-Host "$sourceLabel ($branchShort) matches PR body ($bodyShort)" -ForegroundColor Green
440450
}
441451
else {
442-
Write-Host " ⚠️ Could not resolve branch commit SHA $branchVmrCommit — falling back to PR body" -ForegroundColor Yellow
452+
Write-Host " ⚠️ MISMATCH: $sourceLabel has $branchShort but PR body claims $bodyShort" -ForegroundColor Red
453+
Write-Host " PR body is stale — using $sourceLabel for freshness check" -ForegroundColor Yellow
443454
}
444455
}
445-
}
446-
elseif ($branchVmrCommit -and -not $vmrCommit) {
447-
Write-Host " ⚠️ PR body has no commit reference, but branch commit references $branchVmrCommit" -ForegroundColor Yellow
448-
Write-Host " Using branch commit for freshness check" -ForegroundColor Yellow
456+
else {
457+
Write-Host " ℹ️ PR body has no commit reference — using $sourceLabel ($branchShort)" -ForegroundColor Yellow
458+
}
459+
460+
# Resolve to full SHA for accurate comparison
449461
$resolvedCommit = Invoke-GitHubApi "/repos/$freshnessRepo/commits/$branchVmrCommit"
450462
if ($resolvedCommit) {
451463
$vmrCommit = $resolvedCommit.sha
452464
$usedBranchSnapshot = $true
453465
}
466+
elseif (-not $vmrCommit) {
467+
Write-Host " ⚠️ Could not resolve $sourceLabel SHA $branchShort" -ForegroundColor Yellow
468+
}
454469
}
455-
elseif ($vmrCommit -and -not $branchVmrCommit) {
470+
else {
471+
# No branch-derived snapshot — PR body only
456472
$commitCount = if ($prCommits) { $prCommits.Count } else { 0 }
457-
if ($commitCount -eq 1) {
458-
$firstMsg = $prCommits[0].messageHeadline
459-
if ($firstMsg -match "^Initial commit for subscription") {
460-
Write-Host " ℹ️ PR has only an initial subscription commit — PR body snapshot ($(Get-ShortSha $vmrCommit)) not yet verifiable from branch" -ForegroundColor DarkGray
461-
}
462-
else {
463-
Write-Host " ⚠️ No VMR SHA found in branch commit messages — trusting PR body ($(Get-ShortSha $vmrCommit))" -ForegroundColor Yellow
464-
}
473+
if ($commitCount -eq 1 -and $prCommits[0].messageHeadline -match "^Initial commit for subscription") {
474+
Write-Host " ℹ️ PR has only an initial subscription commit — PR body snapshot ($(Get-ShortSha $vmrCommit)) not yet verifiable" -ForegroundColor DarkGray
465475
}
466476
else {
467-
Write-Host " ⚠️ No VMR SHA found in $commitCount branch commit messages — trusting PR body ($(Get-ShortSha $vmrCommit))" -ForegroundColor Yellow
477+
Write-Host " ⚠️ Could not verify PR body snapshot ($(Get-ShortSha $vmrCommit)) from branch" -ForegroundColor Yellow
468478
}
469479
}
470480
}
@@ -485,7 +495,11 @@ if ($vmrCommit -and $vmrBranch) {
485495
if ($branchHead) {
486496
$sourceHeadSha = $branchHead.sha
487497
$sourceHeadDate = $branchHead.commit.committer.date
488-
$snapshotSource = if ($usedBranchSnapshot) { "from branch commit" } else { "from PR body" }
498+
$snapshotSource = if ($usedBranchSnapshot) {
499+
if ($versionDetailsVmrCommit -and $vmrCommit.StartsWith($versionDetailsVmrCommit)) { "from Version.Details.xml" }
500+
elseif ($commitMsgVmrCommit) { "from branch commit" }
501+
else { "from branch" }
502+
} else { "from PR body" }
489503
Write-Status "PR snapshot" "$(Get-ShortSha $vmrCommit) ($snapshotSource)"
490504
Write-Status "$freshnessRepoLabel HEAD" "$(Get-ShortSha $sourceHeadSha) ($sourceHeadDate)"
491505

0 commit comments

Comments
 (0)