-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathazure-pipelines.yml
511 lines (450 loc) · 15.4 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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
trigger:
branches:
include:
- main
- develop
- release-*
paths:
exclude:
- .github_changelog_generator
- .gitignore
- LICENSE.md
- README.md
- README.zh-cn.md
- NuGet.Config
- update-esptool.ps1
- update-jlink.ps1
- assets/*
- config/*
- .github/*
- Samples/*
# PR always trigger build
pr:
autoCancel: true
# add nf-tools repo to resources (for Azure Pipelines templates)
resources:
repositories:
- repository: templates
type: github
name: nanoframework/nf-tools
endpoint: nanoframework
jobs:
##############################
- job: Check_Build_Options
pool:
vmImage: 'windows-latest'
steps:
- checkout: self
# get commit message
- powershell: |
# default to false
$update = $false
if($env:System_PullRequest_PullRequestId -ne $null)
{
# PR build, nothing interesting in commit message
Write-Host "Build from PR"
}
else
{
if($env:StartReleaseCandidate -like "true")
{
# this is a release prep so NO build
echo "##vso[task.setvariable variable=SKIP_BUILD;isOutput=true]true"
Write-Host "Release preparation, skipping build."
}
else
{
# build NOT from PR
Write-Host "Build NOT from PR, commit ID: $env:Build_SourceVersion"
}
}
name: BuildOptions
displayName: Evaluate build options
- task: PowerShell@2
condition: eq( variables['StartReleaseCandidate'], true)
displayName: NBGV prepare release
inputs:
targetType: 'inline'
script: |
# compute authorization header in format "AUTHORIZATION: basic 'encoded token'"
# 'encoded token' is the Base64 of the string "nfbot:personal-token"
$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nfbot:$(GitHubToken)"))))"
cd "$env:Agent_TempDirectory" > $null
Write-Host "Cloning from: $env:BUILD_REPOSITORY_URI"
git clone $env:BUILD_REPOSITORY_URI repo
cd repo > $null
git config --global gc.auto 0
git config --global user.name nfbot
git config --global user.email [email protected]
git config --global core.autocrlf true
Write-Host "Checkout main branch..."
git checkout --quiet main > $null
# prepare release and capture output
Write-Host "Prepare release with NBGV..."
$release = nbgv prepare-release
Write-Host "Prepare commit..."
# get commit message for the merge
$commitMessage = git log -1 --pretty=%B
# amend commit message to skip build
git commit --amend -m "$commitMessage" -m "***NO_CI***" > $null
Write-Host "Pushing changes to GitHub..."
# push all changes to github
git -c http.extraheader="AUTHORIZATION: $auth" push --quiet --all origin
# get release branch name
$branch = $release.Split(' ')[0]
Write-Host "Prepare PR..."
# start PR for release
$prRequestBody = @{title="Release $branch";body="";head="$branch";base="main"} | ConvertTo-Json
$githubApiEndpoint = "https://api.github.com/repos/$env:BUILD_REPOSITORY_NAME/pulls"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$headers = @{}
$headers.Add("Authorization","$auth")
$headers.Add("Accept","application/vnd.github.symmetra-preview+json")
try
{
$result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $githubApiEndpoint -Header $headers -ContentType "application/json" -Body $prRequestBody
'Started PR for new release...' | Write-Host -NoNewline
'OK' | Write-Host -ForegroundColor Green
}
catch
{
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
"Error starting PR: $responseBody" | Write-Host -ForegroundColor Red
}
workingDirectory: $(Agent.TempDirectory)
ignoreLASTEXITCODE: true
###########################################################
# build tool
- job: Build_tool
condition: >-
and(
succeeded(),
ne(dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true)
)
dependsOn:
- Check_Build_Options
pool:
vmImage: 'windows-latest'
variables:
- group: sign-client-credentials
- name: DOTNET_NOLOGO
value: true
- name: buildPlatform
value: 'x64'
- name: buildConfiguration
value: 'Release'
- name: solution
value: 'nanoFirmwareFlasher.sln'
steps:
# need this here in order to persist GitHub credentials
- checkout: self
persistCredentials: true
- script: |
git config --global user.email "[email protected]"
git config --global user.name "nfbot"
displayName: Setup git identity
# only required when updating dependents
- script: nbgv cloud -a -c
condition: >-
eq(variables['UPDATE_DEPENDENTS'], 'true')
displayName: Set Cloud Version
- task: Cache@2
displayName: Cache NuGet packages
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
inputs:
key: 'nuget | "$(Agent.OS)" | **/packages.lock.json, !bin/**'
restoreKeys: |
nuget | "$(Agent.OS)"
nuget
path: $(UserProfile)/.nuget/packages
- task: DotNetCoreCLI@2
displayName: Restore NuGet packages
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
inputs:
command: restore
restoreArguments: '--locked-mode'
verbosityRestore: minimal
projects: nanoFirmwareFlasher.sln
feedsToUse: config
nugetConfigPath: NuGet.Config
- script: dotnet build -c $(BuildConfiguration) /p:PublicRelease=true --no-restore /t:build,pack
displayName: Build NuGet package
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
- task: VisualStudioTestPlatformInstaller@1
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: 'Visual Studio Test Platform Installer'
inputs:
versionSelector: latestStable
- task: VSTest@2
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: 'Running Unit Tests'
continueOnError: false
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*Tests*.dll
!**\obj\**
!**\TestAdapter\**
searchFolder: '$(System.DefaultWorkingDirectory)'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
diagnosticsEnabled: true
vsTestVersion: toolsInstaller
codeCoverageEnabled: true
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false'),
ne(variables['System.PullRequest.PullRequestId'], '')
)
displayName: Restore NuGet packages for Samples
inputs:
restoreSolution: '$(Build.SourcesDirectory)/Samples/Samples.sln'
feedsToUse: config
nugetConfigPath: '$(Build.SourcesDirectory)/Samples/nuget.config'
- task: VSBuild@1
displayName: Build Samples
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false'),
ne(variables['System.PullRequest.PullRequestId'], '')
)
inputs:
solution: '$(Build.SourcesDirectory)/Samples/Samples.sln'
platform: 'Any CPU'
configuration: '$(buildConfiguration)'
- task: PowerShell@2
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Get NuGet build number
inputs:
targetType: 'inline'
script: |
$MyNuGetVersion = $env:NBGV_NuGetPackageVersion -replace "\-g$env:NBGV_GitCommitIdShort", ""
# replace preview with alpha if this is a PR build
if($env:System_PullRequest_PullRequestId -ne $null)
{
$MyNuGetVersion = $MyNuGetVersion -replace "preview", "alpha"
}
Write-Host "NuGet build number is $MyNuGetVersion"
Write-Host "$("##vso[task.setvariable variable=MY_NUGET_VERSION]")$MyNuGetVersion"
# update cloud build number (only possible if this is not a PR from a fork)
- task: PowerShell@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Update cloud build number
inputs:
targetType: 'inline'
script: Write-Host "$("##vso[build.updatebuildnumber]")$env:NBGV_NuGetPackageVersion"
- powershell: |
# get subject and commit message for commit
$commitMessage = git log --format='%B' -1
# need to flatten message by removing new lines
$commitMessage = $commitMessage -replace "`r`n", " "
if($commitMessage -like "***PUBLISH_RELEASE***")
{
# set variable
Write-Host "$("##vso[task.setvariable variable=RELEASE_DRAFT]")false"
Write-Host "Release draft: FALSE"
}
else
{
# set variable
Write-Host "$("##vso[task.setvariable variable=RELEASE_DRAFT]")true"
Write-Host "Release draft: TRUE"
}
displayName: set release draft var
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
# Replace the intrument key
- powershell: |
. ./common.ps1
$fileToReplace = "$(System.DefaultWorkingDirectory)/nanoFirmwareFlasher.Tool\appsettings.json"
$sourceString = "INSTRUMENT_KEY"
$instrumentKey = "$(InstrumentKey)"
Find-ReplaceInFile -filePath $fileToReplace -sourceString $sourceString -targetString $instrumentKey
displayName: Replace intrument key
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
- task: CopyFiles@1
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Collecting deployable artifacts
inputs:
sourceFolder: $(Agent.BuildDirectory)
Contents: |
**\*.nupkg
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: DotNetCoreCLI@2
displayName: Install Sign Client CLI
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
inputs:
command: custom
custom: tool
arguments: install --tool-path . sign --version 0.9.1-beta.23530.1
- pwsh: |
.\sign code azure-key-vault `
"**/*.nupkg" `
--base-directory "$(Build.ArtifactStagingDirectory)" `
--file-list "$(Build.Repository.LocalPath)\config\filelist.txt" `
--description ".NET nanoFramework firmware flasher" `
--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: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
# publish artifacts
- task: PublishBuildArtifacts@1
condition: >-
and(
succeeded(),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Publish deployables artifacts
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: deployables
ArtifactType: Container
# push NuGet class lib package to NuGet (happens on all builds except PRs)
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Push nanoff dotnet tool to NuGet
continueOnError: true
inputs:
command: push
feedsToUse: select
nuGetFeedType: external
allowPackageConflicts: true
packagesToPush: '$(Build.ArtifactStagingDirectory)\nanoff.$(NBGV_NuGetPackageVersion).nupkg'
publishFeedCredentials: 'NuGet-nanoFirmwareFlasher'
# push NuGet class lib package to NuGet (happens on all builds except PRs)
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Push NuGet package with library to NuGet
continueOnError: true
inputs:
command: push
feedsToUse: select
nuGetFeedType: external
allowPackageConflicts: true
packagesToPush: '$(Build.ArtifactStagingDirectory)\nanoFramework.Tools.FirmwareFlasher.$(NBGV_NuGetPackageVersion).nupkg'
publishFeedCredentials: 'NuGet-nanoFirmwareFlasher'
# create or update GitHub release
- task: GithubRelease@1
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
displayName: Create/Update GitHub stable release
inputs:
gitHubConnection: 'github.com_nano-$(System.TeamProject)'
tagSource: userSpecifiedTag
tag: v$(MY_NUGET_VERSION)
title: 'nano firmware flasher v$(MY_NUGET_VERSION)'
assets: '$(Build.ArtifactStagingDirectory)/*.nupkg'
isPreRelease: false
action: create
isDraft: false
addChangeLog: true
changeLogType: issueBased
changeLogLabels: |
[
{ "label" : "Type: bug", "displayName" : "Bugs fixed", "state" : "closed" },
{ "label" : "Type: enhancement", "displayName" : "Enhancements and new features", "state" : "closed" },
{ "label" : "Breaking-Change", "displayName" : "Breaking Changes", "state" : "closed" },
{ "label" : "Type: dependencies", "displayName" : "Dependencies updated", "state" : "closed" },
{ "label" : "Type: documentation", "displayName" : "Documentation", "state" : "closed" }
]
##################################
# report build failure to Discord
- job: Report_Build_Failure
dependsOn:
- Check_Build_Options
- Build_tool
condition: >-
or(
failed('Check_Build_Options'),
failed('Build_tool')
)
pool:
vmImage: 'windows-latest'
steps:
- checkout: self
# step from template @ nf-tools repo
- template: azure-pipelines-templates/discord-webhook.yml@templates
parameters:
status: 'failure'
webhookUrl: '$(DiscordWebhook)'
message: ''