-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathEsrpSign.yml
236 lines (213 loc) · 9.02 KB
/
EsrpSign.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
parameters:
- name: "buildOutputPath"
default: "$(Build.ArtifactStagingDirectory)\\build"
- name: "signOutputPath"
default: "$(Build.ArtifactStagingDirectory)\\signed"
- name: "certificateId"
default: "CP-230012"
- name: "pattern"
default: "*.dll,*.exe"
- name: "useMinimatch"
type: boolean
default: false
- name: "signingService"
default: "pwshSigning"
- name: "shouldSign"
default: "auto"
- name: OutputMode
type: string
default: Default
values:
- Default
- AlwaysCopy
- NeverCopy
- CopyIfSigned
- name: "alwaysCopy"
type: boolean
default: False
- name: "useCustomEsrpJson"
type: boolean
default: false
- name: "verifySignature"
type: boolean
default: false
- name: "pageHash"
type: boolean
default: true
- name: "displayName"
default: "ESRP Signing"
steps:
- task: UseDotNet@2
displayName: '${{ parameters.displayName }} - Install .NET Core sdk 2.x'
inputs:
version: 3.x
- pwsh: |
Write-Verbose -Verbose "buildOutputPath = '${{ parameters.buildOutputPath }}'"
Write-Verbose -Verbose "signOutputPath = '${{ parameters.signOutputPath }}'"
Write-Verbose -Verbose "certificateId = '${{ parameters.certificateId }}'"
Write-Verbose -Verbose "pattern = '${{ parameters.pattern }}'"
Write-Verbose -Verbose "useMinimatch = '${{ parameters.useMinimatch }}'"
Write-Verbose -Verbose "signingService = '${{ parameters.signingService }}'"
Write-Verbose -Verbose "shouldSign = '${{ parameters.shouldSign }}'"
Write-Verbose -Verbose "alwaysCopy = '${{ parameters.alwaysCopy }}'"
Write-Verbose -Verbose "outputMode = '${env:OUTPUT_MODE}'"
Write-Verbose -Verbose "useCustomEsrpJson = '${{ parameters.useCustomEsrpJson }}'"
Write-Verbose -Verbose "verifySignature = '${{ parameters.verifySignature }}'"
Write-Verbose -Verbose "pageHash = '${{ parameters.pageHash }}'"
if (('${{ parameters.useCustomEsrpJson }}' -ne 'false') -and ('${{ parameters.certificateId }}' -ne ''))
{
throw "Only one of useCustomEsrpJson and certificateId must be set!"
}
$certId = '${{ parameters.certificateId }}'
$vstsCommandString = "vso[task.setvariable variable=ESRP_TEMPLATE_CERT_ID]$certId"
Write-Verbose -Message ("sending " + $vstsCommandString) -Verbose
Write-Host "##$vstsCommandString"
[string] $VariableName = "EsrpJson"
$vstsCommandString = "vso[task.setvariable variable=$VariableName][]"
Write-Verbose -Message ("sending " + $vstsCommandString) -Verbose
Write-Host "##$vstsCommandString"
$usePgp = $certId -like '*pgp'
$vstsCommandString = "vso[task.setvariable variable=ESRP_TEMPLATE_USE_PGP]$usePgp"
Write-Verbose -Message ("sending " + $vstsCommandString) -Verbose
Write-Host "##$vstsCommandString"
if($env:ALWAYS_COPY -ne 'False') {
Write-Warning "AlwaysCopy is replaced by OutputMode!"
}
if($env:OUTPUT_MODE -ne 'Default' -and $env:ALWAYS_COPY -ne 'False' ) {
throw "Only one of OutputMode and AlwaysCopy can be set!"
} elseif ($env:ALWAYS_COPY -ne 'False') {
$effectiveOutputMode = 'AlwaysCopy'
} elseif ($env:OUTPUT_MODE -ne 'Default') {
$effectiveOutputMode = $env:OUTPUT_MODE
} else {
# Default
$effectiveOutputMode = 'CopyIfSigned'
}
$vstsCommandString = "vso[task.setvariable variable=ESRP_TEMPLATE_COPY_MODE]$effectiveOutputMode"
Write-Verbose -Message ("sending " + $vstsCommandString) -Verbose
Write-Host "##$vstsCommandString"
displayName: ${{ parameters.displayName }} - Log parameters
env:
ALWAYS_COPY: ${{ parameters.alwaysCopy }}
OUTPUT_MODE: ${{ parameters.OutputMode }}
- pwsh: |
if ('${{ parameters.shouldSign }}' -eq 'auto') {
Write-Verbose -Verbose -Message 'calculating shouldsign'
$shouldSign = $env:BUILD_REASON -eq 'Manual' -and $env:SKIPSIGNING -ne 'True' -and $env:SIGNINGSERVER -ne ''
}
elseif ('${{ parameters.shouldSign }}' -eq 'false') {
$shouldSign = $false
}
else {
$shouldSign = $true
}
$vstsCommandString = "vso[task.setvariable variable=ESRP_TEMPLATE_SHOULD_SIGN]$shouldSign"
Write-Verbose -Message ("sending " + $vstsCommandString) -Verbose
Write-Host "##$vstsCommandString"
displayName: ${{ parameters.displayName }} - Set ESRP_TEMPLATE_SHOULD_SIGN
- template: template-compliance/authenticode-sign.yml
parameters:
buildOutputPath: ${{ parameters.buildOutputPath }}
signOutputPath: ${{ parameters.signOutputPath }}
pattern: ${{ parameters.pattern }}
certificateId: ${{ parameters.certificateId }}
verifySignature: ${{ parameters.verifySignature }}
pageHash: ${{ parameters.pageHash }}
displayName: ${{ parameters.displayName }}
- template: template-compliance/nuget-sign.yml
parameters:
buildOutputPath: ${{ parameters.buildOutputPath }}
signOutputPath: ${{ parameters.signOutputPath }}
pattern: ${{ parameters.pattern }}
certificateId: ${{ parameters.certificateId }}
verifySignature: ${{ parameters.verifySignature }}
displayName: ${{ parameters.displayName }}
- template: template-compliance/pgp-sign.yml
parameters:
signOutputPath: ${{ parameters.signOutputPath }}
pattern: ${{ parameters.pattern }}
certificateId: ${{ parameters.certificateId }}
displayName: ${{ parameters.displayName }}
- template: template-compliance/macOS-sign.yml
parameters:
signOutputPath: ${{ parameters.signOutputPath }}
pattern: ${{ parameters.pattern }}
certificateId: ${{ parameters.certificateId }}
displayName: ${{ parameters.displayName }}
- template: template-compliance/strongname-sign.yml
parameters:
signOutputPath: ${{ parameters.signOutputPath }}
pattern: ${{ parameters.pattern }}
certificateId: ${{ parameters.certificateId }}
displayName: ${{ parameters.displayName }}
- ${{ if eq(parameters.useCustomEsrpJson, 'true') }}:
- template: template-compliance/custom-sign.yml
parameters:
signOutputPath: ${{ parameters.signOutputPath }}
displayName: ${{ parameters.displayName }}
- pwsh: |
if(${env:EsrpJson} -eq '[]') {
throw "No Json generated, exiting! Update template to support ${{ parameters.certificateId }}"
}
Write-Verbose -Verbose "EsrpJson = '${env:EsrpJson}'"
displayName: ${{ parameters.displayName }} - Log Json
- pwsh: |
Write-Verbose "BUILD_OUTPUT_PATH- ${{ parameters.buildOutputPath }}" -Verbose
Write-Verbose "SIGNED_OUTPUT_PATH- ${{ parameters.signOutputPath }}" -Verbose
$mode = $env:ESRP_TEMPLATE_COPY_MODE
if(!(Test-Path '${{ parameters.signOutputPath }}'))
{
if($mode -eq 'NeverCopy') {
throw "Output path does not exist and copy mode is NeverCopy, exiting!"
}
Write-Verbose "Creating SIGNED_OUTPUT_PATH- ${{ parameters.signOutputPath }}" -Verbose
$null = New-Item -Path '${{ parameters.signOutputPath }}' -ItemType Directory -force
}
if($mode -eq 'AlwaysCopy' -or ($mode -eq 'CopyIfSigned' -and $env:ESRP_TEMPLATE_SHOULD_SIGN -eq $true)) {
Write-Verbose "Copying files to SIGNED_OUTPUT_PATH- ${{ parameters.signOutputPath }} because mode is $mode" -Verbose
Copy-Item -Path ${{ parameters.buildOutputPath }}\* -Dest ${{ parameters.signOutputPath }}\ -Recurse -Force -Verbose
} else {
Write-Verbose "Not copying files to SIGNED_OUTPUT_PATH- ${{ parameters.signOutputPath }} because mode is $mode" -Verbose
}
displayName: ${{ parameters.displayName }} - Prepare signed output directory
timeoutInMinutes: 10
- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1
displayName: ${{ parameters.displayName }} - Sign files
inputs:
ConnectedServiceName: ${{ parameters.signingService }}
FolderPath: '${{ parameters.signOutputPath }}'
signConfigType: inlineSignParams
inlineOperation: $(EsrpJson)
Pattern: ${{ parameters.pattern }}
UseMinimatch: ${{ parameters.useMinimatch }}
condition: |
and(succeeded(), eq(variables['ESRP_TEMPLATE_SHOULD_SIGN'], 'True'))
timeoutInMinutes: 30
- pwsh: |
$file = Get-ChildItem -Path "${{ parameters.signOutputPath }}\codesignsummary-*.md" -File
$fileName = $file.Name
$retryCount = 0
$maxTries = 5
while($retryCount -lt $maxTries)
{
try {
Move-Item -Path "${{ parameters.signOutputPath }}\$fileName" -Dest "$(Agent.TempDirectory)\$fileName" -Force -ErrorAction Stop
Write-Verbose "Moved ${{ parameters.signOutputPath }}\$fileName" -Verbose
Write-Host "##vso[artifact.upload containerfolder=signingReport;artifactname=signingReport]$(Agent.TempDirectory)\$fileName"
}
catch {
$retryCount++
if($retryCount -ge $maxTries)
{
throw
}
Write-Verbose -message "Failed to move ${{ parameters.signOutputPath }}\$fileName, will retry. The error is:" -Verbose
Get-Error $_ -ErrorAction Ignore
Start-Sleep -Seconds ($retryCount * 5)
continue
}
break
}
displayName: ${{ parameters.displayName }} - Upload codesign summary
condition: and(succeeded(), eq(variables['ESRP_TEMPLATE_SHOULD_SIGN'], 'True'))
timeoutInMinutes: 10