-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
windows-packaging.yml
379 lines (316 loc) · 16.3 KB
/
windows-packaging.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
parameters:
- name: BuildConfiguration
default: release
- name: BuildPlatform
default: any cpu
- name: Architecture
default: x64
- name: parentJob
default: ''
jobs:
- job: sign_windows_${{ parameters.Architecture }}_${{ parameters.BuildConfiguration }}
displayName: Package Windows - ${{ parameters.Architecture }} ${{ parameters.BuildConfiguration }}
condition: succeeded()
dependsOn: ${{ parameters.parentJob }}
pool:
name: PowerShell1ES
demands:
- ImageOverride -equals MMS2019TLS
variables:
- name: BuildConfiguration
value: ${{ parameters.BuildConfiguration }}
- name: BuildPlatform
value: ${{ parameters.BuildPlatform }}
- name: Architecture
value: ${{ parameters.Architecture }}
- name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE
value: 1
- group: ESRP
steps:
- checkout: self
clean: true
- checkout: ComplianceRepo
clean: true
- template: SetVersionVariables.yml
parameters:
ReleaseTagVar: $(ReleaseTagVar)
- template: shouldSign.yml
- powershell: |
$pkgFilter = if ( '$(Architecture)' -eq 'arm' ) { "arm32" } else { '$(Architecture)' }
if ($env:BuildConfiguration -eq 'minSize') { $pkgFilter += '-gc' }
$vstsCommandString = "vso[task.setvariable variable=PkgFilter]$pkgFilter"
Write-Host ("sending " + $vstsCommandString)
Write-Host "##$vstsCommandString"
displayName: Set packageName variable
- task: DownloadBuildArtifacts@0
inputs:
artifactName: 'results'
itemPattern: '**/*$(PkgFilter).zip'
downloadPath: '$(System.ArtifactsDirectory)\Symbols'
- template: cloneToOfficialPath.yml
- pwsh: |
# cleanup previous install
if((Test-Path "${env:ProgramFiles(x86)}\WiX Toolset xcopy")) {
Remove-Item "${env:ProgramFiles(x86)}\WiX Toolset xcopy" -Recurse -Force
}
$toolsDir = New-Item -ItemType Directory -Path '$(Build.ArtifactStagingDirectory)\tools'
$wixUri = 'https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip'
Invoke-RestMethod -Uri $wixUri -OutFile '$(Build.ArtifactStagingDirectory)\tools\wix.zip' -MaximumRetryCount 5 -RetryIntervalSec 10
Import-Module '$(PowerShellRoot)/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/wix.psm1'
Install-WixZip -zipPath '$(Build.ArtifactStagingDirectory)\tools\wix.zip'
$msixUrl = '$(makeappUrl)'
Invoke-RestMethod -Uri $msixUrl -OutFile '\makeappx.zip'
Expand-Archive '\makeappx.zip' -destination '\' -Force
displayName: Install packaging tools
- powershell: |
$zipPathString = '$(System.ArtifactsDirectory)\Symbols\results\*$(PkgFilter).zip'
Write-Verbose -Verbose "Zip Path: $zipPathString"
$zipPath = Get-Item $zipPathString
if(@($zipPath).Count -eq 0) {
throw "No files found at '$zipPathString'"
}
elseif(@($zipPath).Count -ne 1) {
$names = $zipPath.Name -join "', '"
throw "multiple files '${names}' found with '${zipPathString}'"
}
$expandedFolder = $zipPath.BaseName
Write-Host "sending.. vso[task.setvariable variable=SymbolsFolder]$expandedFolder"
Write-Host "##vso[task.setvariable variable=SymbolsFolder]$expandedFolder"
Expand-Archive -Path $zipPath -Destination "$(System.ArtifactsDirectory)\$expandedFolder" -Force
displayName: Expand symbols zip
- pwsh: |
$fullSymbolsFolder = "$(System.ArtifactsDirectory)\$($env:SYMBOLSFOLDER)"
$filesToSignDirectory = "$(System.ArtifactsDirectory)\toBeSigned"
$null = New-Item -ItemType Directory -Path $filesToSignDirectory -Force
$signedFilesDirectory = "$(System.ArtifactsDirectory)\signed"
$null = New-Item -ItemType Directory -Path $signedFilesDirectory -Force
$itemsToCopyWithRecurse = @(
"$($fullSymbolsFolder)\*.ps1"
"$($fullSymbolsFolder)\Microsoft.PowerShell*.dll"
)
$itemsToCopy = @{
"$($fullSymbolsFolder)\*.ps1" = ""
"$($fullSymbolsFolder)\Microsoft.Management.Infrastructure.CimCmdlets.dll" = ""
"$($fullSymbolsFolder)\Microsoft.WSMan.*.dll" = ""
"$($fullSymbolsFolder)\Modules\CimCmdlets\CimCmdlets.psd1" = "Modules\CimCmdlets"
"$($fullSymbolsFolder)\Modules\Microsoft.PowerShell.Diagnostics\Diagnostics.format.ps1xml" = "Modules\Microsoft.PowerShell.Diagnostics"
"$($fullSymbolsFolder)\Modules\Microsoft.PowerShell.Diagnostics\Event.format.ps1xml" = "Modules\Microsoft.PowerShell.Diagnostics"
"$($fullSymbolsFolder)\Modules\Microsoft.PowerShell.Diagnostics\GetEvent.types.ps1xml" = "Modules\Microsoft.PowerShell.Diagnostics"
"$($fullSymbolsFolder)\Modules\Microsoft.PowerShell.Diagnostics\Microsoft.PowerShell.Diagnostics.psd1" = "Modules\Microsoft.PowerShell.Diagnostics"
"$($fullSymbolsFolder)\Modules\Microsoft.PowerShell.Host\Microsoft.PowerShell.Host.psd1" = "Modules\Microsoft.PowerShell.Host"
"$($fullSymbolsFolder)\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1" = "Modules\Microsoft.PowerShell.Management"
"$($fullSymbolsFolder)\Modules\Microsoft.PowerShell.Security\Microsoft.PowerShell.Security.psd1" = "Modules\Microsoft.PowerShell.Security"
"$($fullSymbolsFolder)\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1" = "Modules\Microsoft.PowerShell.Utility"
"$($fullSymbolsFolder)\Modules\Microsoft.WSMan.Management\Microsoft.WSMan.Management.psd1" = "Modules\Microsoft.WSMan.Management"
"$($fullSymbolsFolder)\Modules\Microsoft.WSMan.Management\WSMan.format.ps1xml" = "Modules\Microsoft.WSMan.Management"
"$($fullSymbolsFolder)\Modules\PSDiagnostics\PSDiagnostics.ps?1" = "Modules\PSDiagnostics"
"$($fullSymbolsFolder)\pwsh.dll" = ""
"$($fullSymbolsFolder)\System.Management.Automation.dll" = ""
"$($fullSymbolsFolder)\pwsh.exe" = ""
}
$itemsToExclude = @(
# This package is retrieved from https://www.github.com/powershell/MarkdownRender
"$($fullSymbolsFolder)\Microsoft.PowerShell.MarkdownRender.dll"
)
Write-Verbose -verbose "recusively copying $($itemsToCopyWithRecurse | out-string) to $filesToSignDirectory"
Copy-Item -Path $itemsToCopyWithRecurse -Destination $filesToSignDirectory -Recurse -verbose -exclude $itemsToExclude
foreach($pattern in $itemsToCopy.Keys) {
$destinationFolder = Join-Path $filesToSignDirectory -ChildPath $itemsToCopy.$pattern
$null = New-Item -ItemType Directory -Path $destinationFolder -Force
Write-Verbose -verbose "copying $pattern to $destinationFolder"
Copy-Item -Path $pattern -Destination $destinationFolder -Recurse -verbose
}
displayName: 'Prepare files to be signed'
- template: EsrpSign.yml@ComplianceRepo
parameters:
buildOutputPath: $(System.ArtifactsDirectory)\toBeSigned
signOutputPath: $(System.ArtifactsDirectory)\signed
certificateId: "$(AUTHENTICODE_CERT)"
pattern: |
**\*.dll
**\*.psd1
**\*.psm1
**\*.ps1xml
**\*.ps1
**\*.exe
useMinimatch: true
shouldSign: $(SHOULD_SIGN)
displayName: Sign our binaries
- pwsh: |
Import-Module $(PowerShellRoot)/build.psm1 -Force
Import-Module $(PowerShellRoot)/tools/packaging -Force
$signedFilesPath = '$(System.ArtifactsDirectory)\signed\'
$BuildPath = '$(System.ArtifactsDirectory)\$(SymbolsFolder)'
Update-PSSignedBuildFolder -BuildPath $BuildPath -SignedFilesPath $SignedFilesPath
$dlls = Get-ChildItem $BuildPath\*.dll, $BuildPath\*.exe -Recurse
$signatures = $dlls | Get-AuthenticodeSignature
$missingSignatures = $signatures | Where-Object { $_.status -eq 'notsigned' -or $_.SignerCertificate.Issuer -notmatch '^CN=Microsoft.*'}| select-object -ExpandProperty Path
Write-Verbose -verbose "to be signed:`r`n $($missingSignatures | Out-String)"
$filesToSignDirectory = "$(System.ArtifactsDirectory)\thirdPartyToBeSigned"
$null = New-Item -ItemType Directory -Path $filesToSignDirectory -Force
$signedFilesDirectory = "$(System.ArtifactsDirectory)\thirdPartySigned"
$null = New-Item -ItemType Directory -Path $signedFilesDirectory -Force
$missingSignatures | ForEach-Object {
$pathWithoutLeaf = Split-Path $_
$relativePath = $pathWithoutLeaf.replace($BuildPath,'')
$targetDirectory = Join-Path -Path $filesToSignDirectory -ChildPath $relativePath
if(!(Test-Path $targetDirectory))
{
$null = New-Item -ItemType Directory -Path $targetDirectory -Force
}
Copy-Item -Path $_ -Destination $targetDirectory
}
displayName: Create ThirdParty Signing Folder
condition: and(succeeded(), eq(variables['SHOULD_SIGN'], 'true'))
- template: EsrpSign.yml@ComplianceRepo
parameters:
buildOutputPath: $(System.ArtifactsDirectory)\thirdPartyToBeSigned
signOutputPath: $(System.ArtifactsDirectory)\thirdPartySigned
certificateId: "CP-231522"
pattern: |
**\*.dll
useMinimatch: true
shouldSign: $(SHOULD_SIGN)
displayName: Sign ThirdParty binaries
- powershell: |
Get-ChildItem '$(System.ArtifactsDirectory)\thirdPartySigned\*'
displayName: Capture ThirdParty Signed files
condition: and(succeeded(), eq(variables['SHOULD_SIGN'], 'true'))
- powershell: |
Import-Module $(PowerShellRoot)/build.psm1 -Force
Import-Module $(PowerShellRoot)/tools/packaging -Force
$signedFilesPath = '$(System.ArtifactsDirectory)\thirdPartySigned'
$BuildPath = '$(System.ArtifactsDirectory)\$(SymbolsFolder)'
Update-PSSignedBuildFolder -BuildPath $BuildPath -SignedFilesPath $SignedFilesPath
displayName: Merge ThirdParty signed files with Build
condition: and(succeeded(), eq(variables['SHOULD_SIGN'], 'true'))
- template: Sbom.yml@ComplianceRepo
parameters:
BuildDropPath: '$(System.ArtifactsDirectory)\$(SymbolsFolder)'
Build_Repository_Uri: $(Github_Build_Repository_Uri)
PackageName: PowerShell Windows ${{ parameters.Architecture }} ${{ parameters.BuildConfiguration }}
PackageVersion: $(Version)
sourceScanPath: '$(PowerShellRoot)\tools'
- powershell: |
Import-Module $(PowerShellRoot)/build.psm1 -Force
Import-Module $(PowerShellRoot)/tools/packaging -Force
$destFolder = '$(System.ArtifactsDirectory)\signedZip'
$BuildPath = '$(System.ArtifactsDirectory)\$(SymbolsFolder)'
New-Item -ItemType Directory -Path $destFolder -Force
$BuildPackagePath = New-PSBuildZip -BuildPath $BuildPath -DestinationFolder $destFolder
Write-Verbose -Verbose "New-PSSignedBuildZip returned `$BuildPackagePath as: $BuildPackagePath"
Write-Host "##vso[artifact.upload containerfolder=results;artifactname=results]$BuildPackagePath"
$vstsCommandString = "vso[task.setvariable variable=BuildPackagePath]$BuildPackagePath"
Write-Host ("sending " + $vstsCommandString)
Write-Host "##$vstsCommandString"
displayName: Compress signed files
- pwsh: |
$runtime = switch ($env:Architecture)
{
"x64" { "win7-x64" }
"x86" { "win7-x86" }
"arm" { "win-arm"}
"arm64" { "win-arm64" }
"fxdependent" { "fxdependent" }
"fxdependentWinDesktop" { "fxdependent-win-desktop" }
}
$signedPkg = "$(BuildPackagePath)"
Write-Verbose -Verbose -Message "signedPkg = $signedPkg"
$params = @{}
if ($env:BuildConfiguration -eq 'minSize') {
$params['ForMinimalSize'] = $true
}
$(PowerShellRoot)/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 -BuildZip $signedPkg -location '$(PowerShellRoot)' -destination '$(System.ArtifactsDirectory)\pkgSigned' -Runtime $runtime -ReleaseTag '$(ReleaseTagVar)' @params
displayName: 'Build Windows Universal - $(Architecture) Package'
- powershell: |
Get-ChildItem '$(System.ArtifactsDirectory)\pkgSigned' | ForEach-Object {
$packagePath = $_.FullName
Write-Host "Uploading $packagePath"
Write-Host "##vso[artifact.upload containerfolder=signed;artifactname=signed]$packagePath"
}
displayName: Upload unsigned packages
- ${{ if and(ne(variables['BuildConfiguration'],'minSize'), in(variables['Architecture'], 'x64', 'x86')) }}:
- template: EsrpSign.yml@ComplianceRepo
parameters:
buildOutputPath: $(System.ArtifactsDirectory)\pkgSigned
signOutputPath: $(Build.StagingDirectory)\signedPackages
certificateId: "$(AUTHENTICODE_CERT)"
pattern: |
**\*.msi
useMinimatch: true
shouldSign: $(SHOULD_SIGN)
displayName: Sign MSI
alwaysCopy: true
- pwsh: |
Get-ChildItem '$(System.ArtifactsDirectory)\signedPackages' | ForEach-Object {
$packagePath = $_.FullName
Write-Host "Uploading $packagePath"
Write-Host "##vso[artifact.upload containerfolder=finalResults;artifactname=finalResults]$packagePath"
}
displayName: Upload signed MSI to finalResults
- task: AzureFileCopy@4
displayName: 'upload signed msi to Azure - ${{ parameters.architecture }}'
inputs:
SourcePath: '$(Build.StagingDirectory)\signedPackages\PowerShell-$(version)-win-${{ parameters.architecture }}.msi'
azureSubscription: '$(AzureFileCopySubscription)'
Destination: AzureBlob
storage: '$(StorageAccount)'
ContainerName: '$(AzureVersion)'
resourceGroup: '$(StorageResourceGroup)'
- pwsh: |
cd $(PowerShellRoot)
Import-Module $(PowerShellRoot)/build.psm1 -Force
Import-Module $(PowerShellRoot)/tools/packaging -Force
$msiPath = '$(Build.StagingDirectory)\signedPackages\PowerShell-$(version)-win-${{ parameters.architecture }}.msi'
New-ExePackage -ProductVersion '$(version)' -MsiLocationPath $msiPath -ProductTargetArchitecture ${{ parameters.architecture }}
$exePath = Get-ChildItem '.\PowerShell-*.exe' | Select-Object -First 1 -ExpandProperty fullname
$enginePath = Join-Path -Path '$(System.ArtifactsDirectory)\unsignedEngine' -ChildPath engine.exe
# Expand Burn Engine so we can sign it.
Expand-ExePackageEngine -ExePath $exePath -EnginePath $enginePath
displayName: Create exe wrapper
- template: EsrpSign.yml@ComplianceRepo
parameters:
buildOutputPath: $(System.ArtifactsDirectory)\unsignedEngine
signOutputPath: $(System.ArtifactsDirectory)\signedEngine
certificateId: "$(AUTHENTICODE_CERT)"
pattern: |
**\*.exe
useMinimatch: true
shouldSign: $(SHOULD_SIGN)
displayName: Sign Burn Engine
alwaysCopy: true
- pwsh: |
cd '$(PowerShellRoot)'
Import-Module '$(PowerShellRoot)/build.psm1' -Force
Import-Module '$(PowerShellRoot)/tools/packaging' -Force
$exePath = Get-ChildItem '.\PowerShell-*.exe' | Select-Object -First 1 -ExpandProperty fullname
$enginePath = Join-Path -Path '$(System.ArtifactsDirectory)\signedEngine' -ChildPath engine.exe
$enginePath | Get-AuthenticodeSignature | out-string | Write-Verbose -verbose
Compress-ExePackageEngine -ExePath $exePath -EnginePath $enginePath
displayName: Re-attach the signed Burn engine in exe wrapper
- pwsh: |
cd '$(PowerShellRoot)'
Get-ChildItem '.\PowerShell-*.exe' | ForEach-Object {
$packagePath = $_.FullName
Write-Host "Uploading $packagePath"
Write-Host "##vso[artifact.upload containerfolder=signed;artifactname=signed]$packagePath"
}
displayName: Upload unsigned exe
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
displayName: 'Component Detection'
inputs:
sourceScanPath: '$(PowerShellRoot)\tools'
snapshotForceEnabled: true
- powershell: |
if ((Test-Path "\PowerShell")) {
Remove-Item -Path "\PowerShell" -Force -Recurse -Verbose
}
else {
Write-Verbose -Verbose -Message "No cleanup required."
}
if((Test-Path "${env:ProgramFiles(x86)}\WiX Toolset xcopy")) {
Write-Verbose -Verbose "Cleaning up Wix tools"
Remove-Item "${env:ProgramFiles(x86)}\WiX Toolset xcopy" -Recurse -Force
}
displayName: Clean up local Clone
condition: always()