1
1
param (
2
2
[Parameter (Mandatory = $true )][string ] $InputPath , # Full path to directory where Symbols.NuGet packages to be checked are stored
3
3
[Parameter (Mandatory = $true )][string ] $ExtractPath , # Full path to directory where the packages will be extracted during validation
4
- [Parameter (Mandatory = $true )][string ] $GHRepoName , # GitHub name of the repo including the Org. E.g., dotnet/arcade
5
- [Parameter (Mandatory = $true )][string ] $GHCommit , # GitHub commit SHA used to build the packages
4
+ [Parameter (Mandatory = $false )][string ] $GHRepoName , # GitHub name of the repo including the Org. E.g., dotnet/arcade
5
+ [Parameter (Mandatory = $false )][string ] $GHCommit , # GitHub commit SHA used to build the packages
6
6
[Parameter (Mandatory = $true )][string ] $SourcelinkCliVersion # Version of SourceLink CLI to use
7
7
)
8
8
@@ -13,6 +13,12 @@ param(
13
13
# all files present in the repo at a specific commit point.
14
14
$global :RepoFiles = @ {}
15
15
16
+ # Maximum number of jobs to run in parallel
17
+ $MaxParallelJobs = 6
18
+
19
+ # Wait time between check for system load
20
+ $SecondsBetweenLoadChecks = 10
21
+
16
22
$ValidatePackage = {
17
23
param (
18
24
[string ] $PackagePath # Full path to a Symbols.NuGet package
@@ -22,8 +28,8 @@ $ValidatePackage = {
22
28
23
29
# Ensure input file exist
24
30
if (! (Test-Path $PackagePath )) {
25
- Write-PipelineTaskError " Input file does not exist: $PackagePath "
26
- ExitWithExitCode 1
31
+ Write-Host " Input file does not exist: $PackagePath "
32
+ return 1
27
33
}
28
34
29
35
# Extensions for which we'll look for SourceLink information
@@ -38,7 +44,7 @@ $ValidatePackage = {
38
44
39
45
Add-Type - AssemblyName System.IO.Compression.FileSystem
40
46
41
- [System.IO.Directory ]::CreateDirectory($ExtractPath );
47
+ [System.IO.Directory ]::CreateDirectory($ExtractPath ) | Out-Null
42
48
43
49
try {
44
50
$zip = [System.IO.Compression.ZipFile ]::OpenRead($PackagePath )
@@ -138,62 +144,86 @@ $ValidatePackage = {
138
144
139
145
if ($FailedFiles -eq 0 ) {
140
146
Write-Host " Passed."
147
+ return 0
141
148
}
142
149
else {
143
- Write-PipelineTaskError " $PackagePath has broken SourceLink links."
150
+ Write-Host " $PackagePath has broken SourceLink links."
151
+ return 1
144
152
}
145
153
}
146
154
147
155
function ValidateSourceLinkLinks {
148
- if (! ($GHRepoName -Match " ^[^\s\/]+/[^\s\/]+$" )) {
156
+ if ($GHRepoName -ne " " -and ! ($GHRepoName -Match " ^[^\s\/]+/[^\s\/]+$" )) {
149
157
if (! ($GHRepoName -Match " ^[^\s-]+-[^\s]+$" )) {
150
- Write-PipelineTaskError " GHRepoName should be in the format <org>/<repo> or <org>-<repo>"
158
+ Write-PipelineTaskError " GHRepoName should be in the format <org>/<repo> or <org>-<repo>. ' $GHRepoName ' "
151
159
ExitWithExitCode 1
152
160
}
153
161
else {
154
162
$GHRepoName = $GHRepoName -replace ' ^([^\s-]+)-([^\s]+)$' , ' $1/$2' ;
155
163
}
156
164
}
157
165
158
- if (! ($GHCommit -Match " ^[0-9a-fA-F]{40}$" )) {
159
- Write-PipelineTaskError " GHCommit should be a 40 chars hexadecimal string"
166
+ if ($GHCommit -ne " " -and ! ($GHCommit -Match " ^[0-9a-fA-F]{40}$" )) {
167
+ Write-PipelineTaskError " GHCommit should be a 40 chars hexadecimal string. ' $GHCommit ' "
160
168
ExitWithExitCode 1
161
169
}
162
170
163
- $RepoTreeURL = -Join (" http://api.github.com/repos/" , $GHRepoName , " /git/trees/" , $GHCommit , " ?recursive=1" )
164
- $CodeExtensions = @ (" .cs" , " .vb" , " .fs" , " .fsi" , " .fsx" , " .fsscript" )
171
+ if ($GHRepoName -ne " " -and $GHCommit -ne " " ) {
172
+ $RepoTreeURL = -Join (" http://api.github.com/repos/" , $GHRepoName , " /git/trees/" , $GHCommit , " ?recursive=1" )
173
+ $CodeExtensions = @ (" .cs" , " .vb" , " .fs" , " .fsi" , " .fsx" , " .fsscript" )
165
174
166
- try {
167
- # Retrieve the list of files in the repo at that particular commit point and store them in the RepoFiles hash
168
- $Data = Invoke-WebRequest $RepoTreeURL - UseBasicParsing | ConvertFrom-Json | Select-Object - ExpandProperty tree
175
+ try {
176
+ # Retrieve the list of files in the repo at that particular commit point and store them in the RepoFiles hash
177
+ $Data = Invoke-WebRequest $RepoTreeURL - UseBasicParsing | ConvertFrom-Json | Select-Object - ExpandProperty tree
169
178
170
- foreach ($file in $Data ) {
171
- $Extension = [System.IO.Path ]::GetExtension($file.path )
179
+ foreach ($file in $Data ) {
180
+ $Extension = [System.IO.Path ]::GetExtension($file.path )
172
181
173
- if ($CodeExtensions.Contains ($Extension )) {
174
- $RepoFiles [$file.path ] = 1
182
+ if ($CodeExtensions.Contains ($Extension )) {
183
+ $RepoFiles [$file.path ] = 1
184
+ }
175
185
}
176
186
}
187
+ catch {
188
+ Write-Host " Problems downloading the list of files from the repo. Url used: $RepoTreeURL . Execution will proceed without caching."
189
+ }
177
190
}
178
- catch {
179
- Write-PipelineTaskError " Problems downloading the list of files from the repo. Url used: $RepoTreeURL "
180
- Write-Host $_
181
- ExitWithExitCode 1
191
+ elseif ($GHRepoName -ne " " -or $GHCommit -ne " " ) {
192
+ Write-Host " For using the http caching mechanism both GHRepoName and GHCommit should be informed."
182
193
}
183
194
184
195
if (Test-Path $ExtractPath ) {
185
196
Remove-Item $ExtractPath - Force - Recurse - ErrorAction SilentlyContinue
186
197
}
187
198
188
199
# Process each NuGet package in parallel
189
- $Jobs = @ ()
190
200
Get-ChildItem " $InputPath \*.symbols.nupkg" |
191
201
ForEach-Object {
192
- $Jobs += Start-Job - ScriptBlock $ValidatePackage - ArgumentList $_.FullName
202
+ Start-Job - ScriptBlock $ValidatePackage - ArgumentList $_.FullName | Out-Null
203
+ $NumJobs = @ (Get-Job - State ' Running' ).Count
204
+
205
+ while ($NumJobs -ge $MaxParallelJobs ) {
206
+ Write-Host " There are $NumJobs validation jobs running right now. Waiting $SecondsBetweenLoadChecks seconds to check again."
207
+ sleep $SecondsBetweenLoadChecks
208
+ $NumJobs = @ (Get-Job - State ' Running' ).Count
209
+ }
210
+
211
+ foreach ($Job in @ (Get-Job - State ' Completed' )) {
212
+ Receive-Job - Id $Job.Id
213
+ Remove-Job - Id $Job.Id
214
+ }
193
215
}
194
216
217
+ $ValidationFailures = 0
195
218
foreach ($Job in $Jobs ) {
196
- Wait-Job - Id $Job.Id | Receive-Job
219
+ $jobResult = Wait-Job - Id $Job.Id | Receive-Job
220
+ if ($jobResult -ne " 0" ) {
221
+ $ValidationFailures ++
222
+ }
223
+ }
224
+ if ($ValidationFailures -gt 0 ) {
225
+ Write-PipelineTaskError " $ValidationFailures package(s) failed validation."
226
+ ExitWithExitCode 1
197
227
}
198
228
}
199
229
0 commit comments