-
Notifications
You must be signed in to change notification settings - Fork 304
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
393 lines (367 loc) · 19 KB
/
Copy pathazure-pipelines.yml
File metadata and controls
393 lines (367 loc) · 19 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
trigger: none
# Branch(es) that trigger(s) build(s) on PR
pr:
branches:
include:
- "*"
paths:
exclude:
- .github/**
- .gitignore
- .devcontainer/*
- docs/*
- .vscode/*
- .markdownlint-cli2.jsonc
- .markdownlintignore
- CODE_OF_CONDUCT.md
- CONTRIBUTING.md
- README.md
- SECURITY.md
- azure-pipelines-official.yml
- azure-pipelines-codeql.yml
- "**/*.xlf"
parameters:
# This option should be used with caution. This is useful for unblocking circular deps issue with testanywhere
- name: SkipTests
displayName: "Skip tests"
type: boolean
default: False
variables:
# Cannot use key:value syntax in root defined variables
- name: _TeamName
value: MSTest
- name: _RunAsInternal
value: False
- name: _RunAsPublic
value: True
# OS-agnostic Microsoft.Testing.Platform report/dump arguments shared by the Release unit-test
# ("--test-modules") commands in the Windows job (below) and the Linux/MacOS jobs
# (eng/pipelines/steps/test-non-windows.yml). Keeping them in a single variable guarantees every OS
# emits the same set of reports (TRX + CTRF + JUnit + AzDO) so the published TestResults drops stay
# in sync. Only the test-module glob, --results-directory, and --diagnostic-output-directory differ
# per OS (path separators + .exe vs .dll), so those stay inline in each script.
# --report-trx / --report-trx-filename "{asm}_{tfm}.trx" — TRX per (assembly x TFM).
# --report-ctrf / --report-ctrf-filename "{asm}_{tfm}.ctrf.json" — CTRF JSON per (assembly x TFM).
# --report-junit / --report-junit-filename "{asm}_{tfm}.xml" — JUnit XML per (assembly x TFM).
# --report-azdo — surfaces failed tests in the AzDO UI.
# --report-azdo-summary — Markdown job summary uploaded to the build's Summary tab.
# --report-azdo-slow-test-history 30 — query the pipeline's own test history (last 30 days) and lower the
# per-test 'still running' threshold for historically fast tests. Mirrors the Debug path in
# test/Directory.Build.targets so Debug and Release dogfood the same AzDO surface.
# --report-azdo-slow-test-history-min-sample 10 / --report-azdo-slow-test-history-multiplier 3.0 — exercise
# the slow-test-history sub-options and their 'requires report-azdo-slow-test-history' validation. Values
# match the extension defaults, so they don't change which tests are flagged; they only keep the option
# surface covered.
# --report-azdo-flaky-history 30 — query test history (last 30 days) and annotate reported failures with
# flakiness context. Annotation only: it does NOT demote failures to warnings (that is the separate
# report-azdo-demote-known-flaky option, intentionally left off so a genuine regression is never hidden).
# --hangdump --hangdump-timeout 15m — dump a module that hangs past 15 minutes.
# The report-azdo history options (slow-test-history, flaky-history) authenticate via the SYSTEM_ACCESSTOKEN
# secret. It is now mapped onto the public Test/TestRelease steps below; fork PR builds don't receive the
# secret so the history service silently no-ops there, while trusted-branch builds exercise it end-to-end.
# Placeholders ({asm}/{tfm}) are resolved by Microsoft.Testing.Platform.Services.ArtifactNamingHelper.
- name: _ReleaseUnitTestReportArgs
value: '--report-trx --report-trx-filename "{asm}_{tfm}.trx" --report-ctrf --report-ctrf-filename "{asm}_{tfm}.ctrf.json" --report-azdo --report-azdo-summary --report-azdo-slow-test-history 30 --report-azdo-slow-test-history-min-sample 10 --report-azdo-slow-test-history-multiplier 3.0 --report-azdo-flaky-history 30 --report-junit --report-junit-filename "{asm}_{tfm}.xml" --hangdump --hangdump-timeout 15m'
stages:
- stage: build
displayName: Build
jobs:
# Lightweight job that classifies the PR diff into two scopes (product vs samples)
# and exposes them as output variables. Downstream jobs use them to skip work that
# the diff does not touch (so e.g. a samples-only Dependabot PR does not spin up
# the full Windows/Linux/macOS product matrix, and a product-only PR does not run
# the samples build).
#
# Fail-safe behaviour:
# - Non-PR triggers (manual queue, scheduled, etc.) leave SYSTEM_PULLREQUEST_TARGETBRANCH
# empty, so we emit "true" for both flags and run everything.
# - If the diff is empty (e.g. force-push to the same SHA), we also run everything.
# - Downstream conditions use `ne(..., 'false')` rather than `eq(..., 'true')`
# so a missing/empty output (e.g. detect step failed) still runs the job.
- job: DetectChanges
displayName: Detect changed paths
pool:
name: NetCore-Public
demands: ImageOverride -equals build.ubuntu.2204.amd64.open
steps:
- checkout: self
fetchDepth: 0
clean: false
- bash: |
set -euo pipefail
target="${SYSTEM_PULLREQUEST_TARGETBRANCH:-}"
# ADO exposes the target branch as a full ref (e.g. "refs/heads/main"); strip the
# "refs/heads/" prefix so it can be combined with the "origin/" remote-tracking prefix.
target="${target#refs/heads/}"
if [[ -z "${target}" ]]; then
echo "Not a PR build (SYSTEM_PULLREQUEST_TARGETBRANCH is empty); running all jobs."
hasProduct=true
hasSamples=true
else
echo "PR target branch: ${target}"
git fetch --no-tags --depth=200 origin "${target}" 2>/dev/null \
|| git fetch --no-tags origin "${target}"
base="$(git merge-base "origin/${target}" HEAD)"
echo "Diff range: ${base}..HEAD"
files="$(git diff --name-only "${base}" HEAD)"
echo "Changed files:"
echo "${files}"
if [[ -z "${files}" ]]; then
echo "No files changed in diff; running all jobs."
hasProduct=true
hasSamples=true
else
# A file is a "samples-affecting" change if it lives under samples/** or it is
# one of the eng/ scripts that drives the samples build (build-samples.ps1).
# Everything else is treated as a product change.
samples_pattern='^(samples/|eng/build-samples\.ps1$)'
if echo "${files}" | grep -Eqv "${samples_pattern}"; then
hasProduct=true
else
hasProduct=false
fi
if echo "${files}" | grep -Eq "${samples_pattern}"; then
hasSamples=true
else
hasSamples=false
fi
fi
fi
echo "hasProductChanges=${hasProduct}"
echo "hasSamplesChanges=${hasSamples}"
echo "##vso[task.setvariable variable=hasProductChanges;isOutput=true]${hasProduct}"
echo "##vso[task.setvariable variable=hasSamplesChanges;isOutput=true]${hasSamples}"
name: detect
displayName: Classify changed files
- template: /eng/common/templates/jobs/jobs.yml
parameters:
enableMicrobuild: true
enablePublishTestResults: true
testResultsFormat: 'vstest'
artifacts:
publish:
artifacts: true
logs: true
manifests: true
enableTelemetry: true
jobs:
- job: Windows
dependsOn: DetectChanges
condition: and(succeededOrFailed(), ne(dependencies.DetectChanges.outputs['detect.hasProductChanges'], 'false'))
timeoutInMinutes: 90
pool:
name: NetCore-Public
demands: ImageOverride -equals windows.vs2026preview.scout.amd64.open
variables:
- template: /eng/pipelines/variables/test-env-vars.yml
strategy:
matrix:
Release:
_BuildConfig: Release
Debug:
_BuildConfig: Debug
steps:
- template: /eng/pipelines/steps/install-windows-prereqs.yml
- task: PowerShell@2
displayName: 'Enable local dumps'
inputs:
targetType: 'inline'
script: |
New-Item -Path $(Build.SourcesDirectory)\artifacts\CrashDumps -ItemType Directory -Force
Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps"
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Value "$(Build.SourcesDirectory)\artifacts\CrashDumps" -PropertyType ExpandString -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpCount" -Value 10 -PropertyType DWord -Force
- script: eng\common\CIBuild.cmd
-configuration $(_BuildConfig)
-prepareMachine
/p:Publish=false
/p:Test=false
/p:FastAcceptanceTest=true
name: Build
displayName: Build
- ${{ if eq(parameters.SkipTests, False) }}:
# Because the build step is using -ci flag, restore is done in a local .packages directory.
# We need to pass NUGET_PACKAGES so that when dotnet test is doing evaluation phase on the projects, it can resolve .props/.targets from packages and import them.
# Otherwise, props/targets are not imported. It's important that they are imported so that IsTestingPlatformApplication ends up being set.
#
# -p:TestingPlatformCaptureOutput=false streams each test exe's stdout to the AzDO console at
# MessageImportance.High. Required so the silence-driven heartbeat (and per-test progress) emitted
# by Microsoft.Testing.Platform actually reaches the live build log; with the default (true), the
# output is buffered into a per-module .log file and only surfaced on failure, so no live progress
# is visible during long-running test sessions.
- script: dotnet test -c $(_BuildConfig) --no-build -bl:$(BUILD.SOURCESDIRECTORY)\artifacts\TestResults\$(_BuildConfig)\TestStep.binlog -p:UsingDotNetTest=true -p:TestingPlatformCaptureOutput=false
name: Test
displayName: Test
condition: and(succeeded(), eq(variables._BuildConfig, 'Debug'))
env:
# Expose the build's OAuth token so the report-azdo history options (slow-test-history /
# flaky-history injected by test/Directory.Build.targets) can query this pipeline's own
# test-result history. Secret variables are not auto-exposed to scripts, so the explicit mapping
# is required. Fork PR builds don't receive the secret, so the history service simply no-ops
# there; trusted branch builds exercise it end-to-end.
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
# Integration tests are redundant in Release—they spawn child processes that already cover
# both Debug and Release configurations. Use --test-modules to run only unit tests.
# Use *.exe to cover both net4x (native exe) and net8+/net9+ (apphost exe) in a single glob.
#
# --test-modules bypasses MSBuild evaluation, so test/Directory.Build.targets cannot inject
# any of its TestingPlatformCommandLineArguments. We therefore restore the subset of those
# options that makes sense in Release. The OS-agnostic report/dump flags (TRX + CTRF + JUnit +
# AzDO + hangdump) live in the $(_ReleaseUnitTestReportArgs) variable defined at the top of this
# file so the Windows and Linux/MacOS commands stay in sync; see that variable for the per-flag
# documentation. Only the test-module glob, --results-directory, and --diagnostic-output-directory
# are inlined here because they differ per OS (path separators + .exe vs .dll).
# Use *.exe to cover both net4x (native exe) and net8+/net9+ (apphost exe) in a single glob.
# We intentionally do NOT pass:
# --crashdump — gated on .NETCoreApp in Directory.Build.targets; the CrashDump extension's
# ValidateTestHostEnvironmentVariablesAsync hard-fails the run on non-NETCoreApp hosts
# (see src/Platform/Microsoft.Testing.Extensions.CrashDump/CrashDumpEnvironmentVariableProvider.cs),
# and this glob mixes net4x and net8+/net9+ hosts.
# --coverage — coverage upload is Debug-only (see "Merge coverage" / "Publish coverage to
# Azure DevOps" steps below), so collecting coverage in Release would just write unused
# .coverage files.
- script: dotnet test --no-build --test-modules "artifacts/bin/*UnitTests*/$(_BuildConfig)/**/*UnitTests.exe" --results-directory $(BUILD.SOURCESDIRECTORY)\artifacts\TestResults\$(_BuildConfig) $(_ReleaseUnitTestReportArgs) --diagnostic --diagnostic-output-directory $(BUILD.SOURCESDIRECTORY)\artifacts\log\$(_BuildConfig) --diagnostic-verbosity trace
name: TestRelease
displayName: Test (unit tests only)
condition: and(succeeded(), eq(variables._BuildConfig, 'Release'))
env:
# Expose the build's OAuth token so the report-azdo history options (slow-test-history /
# flaky-history in $(_ReleaseUnitTestReportArgs)) can query this pipeline's own test-result
# history. Secret variables are not auto-exposed to scripts, so the explicit mapping is required.
# Fork PR builds don't receive the secret, so the history service simply no-ops there; trusted
# branch builds exercise it end-to-end.
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- task: PublishBuildArtifacts@1
displayName: 'Publish Test Results folders'
inputs:
PathtoPublish: '$(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)'
ArtifactName: TestResults_Windows_$(_BuildConfig)_Attempt$(System.JobAttempt)
condition: always()
- task: CopyFiles@2
displayName: 'Copy binlogs'
inputs:
SourceFolder: '$(Build.SourcesDirectory)/artifacts/tmp/$(_BuildConfig)/testsuite'
Contents: |
**/*.binlog
TargetFolder: '$(Build.ArtifactStagingDirectory)/binlogs'
condition: and(always(), eq(variables._BuildConfig, 'Debug'))
- task: PublishBuildArtifacts@1
displayName: 'Publish integration tests binlogs'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/binlogs'
ArtifactName: Integration_Tests_Windows_Binlogs_$(_BuildConfig)
condition: and(always(), eq(variables._BuildConfig, 'Debug'))
# Publish coverage to Azure DevOps. PublishCodeCoverageResults@2 accepts the binary
# .coverage format Microsoft Code Coverage emits natively (per
# https://learn.microsoft.com/azure/devops/pipelines/tasks/reference/publish-code-coverage-results-v2:
# "The task supports all kinds of coverage formats such as: .coverage, .covx, .covb,
# .cjson, .xml, .lcov, pycov, etc."), and merges multiple files via the minimatch glob.
# Coverage shows up in the build's "Code Coverage" tab and on the build summary, one
# click from the GitHub PR status check (we used to upload to codecov.io here).
- task: PublishCodeCoverageResults@2
displayName: 'Publish coverage to Azure DevOps'
inputs:
summaryFileLocation: '$(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)/*.coverage'
pathToSources: '$(Build.SourcesDirectory)/src'
condition: and(succeededOrFailed(), eq(variables._BuildConfig, 'Debug'))
- task: PublishBuildArtifacts@1
displayName: 'Publish local dumps'
inputs:
PathtoPublish: '$(Build.SourcesDirectory)/artifacts/CrashDumps'
ArtifactName: TestResults_Windows_$(_BuildConfig)
condition: failed()
- job: Linux
dependsOn: DetectChanges
condition: and(succeededOrFailed(), ne(dependencies.DetectChanges.outputs['detect.hasProductChanges'], 'false'))
timeoutInMinutes: 90
pool:
name: NetCore-Public
demands: ImageOverride -equals build.ubuntu.2204.amd64.open
variables:
- template: /eng/pipelines/variables/test-env-vars.yml
strategy:
matrix:
Release:
_BuildConfig: Release
Debug:
_BuildConfig: Debug
steps:
- script: eng/common/cibuild.sh
-configuration $(_BuildConfig)
-prepareMachine
/p:Test=false
/p:Publish=false
/p:NonWindowsBuild=true
/p:FastAcceptanceTest=true
displayName: Build
- ${{ if eq(parameters.SkipTests, False) }}:
- template: /eng/pipelines/steps/test-non-windows.yml
parameters:
osName: Linux
- job: MacOS
dependsOn: DetectChanges
condition: and(succeededOrFailed(), ne(dependencies.DetectChanges.outputs['detect.hasProductChanges'], 'false'))
timeoutInMinutes: 90
pool:
name: Azure Pipelines
vmImage: macos-latest
os: macOS
variables:
- template: /eng/pipelines/variables/test-env-vars.yml
strategy:
matrix:
Release:
_BuildConfig: Release
Debug:
_BuildConfig: Debug
steps:
- script: eng/common/cibuild.sh
-configuration $(_BuildConfig)
-prepareMachine
/p:Test=false
/p:Publish=false
/p:NonWindowsBuild=true
/p:FastAcceptanceTest=true
displayName: Build
- ${{ if eq(parameters.SkipTests, False) }}:
- template: /eng/pipelines/steps/test-non-windows.yml
parameters:
osName: MacOS
- template: /eng/common/templates/jobs/jobs.yml
parameters:
enableMicrobuild: true
artifacts:
publish:
logs:
name: 'Logs_Build_$(Agent.JobName)_$(_BuildConfig)'
manifests: true
enableTelemetry: true
jobs:
- job: WindowsSamples
dependsOn: DetectChanges
condition: and(succeededOrFailed(), ne(dependencies.DetectChanges.outputs['detect.hasSamplesChanges'], 'false'))
timeoutInMinutes: 30
pool:
name: NetCore-Public
demands: ImageOverride -equals windows.vs2026preview.scout.amd64.open
strategy:
matrix:
Release:
_BuildConfig: Release
Debug:
_BuildConfig: Debug
steps:
- task: PowerShell@2
displayName: 'Install Windows SDK'
inputs:
targetType: filePath
filePath: './eng/install-windows-sdk.ps1'
failOnStderr: true
showWarnings: true
- task: PowerShell@2
displayName: 'Build Samples'
inputs:
targetType: filePath
filePath: './eng/build-samples.ps1'
arguments: '-Configuration $(_BuildConfig) -TreatWarningsAsErrors -BinaryLogDirectory "$(Build.SourcesDirectory)\artifacts\log\$(_BuildConfig)"'
failOnStderr: false