@@ -29,8 +29,8 @@ resources:
2929 name : nanoframework/nf-tools
3030 endpoint : nanoframework
3131
32- pool :
33- vmImage : ' windows-latest'
32+ # pool:
33+ # vmImage: 'windows-latest'
3434
3535variables :
3636 - group : sign-client-credentials
@@ -45,26 +45,249 @@ variables:
4545 - name : nugetPackageName
4646 value : ' nanoFramework.System.Runtime.Serialization'
4747
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+ - task : VSBuild@1
197+ inputs :
198+ solution : ' $(helperSolution)'
199+ platform : ' $(buildPlatform)'
200+ msbuildArchitecture : x64
201+ msbuildArgs : ' /p:PublicRelease=true'
202+ configuration : ' $(buildConfiguration)'
203+
204+ - script : dotnet build $(helperSolution) -c Release -p:Platform="Any CPU" -p:PublicRelease=true --no-restore /t:build,pack
205+ displayName : Build and pack Helper
206+ condition : succeeded()
207+
208+ # run Unit Tests for helper class lib
209+ - template : azure-pipelines-templates/run-unit-tests.yml@templates
210+ parameters :
211+ skipInstall : false
212+ unitTestRunsettings : ' $(System.DefaultWorkingDirectory)\helper.runsettings'
213+
214+ - task : CopyFiles@1
215+ condition : succeeded()
216+ displayName : Collecting deployable artifacts
217+ inputs :
218+ sourceFolder : $(Agent.BuildDirectory)
219+ Contents : |
220+ **\helper*.nupkg
221+ TargetFolder : ' $(Build.ArtifactStagingDirectory)'
222+ flattenFolders : true
223+
224+ - task : PowerShell@2
225+ condition : succeeded()
226+ displayName : Check deployable artifacts
227+ inputs :
228+ targetType : ' inline'
229+ script : |
230+ $artifacts = (Get-ChildItem -Path "$env:Build_ArtifactStagingDirectory" -Recurse)
231+
232+ if ($artifacts.Count -eq 0)
233+ {
234+ Write-Error "No deployable artifacts found!"
235+ Exit 1
236+ }
237+
238+ - task : DotNetCoreCLI@2
239+ displayName : Install Sign Client CLI
240+ condition : succeeded()
241+ inputs :
242+ command : custom
243+ custom : tool
244+ arguments : install --tool-path . sign --version 0.9.1-beta.23530.1
245+
246+ - pwsh : |
247+ .\sign code azure-key-vault `
248+ "**/*.nupkg" `
249+ --base-directory "$(Build.ArtifactStagingDirectory)" `
250+ --description ".NET nanoFramework Serialization helper" `
251+ --description-url "https://github.com/$env:Build_Repository_Name" `
252+ --azure-key-vault-tenant-id "$(SignTenantId)" `
253+ --azure-key-vault-client-id "$(SignClientId)" `
254+ --azure-key-vault-client-secret "$(SignClientSecret)" `
255+ --azure-key-vault-certificate "$(SignKeyVaultCertificate)" `
256+ --azure-key-vault-url "$(SignKeyVaultUrl)" `
257+ --timestamp-url http://timestamp.digicert.com
258+ displayName: Sign packages
259+ continueOnError: true
260+ condition: succeeded()
261+
262+ # publish artifacts (only possible if this is not a PR originated on a fork)
263+ - task : PublishPipelineArtifact@1
264+ condition : succeeded()
265+ displayName : Publish deployable artifacts
266+ inputs :
267+ targetPath : ' $(Build.ArtifactStagingDirectory)'
268+ artifactName : deployables
269+ artifactType : pipeline
270+
271+ # push NuGet packages to NuGet
272+ - task : NuGetCommand@2
273+ displayName : Push NuGet packages to NuGet
274+ condition : >-
275+ and(
276+ succeeded(),
277+ eq(variables['System.PullRequest.PullRequestNumber'], '')
278+ )
279+ continueOnError : true
280+ inputs :
281+ command : push
282+ nuGetFeedType : external
283+ packagesToPush : ' $(Build.ArtifactStagingDirectory)/*.nupkg'
284+ allowPackageConflicts : true
285+ includeSymbols : true
286+ publishFeedCredentials : ' NuGet-$(System.TeamProject)'
287+
288+ # report error
289+ - template : azure-pipelines-templates/discord-webhook-task.yml@templates
290+ parameters :
291+ status : ' failure'
292+ webhookUrl : ' $(DiscordWebhook)'
293+ message : ' '
0 commit comments