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