From 61bcb7cf4da23aabb1419d82ad901a143d2e0d7d Mon Sep 17 00:00:00 2001 From: Brian Robbins Date: Tue, 25 Aug 2026 14:09:27 -0700 Subject: [PATCH] Enable GitHub Source Link for mirrored builds Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .pipelines/mirror.yml | 59 +++++++++++++++++++++++++++++++++++++ .pipelines/perfview-job.yml | 13 +++++++- src/Directory.Build.targets | 43 +++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) diff --git a/.pipelines/mirror.yml b/.pipelines/mirror.yml index 06e078856..ddb682983 100644 --- a/.pipelines/mirror.yml +++ b/.pipelines/mirror.yml @@ -104,6 +104,20 @@ extends: inputs: script: 'git checkout $(SourceBranch)' + - task: PowerShell@1 + displayName: 'Record GitHub Commit' + inputs: + scriptType: inlineScript + inlineScript: | + $githubCommit = (git rev-parse HEAD).Trim() + if ($LASTEXITCODE -ne 0 -or $githubCommit -notmatch '^[0-9a-f]{40}$') + { + Write-Error "Failed to resolve the GitHub commit." + exit 1 + } + + Write-Host "##vso[task.setvariable variable=GitHubCommit;]$githubCommit" + - task: CmdLine@2 displayName: 'Create Mirror Branch' inputs: @@ -120,6 +134,51 @@ extends: inputs: script: 'git pull --strategy=recursive --strategy-option no-renames https://x-access-token:$(AzdoToken)@devdiv.visualstudio.com/DevDiv/_git/perfView $(SourceBranch)' + - task: PowerShell@1 + displayName: 'Record GitHub Commit Metadata' + inputs: + scriptType: inlineScript + inlineScript: | + $ErrorActionPreference = 'Stop' + $existingCommit = @( + Get-Content internal/.github-last-mirrored-commit -ErrorAction SilentlyContinue | + Where-Object { $_ -and -not $_.TrimStart().StartsWith('#') } + ) + if ($existingCommit.Count -eq 1) + { + git merge-base --is-ancestor $existingCommit[0] $(GitHubCommit) + if ($LASTEXITCODE -eq 1) + { + Write-Error "The previously mirrored GitHub commit is not an ancestor of the commit being mirrored. This may indicate that mirror runs completed out of order or that GitHub history was rewritten; refusing to replace the recorded commit." + exit 1 + } + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + elseif ($existingCommit.Count -gt 1) + { + Write-Error "The mirrored GitHub commit metadata contains multiple commit values." + exit 1 + } + + $metadata = @( + '# This file is updated by .pipelines/mirror.yml when GitHub main is mirrored to Azure DevOps.' + '# Do not update this file manually.' + '$(GitHubCommit)' + ) + Set-Content -Path internal/.github-last-mirrored-commit -Value $metadata -Encoding Ascii + git add internal/.github-last-mirrored-commit + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + git diff --cached --quiet + if ($LASTEXITCODE -eq 1) + { + git commit -m "Update mirrored GitHub commit" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + elseif ($LASTEXITCODE -ne 0) + { + exit $LASTEXITCODE + } + - task: CmdLine@2 displayName: 'Run git push' inputs: diff --git a/.pipelines/perfview-job.yml b/.pipelines/perfview-job.yml index 69648ea88..968f6fb70 100644 --- a/.pipelines/perfview-job.yml +++ b/.pipelines/perfview-job.yml @@ -1,5 +1,7 @@ parameters: flavor: 'Debug' + sourceLinkRepositoryUrl: '' + sourceLinkRevisionId: '' steps: - task: UseDotNet@2 @@ -7,13 +9,22 @@ steps: inputs: version: 8.0.x +- task: MSBuild@1 + displayName: 'Restore PerfView.sln' + inputs: + solution: PerfView.sln + maximumCpuCount: true + msbuildArchitecture: 'x64' + msbuildArguments: '/t:restore' + configuration: ${{ parameters.flavor }} + - task: MSBuild@1 displayName: 'Build PerfView.sln' inputs: solution: PerfView.sln maximumCpuCount: true msbuildArchitecture: 'x64' - msbuildArguments: '/restore' + msbuildArguments: '/p:SourceLinkRepositoryUrl=${{ parameters.sourceLinkRepositoryUrl }} /p:SourceLinkRevisionId=${{ parameters.sourceLinkRevisionId }}' configuration: ${{ parameters.flavor }} - task: VisualStudioTestPlatformInstaller@1 diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index 4f9bec1bd..b5c34dbfc 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -6,4 +6,47 @@ + + + $(SourceLinkRepositoryUrl) + $(SourceLinkRevisionId) + + + + + + + + + + + + $(SourceLinkRepositoryUrl) + $(SourceLinkRepositoryUrl) + + + + + + $(SourceLinkRepositoryUrl) + $(SourceLinkRepositoryUrl) + $(SourceLinkRevisionId) + + + +