forked from nanoframework/nf-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
471 lines (413 loc) · 16.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
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
trigger:
branches:
include: [main, develop, "release-*" ]
paths:
exclude: [README.md, CHANGELOG.md, CODE_OF_CONDUCT.md, LICENSE.md, NuGet.Config, .github_changelog_generator, .gitignore]
tags:
include: ["v*"]
# 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
pool:
vmImage: 'windows-2019'
variables:
DOTNET_NOLOGO: true
solution: 'nanoFramework.Tools.Debugger.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- checkout: self
- script: |
git config --global user.email '[email protected]'
git config --global user.name 'nfbot'
displayName: Setup git identity
# get commit message
- powershell: |
# default to false
$update = $false
if($env:Build_Reason -eq 'PullRequest')
{
# PR build, nothing interesting in commit message
Write-Host "Build from PR"
}
else
{
# build NOT from PR
Write-Host "Build NOT from PR, commit ID: $env:Build_SourceVersion"
# get PR associate with commit
$prUrl = "https://api.github.com/repos/$env:Build_Repository_Name/commits/$env:Build_SourceVersion/pulls"
$commit = Invoke-RestMethod -Uri $prUrl -ContentType "application/json" -Headers @{"Accept"="application/vnd.github.groot-preview+json"} -Method GET
if($commit -ne $null)
{
# there is a PR, check labels
$updateDependents = $commit.labels | where {$_.Name -eq 'CI: Update Dependents'}
if($updateDependents -ne $null)
{
$update = $true
}
}
}
# set variable to foward to jobs
echo "##vso[task.setvariable variable=RUN_UPDATE_DEPENDENTS]$update"
displayName: Check PR labels
- task: DotNetCoreCLI@2
condition: or( eq( variables['StartReleaseCandidate'], true ), ne(variables['system.pullrequest.isfork'], true) )
displayName: Install NBGV tool
inputs:
command: custom
custom: tool
arguments: install -g nbgv
# only required when updating dependents
- script: nbgv cloud
condition: eq(variables['UPDATE_DEPENDENTS'], 'true')
displayName: Set Could Version
- powershell: |
# 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
git init "$env:Agent_TempDirectory\repo"
cd repo > $null
git remote add origin "$env:Build_Repository_Uri"
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
git -c http.extraheader="AUTHORIZATION: $auth" fetch --progress origin
git checkout develop
nbgv prepare-release
# 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
# push all changes to github
git -c http.extraheader="AUTHORIZATION: $auth" push --all origin
condition: eq( variables['StartReleaseCandidate'], true )
displayName: NBGV prepare release
- task: SonarCloudPrepare@1
condition: and( ne( variables['StartReleaseCandidate'], true ), ne(variables['UPDATE_DEPENDENTS'], 'true'))
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: 'sonarcloud-debugger'
organization: 'nanoframework'
scannerMode: 'MSBuild'
projectKey: 'nanoframework_nf-debugger'
- task: NuGetToolInstaller@1
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
)
displayName: 'Install specific version of NuGet'
inputs:
versionSpec: '>=5.10.0'
- task: NuGetCommand@2
condition: and( succeeded(), ne( variables['StartReleaseCandidate'], true ), ne(variables['UPDATE_DEPENDENTS'], 'true') )
displayName: NuGet restore
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
condition: and( ne( variables['StartReleaseCandidate'], true ), ne(variables['UPDATE_DEPENDENTS'], 'true'))
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
msbuildArgs: '/p:PublicRelease=true'
configuration: '$(buildConfiguration)'
- task: PowerShell@2
condition: and( ne( variables['StartReleaseCandidate'], true ), ne(variables['UPDATE_DEPENDENTS'], 'true'))
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:Build_Reason -eq 'PullRequest')
{
$MyNuGetVersion = $MyNuGetVersion -replace "preview", "alpha"
}
if ($env:System_PullRequest_SourceBranch -like 'release*')
{
$MyNuGetVersion = $MyNuGetVersion + "-rc." + $env:NBGV_VersionHeight
}
Write-Host "NuGet build number is $MyNuGetVersion"
Write-Host "$("##vso[task.setvariable variable=MY_NUGET_VERSION]")$MyNuGetVersion"
# update could build number (only possible if this is not a PR from a fork)
- task: PowerShell@2
condition: >-
and(
succeeded(),
ne(variables['system.pullrequest.isfork'], true),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Update cloud build number
inputs:
targetType: 'inline'
script: |
Write-Host "NuGet version is $("##vso[build.updatebuildnumber]")$env:MY_NUGET_VERSION"
Write-Host "Build version is $env:NBGV_AssemblyVersion"
- task: NuGetCommand@2
condition: and( succeeded(), ne( variables['StartReleaseCandidate'], true ), ne(variables['UPDATE_DEPENDENTS'], 'true') )
displayName: Pack .NET NuGet package
inputs:
command: 'custom'
arguments: 'pack nanoFramework.Tools.DebugLibrary.Net\nanoFramework.Tools.DebugLibrary.Net.nuspec -Version $(MY_NUGET_VERSION) -properties commit="$(Build.SourceVersion)"'
# arguments: 'pack nanoFramework.Tools.DebugLibrary.Net\nanoFramework.Tools.DebugLibrary.Net.nuspec -Symbols -SymbolPackageFormat snupkg -Version $(MY_NUGET_VERSION) -properties commit="$(Build.SourceVersion)"'
# we don't have tests (yet)
# - task: VSTest@2
# inputs:
# platform: '$(buildPlatform)'
# configuration: '$(buildConfiguration)'
- task: SonarCloudAnalyze@1
condition: and( succeeded(), ne( variables['StartReleaseCandidate'], true ), ne(variables['UPDATE_DEPENDENTS'], 'true') )
displayName: 'Run Code Analysis'
- task: SonarCloudPublish@1
condition: and( succeeded(), ne( variables['StartReleaseCandidate'], true ), ne(variables['UPDATE_DEPENDENTS'], 'true') )
inputs:
pollingTimeoutSec: '300'
- task: UseRubyVersion@0
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Setup Ruby
inputs:
versionSpec: '= 2.7'
addToPath: true
# generate change log
- powershell: |
gem install github_changelog_generator --quiet --no-document
# need to call it passing both cache options with full path otherwise it won't work
github_changelog_generator --token $(GitHubToken) --cache-log $env:AGENT_TEMPDIRECTORY\github-changelog-logger.log --cache-file $env:AGENT_TEMPDIRECTORY\github-changelog-http-cache
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
not(startsWith(variables['Build.SourceBranchName'], 'main')),
not(contains(variables['Build.SourceBranchName'], 'update-dependencies')),
ne(variables['StartReleaseCandidate'], true ),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Generate change log
# generate change log including future version
- powershell: |
gem install github_changelog_generator --quiet --no-document
# need to call it passing both cache options with full path otherwise it won't work
github_changelog_generator --token $(GitHubToken) --cache-log $env:AGENT_TEMPDIRECTORY\github-changelog-logger.log --cache-file $env:AGENT_TEMPDIRECTORY\github-changelog-http-cache --future-release v$env:MY_NUGET_VERSION
condition: >-
and(
succeeded(),
and(
eq(variables['System.PullRequest.PullRequestId'], ''),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
startsWith(variables['Build.SourceBranchName'], 'main'),
not(contains(variables['Build.SourceBranchName'], 'update-dependencies'))
),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Generate change log
# copy change log to artifacts directory
- task: CopyFiles@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Copy Changelog
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
Contents: 'CHANGELOG.md'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
# push new changelog to GitHub repo
- task: PowerShell@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
not(contains(variables['Build.SourceBranchName'], 'update-dependencies')),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Push changelog to GitHub
inputs:
targetType: 'inline'
script: |
git add CHANGELOG.md
git commit -m "Update CHANGELOG for v$(NBGV_Version)" -m"***NO_CI***"
git config user.email '[email protected]'
git config user.name 'nfbot'
# 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)"))))"
git -c http.extraheader="AUTHORIZATION: $auth" push origin "HEAD:$(Build.SourceBranchName)"
- task: CopyFiles@1
condition: and( succeeded(), ne( variables['StartReleaseCandidate'], true ), ne(variables['UPDATE_DEPENDENTS'], 'true') )
displayName: Collecting deployable artifacts
inputs:
sourceFolder: $(Build.SourcesDirectory)
Contents: |
**\nanoFramework.Tools.Debugger.Net.$(MY_NUGET_VERSION).nupkg
**\nanoFramework.Tools.Debugger.Net.$(MY_NUGET_VERSION).snupkg
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: DotNetCoreCLI@2
displayName: Install SignTool tool
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
inputs:
command: custom
custom: tool
arguments: install --tool-path . SignClient
- pwsh: |
.\SignClient "Sign" `
--baseDirectory "$(Build.ArtifactStagingDirectory)" `
--input "**/*.nupkg" `
--config "$(Build.Repository.LocalPath)\config\SignClient.json" `
--filelist "$(Build.Repository.LocalPath)\config\filelist.txt" `
--user "$(SignClientUser)" `
--secret '$(SignClientSecret)' `
--name ".NET nanoFramework Debugger" `
--description ".NET nanoFramework Debugger" `
--descriptionUrl "https://github.com/$env:Build_Repository_Name"
displayName: Sign packages
continueOnError: true
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['UPDATE_DEPENDENTS'], 'false')
)
# publish artifacts (only possible if this is not a PR originated on a fork)
- task: PublishBuildArtifacts@1
condition: >-
and(
succeeded(),
ne(variables['system.pullrequest.isfork'], true),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Publish deployables artifacts
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: deployables
ArtifactType: Container
# push NuGet packages to Azure Artifacts feed (always happens except on PR builds)
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Push NuGet packages to Azure Artifacts
inputs:
command: push
nuGetFeedType: external
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
publishFeedCredentials: 'AzureArtifacts-debugger'
allowPackageConflicts: true
# push NuGet class lib package to NuGet (always happens except on PR builds)
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
continueOnError: true
displayName: Push NuGet packages to NuGet
inputs:
command: push
nuGetFeedType: external
allowPackageConflicts: true
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
publishFeedCredentials: 'NuGet-debugger'
# update dependencies
- task: PowerShell@2
condition: >-
and(
or(
eq(variables['UPDATE_DEPENDENTS'], 'true'),
eq(variables['RUN_UPDATE_DEPENDENTS'], 'true')
),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: Update dependent tools
inputs:
targetType: filePath
filePath: azure-pipelines/update-dependencies.ps1
env:
MY_GITHUB_TOKEN: $(GitHubToken)
# create or update GitHub release
- task: GithubRelease@1
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Create/Update GitHub PREVIEW release
inputs:
gitHubConnection: 'github.com_nano-$(System.TeamProject)'
tagSource: userSpecifiedTag
tag: v$(MY_NUGET_VERSION)
title: 'nanoFramework Debugger Library v$(MY_NUGET_VERSION)'
releaseNotesSource: inline
releaseNotesInline: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).<br><br><h4>Install from NuGet</h4><br>The following NuGet packages are available for download from this release:<br>:package: [.NET](https://www.nuget.org/packages/nanoFramework.Tools.Debugger.Net/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION) v$(MY_NUGET_VERSION)'
assets: '$(Build.ArtifactStagingDirectory)/*.nupkg'
assetUploadMode: replace
isPreRelease: true
addChangeLog: false
# create or update GitHub release ON tags from release or main branches
- task: GithubRelease@1
condition: >-
and(
succeeded(),
startsWith(variables['Build.SourceBranch'], 'refs/tags/v'),
not(contains(variables['Build.SourceBranch'], 'preview')),
ne(variables['StartReleaseCandidate'], true),
ne(variables['UPDATE_DEPENDENTS'], 'true')
)
displayName: Create/Update GitHub stable release
inputs:
gitHubConnection: 'github.com_nano-$(System.TeamProject)'
tagSource: userSpecifiedTag
tag: v$(MY_NUGET_VERSION)
title: 'nanoFramework Debugger Library v$(MY_NUGET_VERSION)'
releaseNotesSource: inline
releaseNotesInline: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).<br><br><h4>Install from NuGet</h4><br>The following NuGet packages are available for download from this release:<br>:package: [.NET](https://www.nuget.org/packages/nanoFramework.Tools.Debugger.Net/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION) v$(MY_NUGET_VERSION)'
assets: '$(Build.ArtifactStagingDirectory)/*.nupkg'
assetUploadMode: replace
isPreRelease: false
addChangeLog: false
# step from template @ nf-tools repo
# report error
- template: azure-pipelines-templates/discord-webhook-task.yml@templates
parameters:
status: 'failure'
webhookUrl: '$(DiscordWebhook)'
message: ''