-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
azure-pipelines.yml
245 lines (212 loc) · 9.81 KB
/
azure-pipelines.yml
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
variables:
DOTNET_CLI_TELEMETRY_OPTOUT: true
CurrentSemanticVersionBase: '99.0.0'
PreviewNumber: $[counter(variables['CurrentSemanticVersionBase'], 1001)]
NET_VERSION: '9.0.100'
CurrentSemanticVersion: '$(CurrentSemanticVersionBase)-preview$(PreviewNumber)'
NugetPackageVersion: '$(CurrentSemanticVersion)'
PathToSolution: 'AsyncAwaitBestPractices.sln'
PathToSampleAppCsproj: 'sample/HackerNews.csproj'
PathToUnitTestsCsproj: 'src/AsyncAwaitBestPractices.UnitTests/AsyncAwaitBestPractices.UnitTests.csproj'
PathToAsyncAwaitBestPracticesCsproj: 'src/AsyncAwaitBestPractices/AsyncAwaitBestPractices.csproj'
PathToAsyncAwaitBestPracticesMVVMCsproj: 'src/AsyncAwaitBestPractices.MVVM/AsyncAwaitBestPractices.MVVM.csproj'
Xcode_Version: '16'
trigger:
branches:
include:
- main
tags:
include:
- '*'
pr:
autoCancel: 'true'
branches:
include:
- main
jobs:
- job: build_sample
displayName: Build .NET MAUI Sample App
strategy:
matrix:
'Windows':
image: 'windows-latest'
'macOS':
image: 'macos-14'
pool:
vmImage: $(image)
steps:
- task: CmdLine@2
displayName: 'Set Xcode v$(Xcode_Version)'
condition: eq(variables['Agent.OS'], 'Darwin') # Only run this step on macOS
inputs:
script: |
echo Availalbe Xcode Versions:
ls -al /Applications | grep Xcode
echo '##vso[task.setvariable variable=MD_APPLE_SDK_ROOT;]'/Applications/Xcode_$(Xcode_Version).app;sudo xcode-select --switch /Applications/Xcode_$(Xcode_Version).app/Contents/Developer
- task: InstallAppleCertificate@2
displayName: "Set Xcode Signing Certificate"
condition: eq(variables['Agent.OS'], 'Darwin') # Only run this step on macOS
inputs:
certSecureFile: 'certificate.p12'
certPwd: '$(AppleCertificatePassword)'
- task: InstallAppleProvisioningProfile@1
displayName: "Set Xcode Provisioning Profile"
condition: eq(variables['Agent.OS'], 'Darwin') # Only run this step on macOS
inputs:
provisioningProfileLocation: 'secureFiles'
provProfileSecureFile: 'Development_Wildcard.mobileprovision'
- task: UseDotNet@2
displayName: 'Use .Net SDK v$(NET_VERSION)'
inputs:
version: '$(NET_VERSION)'
packageType: 'sdk'
includePreviewVersions: false
- powershell: dotnet workload install maui --skip-sign-check --source https://api.nuget.org/v3/index.json
displayName: Install Latest .NET MAUI Workload
- task: NuGetToolInstaller@1
displayName: 'Use NuGet'
inputs:
checkLatest: true
- task: CmdLine@2
displayName: 'Build Sample App'
inputs:
script: 'dotnet build $(PathToSampleAppCsproj)'
- task: CopyFiles@2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**\bin\$(BuildConfiguration)\**'
TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
- job: build_test_library
displayName: Build + Test Library
pool:
vmImage: 'windows-latest'
steps:
# if this is a Release build, update the version number
- powershell: |
$buildSourceBranch = "$(Build.SourceBranch)"
$tagVersion = $buildSourceBranch.Substring($buildSourceBranch.LastIndexOf("/") + 1)
Write-Host("Branch = $buildSourceBranch, Version = $tagVersion");
Write-Host ("##vso[task.setvariable variable=NugetPackageVersion;]$tagVersion")
displayName: Set NuGet Version to Tag Number
condition: and(startsWith(variables['Build.SourceBranch'], 'refs/tags/'), not(endsWith(variables['Build.SourceBranch'], '-mediaelement'))) # Only run this step when a Tag has triggered the CI Pipeline
# if this is a PR build, then update the version number
- powershell: |
$prNumber = $env:System_PullRequest_PullRequestNumber
$commitId = "$($env:System_PullRequest_SourceCommitId)".Substring(0, 7)
$fullVersionString = "$(CurrentSemanticVersionBase)-build-$prNumber.$(Build.BuildId)+$commitId"
Write-Host("GitHub PR = $prNumber, Commit = $commitId");
Write-Host ("##vso[task.setvariable variable=NugetPackageVersion;]$fullVersionString")
Write-Host ("##vso[task.setvariable variable=NugetPackageVersionMediaElement;]$fullVersionString")
Write-Host "##vso[build.updatebuildnumber]$fullVersionString"
displayName: Set NuGet Version to PR Version
condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['build.reason'], 'PullRequest')) # Only run this step on Windows when a Pull Request has triggered the CI Pipeline
- task: UseDotNet@2
displayName: 'Use .Net Core SDK 2.1.x'
inputs:
version: ' 2.1.x'
packageType: 'sdk'
- task: UseDotNet@2
displayName: 'Use .Net Core SDK 3.0.x'
inputs:
version: ' 3.0.x'
packageType: 'sdk'
- task: UseDotNet@2
displayName: 'Use .Net SDK 8.0.x'
inputs:
version: '8.0.x'
packageType: 'sdk'
- task: UseDotNet@2
displayName: 'Use .Net SDK 9.0.x'
inputs:
version: '$(NET_VERSION)'
packageType: 'sdk'
- task: NuGetToolInstaller@1
displayName: 'Use NuGet'
inputs:
checkLatest: true
- task: CmdLine@2
displayName: 'Run UnitTests'
inputs:
script: 'dotnet test $(PathToUnitTestsCsproj) -c Release --settings ".runsettings" --collect "code coverage" --logger trx --results-directory $(Agent.TempDirectory)'
- task: PublishTestResults@2
condition: eq(variables['Agent.OS'], 'Windows_NT') # Only run this step on Windows
displayName: 'Publish Test Results'
inputs:
testResultsFormat: VSTest
testResultsFiles: '**/*.trx'
searchFolder: $(Agent.TempDirectory)
- task: PublishCodeCoverageResults@2
condition: eq(variables['Agent.OS'], 'Windows_NT') # Only run this step on Windows
displayName: 'Publish Code Coverage Results'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
failIfCoverageEmpty: true
- task: CmdLine@2
displayName: 'Pack AsyncAwaitBestPractices NuGet'
inputs:
script: 'dotnet pack $(PathToAsyncAwaitBestPracticesCsproj) -c Release -p:PackageVersion=$(NugetPackageVersion)'
- task: CmdLine@2
displayName: 'Pack AsyncAwaitBestPractices.MVVM NuGet'
inputs:
script: 'dotnet pack $(PathToAsyncAwaitBestPracticesMVVMCsproj) -c Release -p:PackageVersion=$(NugetPackageVersion)'
# check vulnerabilities
- powershell: |
dotnet list $(PathToAsyncAwaitBestPracticesCsproj) package --vulnerable --include-transitive | findstr /S /c:"has the following vulnerable packages";
if ($LastExitCode -ne 1)
{
dotnet list $(PathToAsyncAwaitBestPracticesCsproj) package --vulnerable --include-transitive;
exit 1;
}
exit 0;
displayName: 'Check AsyncAwaitBestPractices Dependencies Vulnerabilities'
condition: eq(variables['Agent.OS'], 'Windows_NT') # Only run this step on Windows
- powershell: |
dotnet list $(PathToAsyncAwaitBestPracticesMVVMCsproj) package --vulnerable --include-transitive | findstr /S /c:"has the following vulnerable packages";
if ($LastExitCode -ne 1)
{
dotnet list $(PathToAsyncAwaitBestPracticesMVVMCsproj) package --vulnerable --include-transitive;
exit 1;
}
exit 0;
displayName: 'Check AsyncAwaitBestPractices.MVVM Dependencies Vulnerabilities'
condition: eq(variables['Agent.OS'], 'Windows_NT') # Only run this step on Windows
- powershell: |
dotnet list $(PathToSampleAppCsproj) package --vulnerable --include-transitive | findstr /S /c:"has the following vulnerable packages";
if ($LastExitCode -ne 1)
{
dotnet list $(PathToSampleAppCsproj) package --vulnerable --include-transitive;
exit 1;
}
exit 0;
displayName: 'Check Sample App Dependencies Vulnerabilities'
condition: eq(variables['Agent.OS'], 'Windows_NT') # Only run this step on Windows
# Copy all NuGet packages
- task: PowerShell@2
condition: and(eq(variables['Agent.OS'], 'Windows_NT'), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/'))) # Only run this step on Windows and when it's not a Release build
displayName: 'Copy NuGet Packages to Staging Directory'
inputs:
targetType: 'inline'
script: |
$source = ".\src"
$filter = "nupkg"
Get-ChildItem -Path $source -Recurse | Where-Object { $_.Extension -match $filter } | Copy-Item -Destination "$(Build.ArtifactStagingDirectory)"
pwsh: true
- task: CopyFiles@2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**\bin\$(BuildConfiguration)\**'
TargetFolder: '$(build.artifactstagingdirectory)'
# Publish build artifacts
- task: PublishBuildArtifacts@1
condition: eq(variables['Agent.OS'], 'Windows_NT') # Only run this step on Windows
displayName: 'Publish NuGet Packages'
inputs:
ArtifactName: nuget
PathtoPublish: '$(Build.ArtifactStagingDirectory)'