@@ -30,17 +30,50 @@ jobs:
3030
3131 - checkout : self
3232
33- # get commint message
33+ # get commit message
3434 - powershell : |
3535
36- if($env:StartReleaseCandidate -like "true")
36+ # default to false
37+ $update = $false
38+
39+ if($env:System_PullRequest_PullRequestId -ne $null)
3740 {
38- # this is a release prep so NO build
39- echo "##vso[task.setvariable variable=SKIP_BUILD;isOutput=true]true"
40-
41- Write-Host "Release preparation, skipping build."
41+ # PR build, nothing interesting in commit message
42+ Write-Host "Build from PR"
4243 }
43-
44+ else
45+ {
46+ if($env:StartReleaseCandidate -like "true")
47+ {
48+ # this is a release prep so NO build
49+ echo "##vso[task.setvariable variable=SKIP_BUILD;isOutput=true]true"
50+
51+ Write-Host "Release preparation, skipping build."
52+ }
53+ else
54+ {
55+ # build NOT from PR
56+ Write-Host "Build NOT from PR, commit ID: $env:Build_SourceVersion"
57+
58+ # get PR associated with commit
59+ $prUrl = "https://api.github.com/repos/$env:Build_Repository_Name/commits/$env:Build_SourceVersion/pulls"
60+ $commit = Invoke-RestMethod -Uri $prUrl -ContentType "application/json" -Headers @{"Accept"="application/vnd.github.groot-preview+json"} -Method GET
61+
62+ if($commit -ne $null)
63+ {
64+ # there is a PR, check labels
65+ $updateDependents = $commit.labels | where {$_.Name -eq 'CI: Update Dependents'}
66+ if($updateDependents -ne $null)
67+ {
68+ $update = $true
69+ }
70+ }
71+ }
72+ }
73+
74+ # set variable to foward to jobs
75+ echo "##vso[task.setvariable variable=RUN_UPDATE_DEPENDENTS]$update"
76+
4477 name: BuildOptions
4578 displayName: Evaluate build options
4679
@@ -130,7 +163,7 @@ jobs:
130163# ##########################################################
131164# build tool
132165- job : Build_tool
133- condition : ne( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true )
166+ condition : ne(dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true)
134167 dependsOn :
135168 - Check_Build_Options
136169
@@ -158,12 +191,27 @@ jobs:
158191
159192 - task : UseDotNet@2
160193 displayName : Install .NET SDK
194+ condition : eq(variables['UPDATE_DEPENDENTS'], 'false')
161195 inputs :
162196 packageType : sdk
163197 version : 6.x
164198
199+ - task : DotNetCoreCLI@2
200+ displayName : Install NBGV tool
201+ condition : ne(variables['system.pullrequest.isfork'], true)
202+ inputs :
203+ command : custom
204+ custom : tool
205+ arguments : install -g nbgv
206+
207+ # only required when updating dependents
208+ - script : nbgv cloud
209+ condition : eq(variables['UPDATE_DEPENDENTS'], 'true')
210+ displayName : Set Could Version
211+
165212 - task : DotNetCoreCLI@2
166213 displayName : Restore NuGet packages
214+ condition : eq(variables['UPDATE_DEPENDENTS'], 'false')
167215 inputs :
168216 command : restore
169217 verbosityRestore : minimal
@@ -173,12 +221,18 @@ jobs:
173221
174222 - script : dotnet build -c $(BuildConfiguration) /p:PublicRelease=true --no-restore /t:build,pack
175223 displayName : Build NuGet package
224+ condition : eq(variables['UPDATE_DEPENDENTS'], 'false')
176225
177226 - script : dotnet pack --runtime win-x64 -c $(BuildConfiguration) -p:PublicRelease=true -p:PackGlobalTool=true --no-restore
178227 displayName : Build .NET Core Tool NuGet package
228+ condition : eq(variables['UPDATE_DEPENDENTS'], 'false')
179229
180230 - task : PowerShell@2
181- condition : succeeded()
231+ condition : >-
232+ and(
233+ succeeded(),
234+ eq(variables['UPDATE_DEPENDENTS'], 'false')
235+ )
182236 displayName : Get NuGet build number
183237 inputs :
184238 targetType : ' inline'
@@ -197,7 +251,12 @@ jobs:
197251
198252 # update could build number (only possible if this is not a PR from a fork)
199253 - task : PowerShell@2
200- condition : and( succeeded(), ne(variables['system.pullrequest.isfork'], true) )
254+ condition : >-
255+ and(
256+ succeeded(),
257+ ne(variables['system.pullrequest.isfork'], true),
258+ eq(variables['UPDATE_DEPENDENTS'], 'false')
259+ )
201260 displayName : Update cloud build number
202261 inputs :
203262 targetType : ' inline'
@@ -224,9 +283,14 @@ jobs:
224283 }
225284
226285 displayName: set release draft var
286+ condition: eq(variables['UPDATE_DEPENDENTS'], 'false')
227287
228288 - task : CopyFiles@1
229- condition : succeeded()
289+ condition : >-
290+ and(
291+ succeeded(),
292+ eq(variables['UPDATE_DEPENDENTS'], 'false')
293+ )
230294 displayName : Collecting deployable artifacts
231295 inputs :
232296 sourceFolder : $(Agent.BuildDirectory)
@@ -237,7 +301,12 @@ jobs:
237301
238302 - task : DotNetCoreCLI@2
239303 displayName : Install SignTool tool
240- condition : and( succeeded(), eq(variables['System.PullRequest.PullRequestId'], '') )
304+ condition : >-
305+ and(
306+ succeeded(),
307+ eq(variables['System.PullRequest.PullRequestId'], ''),
308+ eq(variables['UPDATE_DEPENDENTS'], 'false')
309+ )
241310 inputs :
242311 command : custom
243312 custom : tool
@@ -256,11 +325,21 @@ jobs:
256325 --descriptionUrl "https://github.com/$env:Build_Repository_Name"
257326 displayName: Sign packages
258327 continueOnError: true
259- condition: and( succeeded(), eq(variables['System.PullRequest.PullRequestId'], '') )
328+ condition: >-
329+ and(
330+ succeeded(),
331+ eq(variables['System.PullRequest.PullRequestId'], ''),
332+ eq(variables['UPDATE_DEPENDENTS'], 'false')
333+ )
260334
261335 # publish artifacts (only possible if this is not a PR originated on a fork)
262336 - task : PublishBuildArtifacts@1
263- condition : and( succeeded(), ne(variables['system.pullrequest.isfork'], true) )
337+ condition : >-
338+ and(
339+ succeeded(),
340+ ne(variables['system.pullrequest.isfork'], true),
341+ eq(variables['UPDATE_DEPENDENTS'], 'false')
342+ )
264343 displayName : Publish deployables artifacts
265344 inputs :
266345 PathtoPublish : ' $(Build.ArtifactStagingDirectory)'
@@ -269,7 +348,13 @@ jobs:
269348
270349 # push NuGet class lib package to NuGet (happens on all builds except PRs)
271350 - task : NuGetCommand@2
272- condition : and( succeeded(), eq(variables['System.PullRequest.PullRequestId'], ''), not( startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) )
351+ condition : >-
352+ and(
353+ succeeded(),
354+ eq(variables['System.PullRequest.PullRequestId'], ''),
355+ not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
356+ eq(variables['UPDATE_DEPENDENTS'], 'false')
357+ )
273358 displayName : Push nanoff NuGet package to NuGet
274359 continueOnError : true
275360 inputs :
@@ -282,7 +367,13 @@ jobs:
282367
283368 # push NuGet class lib package to NuGet (happens on all builds except PRs)
284369 - task : NuGetCommand@2
285- condition : and( succeeded(), eq(variables['System.PullRequest.PullRequestId'], ''), not( startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) )
370+ condition : >-
371+ and(
372+ succeeded(),
373+ eq(variables['System.PullRequest.PullRequestId'], ''),
374+ not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
375+ eq(variables['UPDATE_DEPENDENTS'], 'false')
376+ )
286377 displayName : Push library NuGet package to NuGet
287378 continueOnError : true
288379 inputs :
@@ -292,10 +383,33 @@ jobs:
292383 allowPackageConflicts : true
293384 packagesToPush : ' $(Build.ArtifactStagingDirectory)\nanoFramework.Tools.FirmwareFlasher.$(NBGV_NuGetPackageVersion).nupkg'
294385 publishFeedCredentials : ' NuGet-nanoFirmwareFlasher'
295-
386+
387+ # update dependencies
388+ - task : PowerShell@2
389+ condition : >-
390+ and(
391+ or(
392+ eq(variables['UPDATE_DEPENDENTS'], 'true'),
393+ eq(variables['RUN_UPDATE_DEPENDENTS'], 'true')
394+ ),
395+ not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
396+ )
397+ displayName : Update dependent tools
398+ inputs :
399+ targetType : filePath
400+ filePath : azure-pipelines/update-dependencies.ps1
401+ env :
402+ MY_GITHUB_TOKEN : $(GitHubToken)
403+
296404 # create or update GitHub release
297405 - task : GithubRelease@1
298- condition : and( succeeded(), eq(variables['System.PullRequest.PullRequestId'], ''), not( startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) )
406+ condition : >-
407+ and(
408+ succeeded(),
409+ eq(variables['System.PullRequest.PullRequestId'], ''),
410+ not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
411+ eq(variables['UPDATE_DEPENDENTS'], 'false')
412+ )
299413 displayName : Create/Update GitHub PREVIEW release
300414 inputs :
301415 gitHubConnection : ' github.com_nano-$(System.TeamProject)'
@@ -310,7 +424,13 @@ jobs:
310424
311425 # create or update GitHub release
312426 - task : GithubRelease@1
313- condition : and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), not(contains(variables['Build.SourceBranch'], 'preview') ) )
427+ condition : >-
428+ and(
429+ succeeded(),
430+ startsWith(variables['Build.SourceBranch'], 'refs/tags/v'),
431+ not(contains(variables['Build.SourceBranch'], 'preview')),
432+ eq(variables['UPDATE_DEPENDENTS'], 'false')
433+ )
314434 displayName : Create/Update GitHub stable release
315435 inputs :
316436 gitHubConnection : ' github.com_nano-$(System.TeamProject)'
0 commit comments