@@ -29,8 +29,8 @@ resources:
29
29
name : nanoframework/nf-tools
30
30
endpoint : nanoframework
31
31
32
- pool :
33
- vmImage : ' windows-latest'
32
+ # pool:
33
+ # vmImage: 'windows-latest'
34
34
35
35
variables :
36
36
- group : sign-client-credentials
@@ -45,26 +45,242 @@ variables:
45
45
- name : nugetPackageName
46
46
value : ' nanoFramework.System.Runtime.Serialization'
47
47
48
- steps :
49
-
50
- # step from template @ nf-tools repo
51
- # all build, update and publish steps
52
- - template : azure-pipelines-templates/class-lib-build.yml@templates
53
- parameters :
54
- sonarCloudProject : ' nanoframework_System.Runtime.Serialization'
55
- runUnitTests : true
56
- unitTestRunsettings : ' $(System.DefaultWorkingDirectory)\nano.runsettings'
57
-
58
- # run Unit Tests for helper class lib
59
- - template : azure-pipelines-templates/run-unit-tests.yml@templates
60
- parameters :
61
- skipInstall : true
62
- unitTestRunsettings : ' $(System.DefaultWorkingDirectory)\helper.runsettings'
63
-
64
- # step from template @ nf-tools repo
65
- # report error
66
- - template : azure-pipelines-templates/discord-webhook-task.yml@templates
67
- parameters :
68
- status : ' failure'
69
- webhookUrl : ' $(DiscordWebhook)'
70
- message : ' '
48
+ stages :
49
+ - stage : BuildPrep
50
+ displayName : ' Build preparations'
51
+ jobs :
52
+ - job : RunPreChecks
53
+ displayName : ' Running prep checks'
54
+
55
+ pool :
56
+ vmImage : ' ubuntu-latest'
57
+
58
+ steps :
59
+ - checkout : self
60
+ fetchDepth : 1
61
+
62
+ - task : PowerShell@2
63
+ displayName : Check changes
64
+ name : CheckChanges
65
+ inputs :
66
+ targetType : ' inline'
67
+ script : |
68
+ git config --global user.email "[email protected] "
69
+ git config --global user.name "nfbot"
70
+
71
+ $auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$(GitHubToken)")))"
72
+
73
+ if($env:Build_Reason -eq "Manual")
74
+ {
75
+ # this is a manual build, no need to check anything
76
+ Write-host "##[command] Manual build"
77
+ }
78
+ else
79
+ {
80
+ if($env:System_PullRequest_PullRequestNumber -ne $null)
81
+ {
82
+ # get files changed in PR, if this is a PR
83
+ $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
84
+
85
+ # filter removed files
86
+ $files = $commit.where{$_.status -ne 'removed'}
87
+ }
88
+ else
89
+ {
90
+ # get files changed in the commit, if this is NOT a PR
91
+ $commit = Invoke-RestMethod -Uri "https://api.github.com/repos/$env:BUILD_REPOSITORY_NAME/commits/$(Build.SourceVersion)" -Header @{"Authorization"="$auth"} -ContentType "application/json" -Method GET
92
+
93
+ # filter removed files
94
+ $files = $commit.files.where{$_.status -ne 'removed'}
95
+ }
96
+
97
+ # get file names only
98
+ $files = $files | % {$_.filename}
99
+
100
+ Write-host "##[group] Files changed:"
101
+ $files | % { Write-host $_ }
102
+ Write-host "##[endgroup]"
103
+
104
+ # set default values
105
+ echo "##vso[task.setvariable variable=BUILD_LIBRARY;isOutput=true]false"
106
+ echo "##vso[task.setvariable variable=BUILD_HELPER;isOutput=true]false"
107
+
108
+ if(
109
+ (($files.where{$_.Contains('/')}).Count -eq 0) -Or
110
+ (($files.where{$_.StartsWith('Serialization.Shared')}).Count -gt 0) -Or
111
+ (($files.where{$_.StartsWith('Tests')}).Count -gt 0)
112
+ )
113
+ {
114
+ # files at:
115
+ # - repo root
116
+ # - tests
117
+ # - shared location
118
+
119
+ echo "##vso[task.setvariable variable=BUILD_LIBRARY;isOutput=true]true"
120
+ echo "##vso[task.setvariable variable=BUILD_HELPER;isOutput=true]true"
121
+
122
+ Write-host "##[command] Building both solutions"
123
+ }
124
+
125
+ if( ($files.where{$_.Contains('nanoFramework.Serialization.Helper')}).Count -gt 0)
126
+ {
127
+ # files at nanoFramework.Serialization.Helper folder
128
+ echo "##vso[task.setvariable variable=BUILD_HELPER;isOutput=true]true"
129
+
130
+ Write-host "##[command] Build Helper"
131
+ }
132
+
133
+ if( ($files.where{$_.Contains('nanoFramework.System.Runtime.Serialization')}).Count -gt 0)
134
+ {
135
+ # files at nanoFramework.System.Runtime.Serialization folder
136
+ echo "##vso[task.setvariable variable=BUILD_LIBRARY;isOutput=true]true"
137
+
138
+ Write-host "##[command] Build Library"
139
+ }
140
+ }
141
+
142
+ - stage : BuildLibrary
143
+ displayName : ' Build Library'
144
+ condition : eq(dependencies.BuildPrep.outputs['RunPreChecks.CheckChanges.BUILD_LIBRARY'], 'true')
145
+ dependsOn : BuildPrep
146
+
147
+ jobs :
148
+ - job : BuildLibrary
149
+ displayName : ' Building Library'
150
+
151
+ pool :
152
+ vmImage : ' windows-latest'
153
+
154
+ steps :
155
+
156
+ # build library
157
+ - template : azure-pipelines-templates/class-lib-build.yml@templates
158
+ parameters :
159
+ sonarCloudProject : ' nanoframework_System.Runtime.Serialization'
160
+ runUnitTests : true
161
+ unitTestRunsettings : ' $(System.DefaultWorkingDirectory)\nano.runsettings'
162
+
163
+ # report error
164
+ - template : azure-pipelines-templates/discord-webhook-task.yml@templates
165
+ parameters :
166
+ status : ' failure'
167
+ webhookUrl : ' $(DiscordWebhook)'
168
+ message : ' '
169
+
170
+ - stage : BuildHelper
171
+ displayName : ' Build Helper'
172
+ condition : eq(dependencies.BuildPrep.outputs['RunPreChecks.CheckChanges.BUILD_HELPER'], 'true')
173
+ dependsOn : BuildPrep
174
+
175
+ jobs :
176
+ - job : BuildHelper
177
+ displayName : ' Building Helper'
178
+
179
+ pool :
180
+ vmImage : ' windows-latest'
181
+
182
+ variables :
183
+ - name : helperSolution
184
+ value : ' nanoFramework.Serialization.Helper.sln'
185
+
186
+ steps :
187
+ - checkout : self
188
+
189
+ - task : NuGetCommand@2
190
+ displayName : NuGet restore
191
+ inputs :
192
+ restoreSolution : ' $(helperSolution)'
193
+ feedsToUse : config
194
+ nugetConfigPath : ' NuGet.config'
195
+
196
+ - script : dotnet build $(helperSolution) -c Release -p:Platform="Any CPU" -p:PublicRelease=true --no-restore /t:build,pack
197
+ displayName : Build and pack Helper
198
+ condition : succeeded()
199
+
200
+ # run Unit Tests for helper class lib
201
+ - template : azure-pipelines-templates/run-unit-tests.yml@templates
202
+ parameters :
203
+ skipInstall : false
204
+ unitTestRunsettings : ' $(System.DefaultWorkingDirectory)\helper.runsettings'
205
+
206
+ - task : CopyFiles@1
207
+ condition : succeeded()
208
+ displayName : Collecting deployable artifacts
209
+ inputs :
210
+ sourceFolder : $(Agent.BuildDirectory)
211
+ Contents : |
212
+ **\nanoFramework.Serialization.Helper*.nupkg
213
+ **\nanoFramework.Serialization.Helper*.snupkg
214
+ TargetFolder : ' $(Build.ArtifactStagingDirectory)'
215
+ flattenFolders : true
216
+
217
+ - task : PowerShell@2
218
+ condition : succeeded()
219
+ displayName : Check deployable artifacts
220
+ inputs :
221
+ targetType : ' inline'
222
+ script : |
223
+ $artifacts = (Get-ChildItem -Path "$env:Build_ArtifactStagingDirectory" -Recurse)
224
+
225
+ if ($artifacts.Count -eq 0)
226
+ {
227
+ Write-Error "No deployable artifacts found!"
228
+ Exit 1
229
+ }
230
+
231
+ - task : DotNetCoreCLI@2
232
+ displayName : Install Sign Client CLI
233
+ condition : succeeded()
234
+ inputs :
235
+ command : custom
236
+ custom : tool
237
+ arguments : install --tool-path . sign --version 0.9.1-beta.23530.1
238
+
239
+ - pwsh : |
240
+ .\sign code azure-key-vault `
241
+ "**/*.nupkg" `
242
+ --base-directory "$(Build.ArtifactStagingDirectory)" `
243
+ --description ".NET nanoFramework Serialization helper" `
244
+ --description-url "https://github.com/$env:Build_Repository_Name" `
245
+ --azure-key-vault-tenant-id "$(SignTenantId)" `
246
+ --azure-key-vault-client-id "$(SignClientId)" `
247
+ --azure-key-vault-client-secret "$(SignClientSecret)" `
248
+ --azure-key-vault-certificate "$(SignKeyVaultCertificate)" `
249
+ --azure-key-vault-url "$(SignKeyVaultUrl)" `
250
+ --timestamp-url http://timestamp.digicert.com
251
+ displayName: Sign packages
252
+ continueOnError: true
253
+ condition: succeeded()
254
+
255
+ # publish artifacts (only possible if this is not a PR originated on a fork)
256
+ - task : PublishPipelineArtifact@1
257
+ condition : succeeded()
258
+ displayName : Publish helper artifacts
259
+ inputs :
260
+ targetPath : ' $(Build.ArtifactStagingDirectory)'
261
+ artifactName : helper-artifacts
262
+ artifactType : pipeline
263
+
264
+ # push NuGet packages to NuGet
265
+ - task : NuGetCommand@2
266
+ displayName : Push NuGet packages to NuGet
267
+ condition : >-
268
+ and(
269
+ succeeded(),
270
+ eq(variables['System.PullRequest.PullRequestNumber'], '')
271
+ )
272
+ continueOnError : true
273
+ inputs :
274
+ command : push
275
+ nuGetFeedType : external
276
+ packagesToPush : ' $(Build.ArtifactStagingDirectory)/*.nupkg'
277
+ allowPackageConflicts : true
278
+ includeSymbols : true
279
+ publishFeedCredentials : ' NuGet-$(System.TeamProject)'
280
+
281
+ # report error
282
+ - template : azure-pipelines-templates/discord-webhook-task.yml@templates
283
+ parameters :
284
+ status : ' failure'
285
+ webhookUrl : ' $(DiscordWebhook)'
286
+ message : ' '
0 commit comments