-
Notifications
You must be signed in to change notification settings - Fork 71
/
azure-pipelines.yml
296 lines (266 loc) · 10.4 KB
/
azure-pipelines.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
# Build, test and package idunno.Authentication nuget packages
trigger:
- dev
- rel/*
- dependabot/*
pr:
- dev
- dependabot/*
- rel/*
variables:
solution: '**/*.sln'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
disable.coverage.autogenerate: 'true'
isDevBranch: $[eq(variables['Build.SourceBranch'], 'refs/heads/dev')]
isReleaseBranch: $[eq(variables['Build.SourceBranch'], 'refs/heads/rel')]
isPullRequest: $[eq(variables['Build.Reason'], 'PullRequest')]
stages:
- stage: Build
displayName: Build, test and package
variables:
- group: 'Report Generator License Key'
jobs:
- job: Build
pool:
vmImage: 'windows-latest'
steps:
# .NET 8
- task: UseDotNet@2
displayName: 'Install .NET Core 8.0.x SDK'
inputs:
version: '8.0.x'
packageType: 'sdk'
# .NET 6
- task: UseDotNet@2
displayName: 'Install .NET Core 6.0.x SDK'
inputs:
version: '6.0.x'
packageType: 'sdk'
# .NET 3.1 sdk, needed for certificate authentication tests
- task: UseDotNet@2
displayName: 'Install .NET Core 3.1 SDK'
inputs:
version: '3.1.x'
packageType: 'sdk'
# Install nerdbank versioning tool
# https://github.com/dotnet/Nerdbank.GitVersioning/blob/master/doc/nbgv-cli.md
- task: DotNetCoreCLI@2
displayName: Install NBGV tool
inputs:
command: custom
custom: tool
arguments: install --tool-path tooling nbgv
- script: .\tooling\nbgv cloud
displayName: Build Version Properties
# Build
- task: DotNetCoreCLI@2
displayName: dotnet build
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
# Run tests
- task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: test
projects: '**/test/**/*.csproj'
arguments: '--configuration $(buildConfiguration) --settings $(Build.SourcesDirectory)/tests.runsettings -- RunConfiguration.DisableAppDomain=true'
# Generate code coverage report
# https://danielpalme.github.io/ReportGenerator/
- task: reportgenerator@5
displayName: Generate Code Coverage Report
inputs:
reports: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
targetdir: $(Build.ArtifactStagingDirectory)/coverageReports/
reporttypes: 'HtmlInline_AzurePipelines;Cobertura;Badges'
license: '$(ReportGeneratorLicenseKey)'
# Produce unsigned packages
- task: DotNetCoreCLI@2
displayName: "dotnet pack"
inputs:
command: 'pack'
outputDir: '$(Build.ArtifactStagingDirectory)/Packages'
configuration: $(buildConfiguration)
arguments: '/p:IncludeSymbols=true'
verbosityPack: minimal
packagesToPack: '**/src/**/*.csproj'
nobuild: true
# Publish unsigned packages
- publish: $(Build.ArtifactStagingDirectory)/Packages
displayName: Publish artifacts
artifact: BuildPackages
# Publish Code Coverage results
- task: PublishCodeCoverageResults@2
displayName: 'Publish Code Coverage Results'
inputs:
codeCoverageTool: cobertura
summaryFileLocation: $(Build.ArtifactStagingDirectory)/coverageReports/Cobertura.xml
reportDirectory: $(Build.ArtifactStagingDirectory)/coverageReports/
- stage : PublishUnsigned
displayName: Push unsigned artificates to artifact feed
dependsOn: Build
condition: |
and(
succeeded('Build'),
startsWith(variables['Build.sourceBranch'], 'refs/heads/dev'),
not(eq(variables['build.reason'], 'PullRequest'))
)
jobs:
- job: PublishUnsigned
displayName: Push unsigned packages
pool:
vmImage: 'windows-latest'
steps:
- checkout: none
- download: current
displayName: 'Get unsignedPackages from build stage'
artifact: BuildPackages
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: DotNetCoreCLI@2
displayName: 'Push unsigned packages to Artifacts feed'
inputs:
command: 'push'
searchPatternPush: '$(Pipeline.Workspace)/BuildPackages/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'idunno.Authentication/idunno.Authentication.Builds'
allowPackageConflicts: false
- stage: CodeSign
displayName: Codesign release assemblies and packages
dependsOn: PublishUnsigned
condition: |
and(
succeeded('Build'),
startsWith(variables['Build.sourceBranch'], 'refs/heads/rel'),
not(eq(variables['build.reason'], 'PullRequest'))
)
jobs:
- deployment: CodeSign
displayName: Code Signing
pool:
vmImage: windows-latest
environment: Signing Isolation
variables:
- group: Signing Credentials
strategy:
runOnce:
deploy:
steps:
- checkout: none
- download: current
displayName: 'Get unsignedPackages from build stage'
artifact: BuildPackages
# Install nuget tool
- task: NuGetToolInstaller@1
# Install azuresigntool
# https://github.com/vcsjones/AzureSignTool
- task: DotNetCoreCLI@2
displayName: Install AzureCodeSign tool
inputs:
command: custom
custom: tool
arguments: install --tool-path tooling azuresigntool
- task: PowerShell@2
displayName: Expand build output nupkgs
inputs:
# We need to extract the assemblies we built in the build stage from
# the build output nupkgs to authenticode sign them
targetType: inline
script : |
Get-ChildItem $(Pipeline.Workspace)\BuildPackages\*.nupkg | Rename-Item -NewName {$_.name -Replace '\.nupkg$', '.zip' }
Get-ChildItem -Path "$(Pipeline.Workspace)\BuildPackages\*.zip" |
Foreach-Object {
Write-Host "Expanding" $_.FullName
$DestinationDirectory = $_.FullName.replace('.zip', '')
Expand-Archive $_.FullName -DestinationPath $DestinationDirectory
# Delete the things that will be recreated by the nuget pack command
Remove-Item -Recurse -Force "$DestinationDirectory\_rels"
Remove-Item -Recurse -Force "$DestinationDirectory\package"
# To remove [Content-Types].xml we have to get creative, as [ and ] are pattern matching characters
Get-ChildItem $DestinationDirectory | Where-Object Name -Like '`[Content_Types`].xml' | ForEach-Object { Remove-Item -LiteralPath $_.FullName }
}
- task: PowerShell@2
displayName: Sign assemblies extracted from nupkgs
env:
SigningUrl: $(SigningURL)
SigningCertificate: $(SigningCertName)
SigningClientId: $(SigningClientId)
SigningClientSecret: $(SigningClientSecret)
SigningVaultUrl: $(SigningVaultURL)
TenantId: $(AzureTenantId)
inputs:
# Build a file list of extracted assemblies to sign that we know are ours.
targetType: inline
script: |
Write-Host "Signing for $Env:SigningUrl"
$fileList = @()
Get-ChildItem -Path "$(Pipeline.Workspace)\BuildPackages\idunno.Authentication.*.dll" -Recurse |
Foreach-Object {
$fileList += $_.FullName
}
$filesForSigning = $filelist -join "`n"
Write-Host "Files for signing:"
Write-Host $filesForSigning
$filesForSigning | Out-File -FilePath .\fileList.txt
.\tooling\azuresigntool.exe sign `
-du "$Env:SigningUrl" `
-fd sha512 `
-tr http://timestamp.digicert.com `
-td sha384 `
-kvu $Env:SigningVaultUrl `
-kvt $Env:TenantId `
-kvi $Env:SigningClientId `
-kvs $Env:SigningClientSecret `
-kvc $Env:SigningCertificate `
-v `
-ifl .\FileList.txt
Remove-Item .\fileList.txt
- task: PowerShell@2
displayName: Repack nupkgs
inputs:
targetType: inline
script : |
Get-ChildItem -Path "$(Pipeline.Workspace)\BuildPackages\*.zip" |
Foreach-Object {
nuget pack $_.FullName.replace('.zip', '') -OutputDirectory $(Pipeline.Workspace)\BuildPackages
Remove-Item $_.FullName.replace('.zip', '') -Recurse
Remove-Item $_.FullName
}
# Install nugetkeyvaultsigntool
# https://github.com/novotnyllc/NuGetKeyVaultSignTool
- task: DotNetCoreCLI@2
displayName: Install NuGetKeyVaultSignTool tool
inputs:
command: custom
custom: tool
arguments: install --tool-path tooling NuGetKeyVaultSignTool
- task: PowerShell@2
displayName: Sign nupkgs
env:
SigningUrl: $(SigningURL)
SigningCertificate: $(SigningCertName)
SigningClientId: $(SigningClientId)
SigningClientSecret: $(SigningClientSecret)
SigningVaultUrl: $(SigningVaultURL)
TenantId: $(AzureTenantId)
inputs:
targetType: inline
script: |
.\tooling\NuGetKeyVaultSignTool.exe sign $(Pipeline.Workspace)/BuildPackages/**/*.nupkg `
--file-digest "sha256" `
--timestamp-rfc3161 "http://timestamp.digicert.com" `
--timestamp-digest "sha256" `
--azure-key-vault-url "$Env:SigningVaultUrl" `
--azure-key-vault-tenant-id "$Env:TenantId" `
--azure-key-vault-client-id "$Env:SigningClientId" `
--azure-key-vault-client-secret "$Env:SigningClientSecret" `
--azure-key-vault-certificate "$Env:SigningCertificate"
# Publish signed packages
- publish: $(Pipeline.Workspace)\BuildPackages
displayName: Publish signed artifacts
artifact: SignedPackages