11param (
22 [Parameter (Mandatory = $true )][string ] $InputPath , # Full path to directory where Symbols.NuGet packages to be checked are stored
33 [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
66 [Parameter (Mandatory = $true )][string ] $SourcelinkCliVersion # Version of SourceLink CLI to use
77)
88
@@ -13,6 +13,12 @@ param(
1313# all files present in the repo at a specific commit point.
1414$global :RepoFiles = @ {}
1515
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+
1622$ValidatePackage = {
1723 param (
1824 [string ] $PackagePath # Full path to a Symbols.NuGet package
@@ -22,8 +28,8 @@ $ValidatePackage = {
2228
2329 # Ensure input file exist
2430 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
2733 }
2834
2935 # Extensions for which we'll look for SourceLink information
@@ -38,7 +44,7 @@ $ValidatePackage = {
3844
3945 Add-Type - AssemblyName System.IO.Compression.FileSystem
4046
41- [System.IO.Directory ]::CreateDirectory($ExtractPath );
47+ [System.IO.Directory ]::CreateDirectory($ExtractPath ) | Out-Null
4248
4349 try {
4450 $zip = [System.IO.Compression.ZipFile ]::OpenRead($PackagePath )
@@ -138,62 +144,86 @@ $ValidatePackage = {
138144
139145 if ($FailedFiles -eq 0 ) {
140146 Write-Host " Passed."
147+ return 0
141148 }
142149 else {
143- Write-PipelineTaskError " $PackagePath has broken SourceLink links."
150+ Write-Host " $PackagePath has broken SourceLink links."
151+ return 1
144152 }
145153}
146154
147155function ValidateSourceLinkLinks {
148- if (! ($GHRepoName -Match " ^[^\s\/]+/[^\s\/]+$" )) {
156+ if ($GHRepoName -ne " " -and ! ($GHRepoName -Match " ^[^\s\/]+/[^\s\/]+$" )) {
149157 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 ' "
151159 ExitWithExitCode 1
152160 }
153161 else {
154162 $GHRepoName = $GHRepoName -replace ' ^([^\s-]+)-([^\s]+)$' , ' $1/$2' ;
155163 }
156164 }
157165
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 ' "
160168 ExitWithExitCode 1
161169 }
162170
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" )
165174
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
169178
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 )
172181
173- if ($CodeExtensions.Contains ($Extension )) {
174- $RepoFiles [$file.path ] = 1
182+ if ($CodeExtensions.Contains ($Extension )) {
183+ $RepoFiles [$file.path ] = 1
184+ }
175185 }
176186 }
187+ catch {
188+ Write-Host " Problems downloading the list of files from the repo. Url used: $RepoTreeURL . Execution will proceed without caching."
189+ }
177190 }
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."
182193 }
183194
184195 if (Test-Path $ExtractPath ) {
185196 Remove-Item $ExtractPath - Force - Recurse - ErrorAction SilentlyContinue
186197 }
187198
188199 # Process each NuGet package in parallel
189- $Jobs = @ ()
190200 Get-ChildItem " $InputPath \*.symbols.nupkg" |
191201 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+ }
193215 }
194216
217+ $ValidationFailures = 0
195218 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
197227 }
198228}
199229
0 commit comments