-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathazure-pipelines-insertion.yml
More file actions
294 lines (263 loc) · 13.8 KB
/
azure-pipelines-insertion.yml
File metadata and controls
294 lines (263 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
parameters:
- name: 'ComponentBranchName'
default: 'main'
- name: 'CreateDraftPR'
default: 'false'
- name: 'OptionalTitlePrefix'
default: '[Auto Insertion]'
- name: 'VisualStudioBranchName'
default: 'main'
variables:
- group: DotNet-Roslyn-Insertion-Variables
- template: /eng/common/templates-official/variables/pool-providers.yml@self
- name: BuildQueueName
value: 'microsoft-vstest'
- name: ComponentAzdoUri
value: 'https://dev.azure.com/dnceng'
- name: ComponentProjectName
value: 'internal'
- name: ComponentName
value: 'VS Test Platform'
- name: DropPath
value: '/dp=microsoft-vstest/VSSetupArtifacts'
- name: SpecificBuildNumber
value: ''
- name: CherryPick
value: ''
- name: AutoComplete
value: 'true'
- name: ComponentBranchName
value: '${{ parameters.ComponentBranchName }}'
- name: CreateDraftPR
value: '${{ parameters.CreateDraftPR }}'
- name: OptionalTitlePrefix
value: '${{ parameters.OptionalTitlePrefix }}'
- name: VisualStudioBranchName
value: '${{ parameters.VisualStudioBranchName }}'
trigger: none
schedules:
# insert at 1am on monday, wednesday and friday
- cron: 0 1 * * 1,3,5
displayName: Daily midnight insertion to VS
branches:
include:
- main
always: true
resources:
repositories:
- repository: 1ESPipelineTemplates
type: git
name: 1ESPipelineTemplates/1ESPipelineTemplates
ref: refs/tags/release
extends:
template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates
parameters:
sdl:
policheck:
enabled: true
tsa:
enabled: true
pool:
name: $(DncEngInternalBuildPool)
image: windows.vs2026preview.scout.amd64
os: windows
settings:
networkIsolationPolicy: Permissive,CFSClean
customBuildTags:
- ES365AIMigrationTooling
stages:
- stage: insert
displayName: Insert
jobs:
- template: /eng/common/templates-official/jobs/jobs.yml@self
parameters:
jobs:
- job: insert
displayName: Insert
pool:
name: $(DncEngInternalBuildPool)
demands: ImageOverride -equals windows.vs2026preview.scout.amd64
timeoutInMinutes: 90
steps:
- task: PowerShell@2
displayName: 'Install .NET SDK from global.json'
inputs:
targetType: inline
script: |
$globalJson = Get-Content -Raw global.json | ConvertFrom-Json
$version = $globalJson.sdk.version
Write-Host "Installing .NET SDK version $version from global.json"
& eng/common/dotnet-install.ps1 -version $version -runtime ''
- task: AzureCLI@2
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 .
# Acquire dnceng AzDO token via WIF service connection
$dncengToken = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($dncengToken)) {
Write-Error 'Failed to acquire Azure DevOps access token via WIF.'
exit 1
}
# Add VS Interactive experiences team (from devdiv) as reviewer
$team = "10a2f33b-3b3d-47a9-a22f-6bb09247bb63"
$insertArgs = @(
"create-insertion"
"--vs-branch", "$(VisualStudioBranchName)"
"--component-branch", "$(ComponentBranchName)"
"--insertion-name", "$(ComponentName)"
"--component-build-queue", "$(BuildQueueName)"
"--component-azdo-uri", "$(ComponentAzdoUri)"
"--component-project", "$(ComponentProjectName)"
"--build-drop-path", "$(DropPath)"
"--insert-corext-packages", "false"
"--insert-devdiv-source-files", "false"
"--title-prefix", "$(OptionalTitlePrefix)"
"--reviewer-guid", $team
"--dnceng-azdo-token", $dncengToken
"--devdiv-azdo-token", "$(dn-bot-devdiv-build-e-code-full-release-e-packaging-r)"
"--ci"
)
if ("$(AutoComplete)" -eq "true") {
$insertArgs += "--set-auto-complete"
}
if ("$(CreateDraftPR)" -eq "true") {
$insertArgs += "--create-draft-pr"
}
if (-not [string]::IsNullOrWhiteSpace("$(SpecificBuildNumber)")) {
$insertArgs += "--specific-build"
$insertArgs += "$(SpecificBuildNumber)"
}
if (-not [string]::IsNullOrWhiteSpace("$(CherryPick)")) {
$insertArgs += "--cherry-pick"
$insertArgs += "$(CherryPick)"
}
"Running: ./roslyn-tools.exe $($insertArgs -join ' ')"
$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
}
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
# Fetch the app.config from the mirror repo at the exact commit used by the insertion.
# roslyn-tools logs "Found microsoft-vstest build number X" — resolve the source commit from that build.
$mirrorRepoId = "microsoft-vstest"
$dncengBase = "https://dnceng.visualstudio.com/internal"
$dncengHeaders = @{
Authorization = "Bearer $dncengToken"
}
$sourceCommit = $null
# Extract the build ID from the "Updated Updating VS Test Platform from [...] to [buildnum](url) ([sha](sourcesUrl))" line.
# We use the build ID to resolve the full commit SHA via the builds API.
if ($outputText -match 'Updated Updating VS Test Platform from .+ to \[\S+\]\([^)]+\) \(\[[0-9a-f]{7,40}\]\(https://dev\.azure\.com/dnceng/[^)]+/_apis/build/builds/(\d+)/sources\)\)') {
$sourceBuildId = $Matches[1]
Write-Host "Resolving source commit from build ID $sourceBuildId"
$buildUrl = "$dncengBase/_apis/build/builds/${sourceBuildId}?api-version=7.1"
$buildResponse = Invoke-RestMethod -Uri $buildUrl -Headers $dncengHeaders -Method Get
$sourceCommit = $buildResponse.sourceVersion
}
if (-not $sourceCommit) {
# Fallback: resolve source commit from build number via AzDO API
if ($outputText -match 'Found microsoft-vstest build number (\S+)') {
$buildNumber = $Matches[1]
Write-Host "Resolving source commit from build number $buildNumber"
$buildsUrl = "$dncengBase/_apis/build/builds?buildNumber=$buildNumber&api-version=7.1"
$buildsResponse = Invoke-RestMethod -Uri $buildsUrl -Headers $dncengHeaders -Method Get
if ($buildsResponse.value -and $buildsResponse.value.Count -gt 0) {
$sourceCommit = $buildsResponse.value[0].sourceVersion
}
}
}
if (-not $sourceCommit) {
throw "Could not determine source commit from roslyn-tools output"
}
Write-Host "Fetching app.config from mirror repo at commit $sourceCommit"
$encodedPath = [Uri]::EscapeDataString("/src/vstest.console/app.config")
$itemUrl = "$dncengBase/_apis/git/repositories/$mirrorRepoId/items?path=$encodedPath&versionDescriptor.version=$sourceCommit&versionDescriptor.versionType=commit&api-version=7.1"
$appConfigContent = Invoke-RestMethod -Uri $itemUrl -Headers $dncengHeaders -Method Get
# 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
}
}