Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 51 additions & 25 deletions eng/common/post-build/sourcelink-validation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ $global:RepoFiles = @{}
# Maximum number of jobs to run in parallel
$MaxParallelJobs = 16

$MaxRetry = 5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This variable could be plural since it represents a count of things.


# Wait time between check for system load
$SecondsBetweenLoadChecks = 10

Expand All @@ -29,7 +31,10 @@ $ValidatePackage = {
# Ensure input file exist
if (!(Test-Path $PackagePath)) {
Write-Host "Input file does not exist: $PackagePath"
return 1
return [pscustomobject]@{
result = 1
packagePath = $PackagePath
Comment thread
MattGal marked this conversation as resolved.
}
}

# Extensions for which we'll look for SourceLink information
Expand Down Expand Up @@ -59,7 +64,10 @@ $ValidatePackage = {

# We ignore resource DLLs
if ($FileName.EndsWith('.resources.dll')) {
return
return [pscustomobject]@{
result = 0
packagePath = $PackagePath
}
}

[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, $TargetFile, $true)
Expand Down Expand Up @@ -91,36 +99,49 @@ $ValidatePackage = {
$Status = 200
$Cache = $using:RepoFiles

if ( !($Cache.ContainsKey($FilePath)) ) {
try {
$Uri = $Link -as [System.URI]

# Only GitHub links are valid
if ($Uri.AbsoluteURI -ne $null -and ($Uri.Host -match 'github' -or $Uri.Host -match 'githubusercontent')) {
$Status = (Invoke-WebRequest -Uri $Link -UseBasicParsing -Method HEAD -TimeoutSec 5).StatusCode
$totalRetries = 0

while ($totalRetries -lt $using:MaxRetry) {
if ( !($Cache.ContainsKey($FilePath)) ) {
try {
$Uri = $Link -as [System.URI]

# Only GitHub links are valid
if ($Uri.AbsoluteURI -ne $null -and ($Uri.Host -match 'github' -or $Uri.Host -match 'githubusercontent')) {
$Status = (Invoke-WebRequest -Uri $Link -UseBasicParsing -Method HEAD -TimeoutSec 5).StatusCode
}
else {
$Status = 0
Comment thread
MattGal marked this conversation as resolved.
}
}
else {
catch {
write-host $_
$Status = 0
}
}
catch {
write-host $_
$Status = 0
}
}

if ($Status -ne 200) {
if ($NumFailedLinks -eq 0) {
if ($FailedFiles.Value -eq 0) {
Write-Host
if ($Status -ne 200) {
if ($totalRetries -lt $using:MaxRetry)
{
$totalRetries++
Comment thread
MattGal marked this conversation as resolved.
Outdated
}
else {
if ($NumFailedLinks -eq 0) {
if ($FailedFiles.Value -eq 0) {
Write-Host
}

Write-Host "`tFile $RealPath has broken links:"
}

Write-Host "`t`tFailed to retrieve $Link"

$NumFailedLinks++
}

Write-Host "`tFile $RealPath has broken links:"
}

Write-Host "`t`tFailed to retrieve $Link"

$NumFailedLinks++
else {
break
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not touched in this PR, but looking down (~162?) there's a catch-all catch; could that log the exception it hits?

}
}
}
Expand Down Expand Up @@ -220,6 +241,7 @@ function ValidateSourceLinkLinks {
# Process each NuGet package in parallel
Get-ChildItem "$InputPath\*.symbols.nupkg" |
ForEach-Object {
Write-Host "Starting $($_.FullName)"
Start-Job -ScriptBlock $ValidatePackage -ArgumentList $_.FullName | Out-Null
$NumJobs = @(Get-Job -State 'Running').Count

Expand Down Expand Up @@ -267,6 +289,10 @@ function InstallSourcelinkCli {
try {
InstallSourcelinkCli

foreach ($Job in @(Get-Job)) {
Remove-Job -Id $Job.Id
}

ValidateSourceLinkLinks
}
catch {
Expand Down
21 changes: 12 additions & 9 deletions eng/common/post-build/symbols-validation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,27 @@ $CountMissingSymbols = {
elseif (Test-Path $SymbolPath) {
return 'Module'
}
elseif ($output.Contains("503 Service Unavailable")) {
# If we got a 503 error, we should retry.
else
{
$totalRetries++
}
else {
return $null
}
}

return $null
}

$FileGuid = New-Guid
$ExpandedSymbolsPath = Join-Path -Path $SymbolsPath -ChildPath $FileGuid

$SymbolsOnMSDL = & $FirstMatchingSymbolDescriptionOrDefault `
-FullPath $FileName `
-TargetServerParam '--microsoft-symbol-server' `
-SymbolsPath $SymbolsPath `
-SymbolsPath "$ExpandedSymbolsPath-msdl" `
-WindowsPdbVerificationParam $WindowsPdbVerificationParam
$SymbolsOnSymWeb = & $FirstMatchingSymbolDescriptionOrDefault `
-FullPath $FileName `
-TargetServerParam '--internal-server' `
-SymbolsPath $SymbolsPath `
-SymbolsPath "$ExpandedSymbolsPath-symweb" `
-WindowsPdbVerificationParam $WindowsPdbVerificationParam

Write-Host -NoNewLine "`t Checking file " $FileName "... "
Expand Down Expand Up @@ -217,6 +217,7 @@ function CheckSymbolsAvailable {
Remove-Item $ExtractPath -Force -Recurse -ErrorAction SilentlyContinue
}

$TotalPackages = 0
$TotalFailures = 0
$DupedSymbols = 0

Expand All @@ -239,6 +240,8 @@ function CheckSymbolsAvailable {
return
}

$TotalPackages++

Start-Job -ScriptBlock $CountMissingSymbols -ArgumentList @($FullName,$WindowsPdbVerificationParam) | Out-Null

$NumJobs = @(Get-Job -State 'Running').Count
Expand All @@ -264,11 +267,11 @@ function CheckSymbolsAvailable {

if ($TotalFailures -gt 0 -or $DupedSymbols -gt 0) {
if ($TotalFailures -gt 0) {
Write-PipelineTelemetryError -Category 'CheckSymbols' -Message "Symbols missing for $TotalFailures packages"
Write-PipelineTelemetryError -Category 'CheckSymbols' -Message "Symbols missing for $TotalFailures/$TotalPackages packages"
}

if ($DupedSymbols -gt 0) {
Write-PipelineTelemetryError -Category 'CheckSymbols' -Message "$DupedSymbols packages had duplicated symbol files"
Write-PipelineTelemetryError -Category 'CheckSymbols' -Message "$DupedSymbols/$TotalPackages packages had duplicated symbol files and could not be extracted"
}

ExitWithExitCode 1
Expand Down