-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclass-lib-build.yml
314 lines (283 loc) · 9.12 KB
/
class-lib-build.yml
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# Copyright (c) .NET Foundation and Contributors
# Portions Copyright (c) Sankarsan Kampa (a.k.a. k3rn31p4nic). All rights reserved.
# See LICENSE file in the project root for full license information.
parameters:
- name: skipNuGetRestore
type: boolean
default: false
- name: skipNuGetCache
type: boolean
default: false
- name: gitUser
type: string
default: nfbot
- name: gitEmail
type: string
default: nanoframework@outlook.com
- name: skipSonarCloudAnalysis
type: boolean
default: false
- name: sonarCloudProject
type: string
default: dummy-key
- name: nugetConfigPath
type: string
default: ''
- name: msbuildExtraParams
type: string
default: ' '
- name: runUnitTests
type: boolean
default: false
- name: unitTestRunsettings
type: string
default: '$(System.DefaultWorkingDirectory)\.runsettings'
steps:
# need this here in order to persist GitHub credentials
- checkout: self
submodules: true
fetchDepth: 0
- script: |
git config --global user.email ${{ parameters.gitEmail }}
git config --global user.name ${{ parameters.gitUser }}
git config --global core.autocrlf true
displayName: Setup git identity
# get commit message
- template: get-commit-details.yml
- template: file-checks.yml
- template: install-nbgv-tool.yml
- template: prepare-release.yml
- task: SonarCloudPrepare@3
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
not(${{ parameters.skipSonarCloudAnalysis }})
)
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: 'sonarcloud-$(System.TeamProject)'
organization: 'nanoframework'
scannerMode: 'dotnet'
projectKey: '${{ parameters.sonarCloudProject }}'
extraProperties: |
sonar.exclusions=**/obj/**,**/*.dll
sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)/**/**.coverage
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/**/**.trx
sonar.scanner.skipJreProvisioning=true
- task: InstallNanoMSBuildComponents@1
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: Install .NET nanoFramework MSBuild components
inputs:
GitHubToken: $(GitHubToken)
- template: install-nuget.yml
- template: cache-nano-nugets.yml
parameters:
skipNuGetCache: ${{ parameters.skipNuGetCache }}
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
not(${{ parameters.skipNuGetRestore }}),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: NuGet restore
retryCountOnTaskFailure: 5
inputs:
restoreSolution: '**/*.sln'
${{ if eq(parameters.nugetConfigPath, '') }}:
feedsToUse: select
${{ else }}:
feedsToUse: config
nugetConfigPath: ${{ parameters.nugetConfigPath }}
- template: versions-check.yml
- task: VSBuild@1
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'],false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
msbuildArgs: '/p:PublicRelease=true ${{ parameters.msbuildExtraParams }}'
configuration: '$(buildConfiguration)'
msbuildArchitecture: 'x64'
maximumCpuCount: true
- template: run-unit-tests.yml
parameters:
runUnitTests: '${{ parameters.runUnitTests }}'
unitTestRunsettings: '${{ parameters.unitTestRunsettings }}'
- template: get-assembly-native-version.yml
- powershell: |
# get subject and commit message for commit
$commitMessage = git log --format='%B' -1
# need to flatten message by removing new lines
$commitMessage = $commitMessage -replace "`r`n", " "
if($commitMessage -like "*PUBLISH_RELEASE*")
{
# set variable
Write-Host "$("##vso[task.setvariable variable=RELEASE_VERSION;isOutput=true]")true"
Write-Host "Release draft: FALSE"
}
else
{
# set variable
Write-Host "$("##vso[task.setvariable variable=RELEASE_VERSION;isOutput=true]")false"
Write-Host "Release draft: TRUE"
}
name: SetReleaseDraftVar
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false)
)
displayName: Set release draft var
- task: SonarCloudAnalyze@3
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
not(${{ parameters.skipSonarCloudAnalysis }})
)
displayName: 'Run Code Analysis'
continueOnError: true
- task: SonarCloudPublish@3
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
not(${{ parameters.skipSonarCloudAnalysis }})
)
displayName: 'Publish Quality Gate Result'
continueOnError: true
- task: UseRubyVersion@0
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')),
eq(variables['StartReleaseCandidate'], false)
)
displayName: Setup Ruby
inputs:
versionSpec: '= 3.0'
addToPath: true
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: Pack NuGet with class library
inputs:
command: 'custom'
arguments: 'pack $(nugetPackageName).nuspec -Version $(MY_NUGET_VERSION) -Symbols -SymbolPackageFormat snupkg -properties nativeVersion="$(NF_ASSEMBLY_NATIVE_VERSION)";commit="$(Build.SourceVersion)";checksum="$(NF_NATIVE_ASSEMBLY_CHECKSUM)"'
- task: CopyFiles@1
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: Collecting deployable artifacts
inputs:
sourceFolder: $(Build.SourcesDirectory)
Contents: |
*$(nugetPackageName)*.nupkg
*$(nugetPackageName)*.snupkg
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: PowerShell@2
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
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: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
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 "$(nugetPackageName)" `
--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: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
# publish artifacts (only possible if this is not a PR originated on a fork)
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: deployables
artifactType: pipeline
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: Publish deployables artifacts
# push NuGet class lib package to NuGet (happens on every build except PRs)
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
continueOnError: true
displayName: Push NuGet packages to NuGet
inputs:
command: push
nuGetFeedType: external
allowPackageConflicts: true
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
includeSymbols: true
publishFeedCredentials: 'NuGet-$(System.TeamProject)'
- template: create-github-release.yml