Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 100 additions & 5 deletions azure-pipelines-insertion.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parameters:
- name: 'ComponentBranchName'
default: 'rel/18.7'
default: 'main'
- name: 'CreateDraftPR'
default: 'false'
- name: 'OptionalTitlePrefix'
Expand Down Expand Up @@ -44,7 +44,7 @@ schedules:
displayName: Daily midnight insertion to VS
branches:
include:
- rel/18.7
- main
Comment thread
nohwnd marked this conversation as resolved.
always: true

resources:
Expand Down Expand Up @@ -86,7 +86,7 @@ extends:
steps:

- task: PowerShell@2
displayName: 'Install .NET SDK from global.json'
displayName: '🚀 Install .NET SDK from global.json'
Comment thread
nohwnd marked this conversation as resolved.
Outdated
inputs:
targetType: inline
script: |
Expand All @@ -96,12 +96,16 @@ extends:
& eng/common/dotnet-install.ps1 -version $version -runtime ''

- task: AzureCLI@2
displayName: 'Run VS Insertion'
displayName: '🚀 Run VS Insertion'
inputs:
azureSubscription: 'DncEng Insertion: Roslyn and Razor'
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
# Disable .NET first-time experience to avoid delays
$env:DOTNET_NOLOGO = '1'
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'

# Install Roslyn insertion tools from the dnceng feed, using --tool-path as a workaround to avoid resetting the process to pick up dotnet tool path changes
$dotnet = "$(Build.SourcesDirectory)\.dotnet\dotnet.exe"
& $dotnet tool install Microsoft.RoslynTools --prerelease --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json --tool-path .
Expand Down Expand Up @@ -153,8 +157,99 @@ extends:
}

"Running: ./roslyn-tools.exe $($insertArgs -join ' ')"
Comment thread
nohwnd marked this conversation as resolved.
Comment thread
nohwnd marked this conversation as resolved.
Comment thread
nohwnd marked this conversation as resolved.
./roslyn-tools.exe @insertArgs
$roslynOutput = ./roslyn-tools.exe @insertArgs 2>&1 | ForEach-Object { Write-Host $_; $_ }
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

# Push vstest.console app.config to the insertion PR branch in the VS repo.
# The file maps to src/vset/Agile/TestPlatform/RocksteadyCLI/App.config in VS.
$devdivToken = "$(dn-bot-devdiv-build-e-code-full-release-e-packaging-r)"
$base64Token = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$devdivToken"))
$headers = @{
Authorization = "Basic $base64Token"
'Content-Type' = 'application/json'
}

$devdivOrg = "https://dev.azure.com/devdiv"
$project = "DevDiv"
$vsRepoId = "a290117c-5a8a-40f7-bc2c-f14dbe3acf6d"
$targetFilePath = "/src/vset/Agile/TestPlatform/RocksteadyCLI/App.config"

# Extract the PR number from roslyn-tools output.
# The tool logs a PR URL like: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/735439
# We match the URL pattern specifically to avoid grabbing timestamps from PR titles.
$outputText = $roslynOutput -join "`n"
$prId = $null
if ($outputText -match '/pullrequest/(\d+)') {
$prId = $Matches[1]
} elseif ($outputText -match 'pullrequests/(\d+)') {
$prId = $Matches[1]
}

if (-not $prId) {
Write-Error "Could not extract PR ID from roslyn-tools output. Cannot push App.config."
Write-Host "roslyn-tools output was:"
Write-Host $outputText
exit 1
Comment thread
nohwnd marked this conversation as resolved.
}
Comment thread
nohwnd marked this conversation as resolved.
Comment thread
nohwnd marked this conversation as resolved.
else {
Write-Host "Detected insertion PR #$prId, pushing App.config..."

try {
# Get the PR to find its source branch
$prUrl = "$devdivOrg/$project/_apis/git/repositories/$vsRepoId/pullrequests/${prId}?api-version=7.1"
$pr = Invoke-RestMethod -Uri $prUrl -Headers $headers -Method Get
$sourceBranch = $pr.sourceRefName
Write-Host "PR source branch: $sourceBranch"

# Get the latest commit on the insertion branch
$refFilter = ($sourceBranch -replace '^refs/', '')
$encodedFilter = [Uri]::EscapeDataString($refFilter)
$refUrl = "$devdivOrg/$project/_apis/git/repositories/$vsRepoId/refs?filter=$encodedFilter&api-version=7.1"
$refResponse = Invoke-RestMethod -Uri $refUrl -Headers $headers -Method Get
if (-not $refResponse.value -or $refResponse.value.Count -eq 0) {
throw "Could not resolve ref for branch $sourceBranch"
}
$latestCommitId = $refResponse.value[0].objectId

Comment thread
nohwnd marked this conversation as resolved.
Comment thread
nohwnd marked this conversation as resolved.
# Read the app.config from the vstest checkout
$appConfigContent = Get-Content -Raw -Path "$(Build.SourcesDirectory)/src/vstest.console/app.config"
Comment thread
nohwnd marked this conversation as resolved.

# Push the app.config to the insertion branch
$pushUrl = "$devdivOrg/$project/_apis/git/repositories/$vsRepoId/pushes?api-version=7.1"
$pushBody = @{
refUpdates = @(
@{
name = $sourceBranch
oldObjectId = $latestCommitId
}
)
commits = @(
@{
comment = "Update RocksteadyCLI App.config from vstest"
changes = @(
@{
changeType = "edit"
item = @{
path = $targetFilePath
}
newContent = @{
content = $appConfigContent
contentType = "rawtext"
}
}
)
}
)
} | ConvertTo-Json -Depth 10

$pushResponse = Invoke-RestMethod -Uri $pushUrl -Headers $headers -Method Post -Body $pushBody
Write-Host "Pushed App.config to insertion branch. Commit: $($pushResponse.commits[0].commitId)"
}
catch {
Write-Error "Failed to push App.config to insertion branch: $_"
exit 1
}
}