-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
azure-pipelines.yml
431 lines (362 loc) · 12.5 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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
trigger:
branches:
include: [main, develop, "release-*" ]
paths:
exclude:
- azure-pipelines.yml
- README.md
- README.zh-cn.md
- CHANGELOG.md
- CODE_OF_CONDUCT.md
- LICENSE.md
- .gitignore
tags:
include:
- refs/tags/v*
# PR always trigger build
pr:
autoCancel: true
jobs:
##############################
- job: Check_Build_Options
pool:
vmImage: 'windows-latest'
steps:
- checkout: self
# check what changed
- powershell: |
git config --global user.email "nfbot"
git config --global user.name "[email protected]"
$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$(GitHubToken)")))"
if($env:System_PullRequest_PullRequestId -ne $null)
{
# get files changed in PR, if this is a PR
$commit = Invoke-RestMethod -Uri "https://api.github.com/repos/$env:Build_Repository_Name/pulls/$env:System_PullRequest_PullRequestNumber/files" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
# filter removed files
$files = $commit.where{$_.status -ne 'removed'}
}
else
{
# get files changed in the commit, if this is NOT a PR
$commit = Invoke-RestMethod -Uri "https://api.github.com/repos/$env:Build_Repository_Name/commits/$(Build.SourceVersion)" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
# filter removed files
$files = $commit.files.where{$_.status -ne 'removed'}
}
# get file names only
$files = $files | % {$_.filename}
Write-host "Files changed:"
$files | % { Write-host $_ }
Write-host ""
# set default values
echo "##vso[task.setvariable variable=BUILD_NANOVC;isOutput=true]false"
echo "##vso[task.setvariable variable=BUILD_NANODU;isOutput=true]false"
echo "##vso[task.setvariable variable=BUILD_PROFILER;isOutput=true]false"
if( ($files.where{$_.Contains('tools/VersionCop')}).Count -gt 0)
{
# files at nano VersionCop folder
echo "##vso[task.setvariable variable=BUILD_NANOVC;isOutput=true]true"
Write-host "Building VersionCop"
}
if( ($files.where{$_.Contains('tools/DependencyUpdater')}).Count -gt 0)
{
# files at nano DependencyUpdater folder
echo "##vso[task.setvariable variable=BUILD_NANODU;isOutput=true]true"
Write-host "Building DependencyUpdater"
}
if( ($files.where{$_.Contains('tools/Profiler')}).Count -gt 0)
{
# files at nano Profiler folder
echo "##vso[task.setvariable variable=BUILD_PROFILER;isOutput=true]true"
Write-host "Building Profiler"
}
name: TargetsToBuild
displayName: Get targets to build
##############
- job: Build_VersionCop
condition: >-
or(
eq(dependencies.Check_Build_Options.outputs['TargetsToBuild.BUILD_NANOVC'], true),
eq(variables['BUILD_VERSIONCOP'], 'true')
)
dependsOn:
Check_Build_Options
pool:
vmImage: 'windows-latest'
variables:
- group: sign-client-credentials
- name: DOTNET_NOLOGO
value: true
steps:
- checkout: self
persistCredentials: true
- template: azure-pipelines-templates/install-nuget.yml
- task: NuGetCommand@2
displayName: Restore NuGet packages
condition: succeeded()
retryCountOnTaskFailure: 5
inputs:
restoreSolution: $(System.DefaultWorkingDirectory)/tools/VersionCop/nanoFramework.VersionCop.sln
feedsToUse: select
includeNuGetOrg: true
- script: dotnet build nanoFramework.VersionCop.sln -c Release -p:Platform="Any CPU" -p:PublicRelease=true --no-restore /t:build,pack
displayName: Build NuGet package
condition: succeeded()
workingDirectory: '$(System.DefaultWorkingDirectory)/tools/VersionCop'
- task: CopyFiles@1
condition: succeeded()
displayName: Collecting deployable artifacts
inputs:
sourceFolder: $(Agent.BuildDirectory)
Contents: |
**\nanovc*.nupkg
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: PowerShell@2
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: Check deployable artifacts
inputs:
targetType: 'inline'
script: |
$artifacts = (Get-ChildItem -Path "$env:Build_ArtifactStagingDirectory" -Recurse)
if ($artifacts.Count -eq 0)
{
Write-Error "No deployable artifacts found!"
Exit 1
}
- task: DotNetCoreCLI@2
displayName: Install Sign Client CLI
condition: succeeded()
inputs:
command: custom
custom: tool
arguments: install --tool-path . sign --version 0.9.1-beta.24529.1
- pwsh: |
.\sign code azure-key-vault `
"**/*.nupkg" `
--base-directory "$(Build.ArtifactStagingDirectory)" `
--description ".NET nanoFramework VersionCop" `
--description-url "https://github.com/$env:Build_Repository_Name" `
--azure-key-vault-tenant-id "$(SignTenantId)" `
--azure-key-vault-client-id "$(SignClientId)" `
--azure-key-vault-client-secret "$(SignClientSecret)" `
--azure-key-vault-certificate "$(SignKeyVaultCertificate)" `
--azure-key-vault-url "$(SignKeyVaultUrl)" `
--timestamp-url http://timestamp.digicert.com
displayName: Sign packages
continueOnError: true
condition: succeeded()
# publish artifacts (only possible if this is not a PR originated on a fork)
- task: PublishPipelineArtifact@1
condition: succeeded()
displayName: Publish deployables artifacts
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: deployables
artifactType: pipeline
# push NuGet packages to NuGet
- task: NuGetCommand@2
displayName: Push NuGet packages to NuGet
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], '')
)
continueOnError: true
inputs:
command: push
nuGetFeedType: external
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
allowPackageConflicts: true
includeSymbols: true
publishFeedCredentials: 'NuGet-$(System.TeamProject)'
##############
- job: Build_DependencyUpdater
condition: >-
or(
eq(dependencies.Check_Build_Options.outputs['TargetsToBuild.BUILD_NANODU'], true),
eq(variables['BUILD_DEPENDENCYUPDATER'], 'true')
)
dependsOn:
Check_Build_Options
pool:
vmImage: 'windows-latest'
variables:
- group: sign-client-credentials
- name: DOTNET_NOLOGO
value: true
steps:
- checkout: self
persistCredentials: true
- template: azure-pipelines-templates/install-nuget.yml
- task: NuGetCommand@2
displayName: Restore NuGet packages
condition: succeeded()
retryCountOnTaskFailure: 5
inputs:
restoreSolution: $(System.DefaultWorkingDirectory)/tools/DependencyUpdater/DependencyUpdater.sln
feedsToUse: select
includeNuGetOrg: true
- script: dotnet build DependencyUpdater.sln -c Release -p:Platform="Any CPU" -p:PublicRelease=true --no-restore /t:build,pack
displayName: Build NuGet package
condition: succeeded()
workingDirectory: '$(System.DefaultWorkingDirectory)/tools/DependencyUpdater'
- task: DotNetCoreCLI@2
condition: succeeded()
displayName: 'Running Unit Tests'
inputs:
command: 'test'
projects: |
**/*Tests.csproj
!**/obj/**
!**/bin/**/ref/**
arguments: '--configuration Release --collect "XPlat Code coverage"'
testRunTitle: 'Unit Tests'
# First install the tool on the machine, then run it
- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Agent.WorkFolder)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage "-reporttypes:HtmlInline_AzurePipelines;Cobertura"
displayName: 'Create code coverage report'
condition: always()
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage results'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml'
condition: always()
- task: CopyFiles@1
condition: succeeded()
displayName: Collecting deployable artifacts
inputs:
sourceFolder: $(Agent.BuildDirectory)
Contents: |
**\nanodu*.nupkg
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: PowerShell@2
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: Check deployable artifacts
inputs:
targetType: 'inline'
script: |
$artifacts = (Get-ChildItem -Path "$env:Build_ArtifactStagingDirectory" -Recurse)
if ($artifacts.Count -eq 0)
{
Write-Error "No deployable artifacts found!"
Exit 1
}
- task: DotNetCoreCLI@2
displayName: Install Sign Client CLI
condition: succeeded()
inputs:
command: custom
custom: tool
arguments: install --tool-path . sign --version 0.9.1-beta.24529.1
- pwsh: |
.\sign code azure-key-vault `
"**/*.nupkg" `
--base-directory "$(Build.ArtifactStagingDirectory)" `
--description ".NET nanoFramework DependencyUpdater" `
--description-url "https://github.com/$env:Build_Repository_Name" `
--azure-key-vault-tenant-id "$(SignTenantId)" `
--azure-key-vault-client-id "$(SignClientId)" `
--azure-key-vault-client-secret "$(SignClientSecret)" `
--azure-key-vault-certificate "$(SignKeyVaultCertificate)" `
--azure-key-vault-url "$(SignKeyVaultUrl)" `
--timestamp-url http://timestamp.digicert.com
displayName: Sign packages
continueOnError: true
condition: succeeded()
# publish artifacts (only possible if this is not a PR originated on a fork)
- task: PublishPipelineArtifact@1
condition: succeeded()
displayName: Publish deployables artifacts
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: deployables
artifactType: pipeline
# push NuGet packages to NuGet
- task: NuGetCommand@2
displayName: Push NuGet packages to NuGet
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], '')
)
continueOnError: true
inputs:
command: push
nuGetFeedType: external
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
includeSymbols: true
publishFeedCredentials: 'NuGet-$(System.TeamProject)'
##############
- job: Build_NanoProfiler
condition: >-
or(
eq(dependencies.Check_Build_Options.outputs['TargetsToBuild.BUILD_PROFILER'], true),
eq(variables['BUILD_NANOPROFILER'], 'true')
)
dependsOn:
Check_Build_Options
pool:
vmImage: 'windows-latest'
variables:
- group: sign-client-credentials
- name: DOTNET_NOLOGO
value: true
steps:
- checkout: self
persistCredentials: true
- template: azure-pipelines-templates/install-nuget.yml
- task: NuGetCommand@2
displayName: Restore NuGet packages
condition: succeeded()
retryCountOnTaskFailure: 5
inputs:
restoreSolution: $(System.DefaultWorkingDirectory)/tools/Profiler/NanoProfiler/NanoProfiler.sln
feedsToUse: select
includeNuGetOrg: true
- task: VSBuild@1
condition: succeeded()
displayName: Build nanoProfiler
inputs:
solution: '$(System.DefaultWorkingDirectory)/tools/Profiler/NanoProfiler/NanoProfiler.sln'
platform: 'Any CPU'
msbuildArgs: '/p:PublicRelease=true'
configuration: 'Release'
maximumCpuCount: true
##################################
# report build failure to Discord
- job: Report_Build_Failure
dependsOn:
- Check_Build_Options
- Build_VersionCop
- Build_DependencyUpdater
- Build_NanoProfiler
condition: >-
or(
failed('Check_Build_Options'),
failed('Build_VersionCop'),
failed('Build_DependencyUpdater'),
failed('Build_NanoProfiler')
)
pool:
vmImage: 'windows-latest'
steps:
- checkout: self
# step from template @ nf-tools repo
- template: azure-pipelines-templates/discord-webhook.yml
parameters:
status: 'failure'
webhookUrl: '$(DiscordWebhook)'
message: ''