Skip to content

Commit 37edd47

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 37edd47

File tree

1 file changed

+253
-25
lines changed

1 file changed

+253
-25
lines changed

azure-pipelines.yml

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

0 commit comments

Comments
 (0)