Skip to content

Commit 60f36c4

Browse files
committed
Rework AZDO yaml to build and publish helper and library
- Move to steps pattern. - Add step to find out what to build. - Add step to build, pack and publish helper. - Kept steps to build, pack and publish library.
1 parent 9dd0c43 commit 60f36c4

File tree

1 file changed

+251
-25
lines changed

1 file changed

+251
-25
lines changed

azure-pipelines.yml

Lines changed: 251 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3535
variables:
3636
- group: sign-client-credentials
@@ -45,26 +45,252 @@ 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+
- checkout: self
156+
fetchDepth: 1
157+
158+
# build library
159+
- template: azure-pipelines-templates/class-lib-build.yml@templates
160+
parameters:
161+
sonarCloudProject: 'nanoframework_System.Runtime.Serialization'
162+
runUnitTests: true
163+
unitTestRunsettings: '$(System.DefaultWorkingDirectory)\nano.runsettings'
164+
165+
# report error
166+
- template: azure-pipelines-templates/discord-webhook-task.yml@templates
167+
parameters:
168+
status: 'failure'
169+
webhookUrl: '$(DiscordWebhook)'
170+
message: ''
171+
172+
- stage: BuildHelper
173+
displayName: 'Build Helper'
174+
condition: eq(dependencies.BuildPrep.outputs['RunPreChecks.CheckChanges.BUILD_HELPER'], 'true')
175+
dependsOn: BuildPrep
176+
177+
jobs:
178+
- job: BuildHelper
179+
displayName: 'Building Helper'
180+
181+
pool:
182+
vmImage: 'windows-latest'
183+
184+
variables:
185+
- name: helperSolution
186+
value: 'nanoFramework.Serialization.Helper.sln'
187+
188+
steps:
189+
- checkout: self
190+
fetchDepth: 1
191+
192+
- task: NuGetCommand@2
193+
displayName: NuGet restore
194+
inputs:
195+
restoreSolution: '$(helperSolution)'
196+
feedsToUse: config
197+
nugetConfigPath: 'NuGet.config'
198+
199+
- task: VSBuild@1
200+
inputs:
201+
solution: '$(helperSolution)'
202+
platform: '$(buildPlatform)'
203+
msbuildArchitecture: x64
204+
msbuildArgs: '/p:PublicRelease=true'
205+
configuration: '$(buildConfiguration)'
206+
207+
- script: dotnet build $(helperSolution) -c Release -p:Platform="Any CPU" -p:PublicRelease=true --no-restore /t:build,pack
208+
displayName: Build and pack Helper
209+
condition: succeeded()
210+
211+
# run Unit Tests for helper class lib
212+
- template: azure-pipelines-templates/run-unit-tests.yml@templates
213+
parameters:
214+
skipInstall: true
215+
unitTestRunsettings: '$(System.DefaultWorkingDirectory)\helper.runsettings'
216+
217+
- task: CopyFiles@1
218+
condition: succeeded()
219+
displayName: Collecting deployable artifacts
220+
inputs:
221+
sourceFolder: $(Agent.BuildDirectory)
222+
Contents: |
223+
**\helper*.nupkg
224+
TargetFolder: '$(Build.ArtifactStagingDirectory)'
225+
flattenFolders: true
226+
227+
- task: PowerShell@2
228+
condition: succeeded()
229+
displayName: Check deployable artifacts
230+
inputs:
231+
targetType: 'inline'
232+
script: |
233+
$artifacts = (Get-ChildItem -Path "$env:Build_ArtifactStagingDirectory" -Recurse)
234+
235+
if ($artifacts.Count -eq 0)
236+
{
237+
Write-Error "No deployable artifacts found!"
238+
Exit 1
239+
}
240+
241+
- task: DotNetCoreCLI@2
242+
displayName: Install Sign Client CLI
243+
condition: succeeded()
244+
inputs:
245+
command: custom
246+
custom: tool
247+
arguments: install --tool-path . sign --version 0.9.1-beta.23530.1
248+
249+
- pwsh: |
250+
.\sign code azure-key-vault `
251+
"**/*.nupkg" `
252+
--base-directory "$(Build.ArtifactStagingDirectory)" `
253+
--description ".NET nanoFramework Serialization helper" `
254+
--description-url "https://github.com/$env:Build_Repository_Name" `
255+
--azure-key-vault-tenant-id "$(SignTenantId)" `
256+
--azure-key-vault-client-id "$(SignClientId)" `
257+
--azure-key-vault-client-secret "$(SignClientSecret)" `
258+
--azure-key-vault-certificate "$(SignKeyVaultCertificate)" `
259+
--azure-key-vault-url "$(SignKeyVaultUrl)" `
260+
--timestamp-url http://timestamp.digicert.com
261+
displayName: Sign packages
262+
continueOnError: true
263+
condition: succeeded()
264+
265+
# publish artifacts (only possible if this is not a PR originated on a fork)
266+
- task: PublishPipelineArtifact@1
267+
condition: succeeded()
268+
displayName: Publish deployable artifacts
269+
inputs:
270+
targetPath: '$(Build.ArtifactStagingDirectory)'
271+
artifactName: deployables
272+
artifactType: pipeline
273+
274+
# push NuGet packages to NuGet
275+
- task: NuGetCommand@2
276+
displayName: Push NuGet packages to NuGet
277+
condition: >-
278+
and(
279+
succeeded(),
280+
eq(variables['System.PullRequest.PullRequestNumber'], '')
281+
)
282+
continueOnError: true
283+
inputs:
284+
command: push
285+
nuGetFeedType: external
286+
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
287+
allowPackageConflicts: true
288+
includeSymbols: true
289+
publishFeedCredentials: 'NuGet-$(System.TeamProject)'
290+
291+
# report error
292+
- template: azure-pipelines-templates/discord-webhook-task.yml@templates
293+
parameters:
294+
status: 'failure'
295+
webhookUrl: '$(DiscordWebhook)'
296+
message: ''

0 commit comments

Comments
 (0)