Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 2265 (Azure#25407)
Browse files Browse the repository at this point in the history
* Improve devops logging for link checker

* Update eng/common/scripts/Verify-Links.ps1

Co-authored-by: Wes Haggard <Wes.Haggard@microsoft.com>
Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>
  • Loading branch information
3 people authored and XiaofeiCao committed Nov 18, 2021
1 parent 918e6ef commit 57b036b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions eng/common/scripts/Verify-Links.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ function CheckLink ([System.Uri]$linkUri, $allowRetry=$true)

if ($statusCode -in $errorStatusCodes) {
if ($originalLinkUri -ne $linkUri) {
LogWarning "[$statusCode] broken link $originalLinkUri (resolved to $linkUri)"
LogError "[$statusCode] broken link $originalLinkUri (resolved to $linkUri)"
}
else {
LogWarning "[$statusCode] broken link $linkUri"
LogError "[$statusCode] broken link $linkUri"
}

$linkValid = $false
Expand Down Expand Up @@ -423,14 +423,17 @@ foreach ($url in $urls) {
$pageUrisToCheck.Enqueue($uri);
}

if ($devOpsLogging) {
Write-Host "##[group]Link checking details"
}
while ($pageUrisToCheck.Count -ne 0)
{
$pageUri = $pageUrisToCheck.Dequeue();
if ($checkedPages.ContainsKey($pageUri)) { continue }
$checkedPages[$pageUri] = $true;

$linkUris = GetLinks $pageUri
Write-Host "Found $($linkUris.Count) links on page $pageUri";
Write-Host "Checking $($linkUris.Count) links found on page $pageUri";
$badLinksPerPage = @();
foreach ($linkUri in $linkUris) {
$isLinkValid = CheckLink $linkUri
Expand All @@ -450,6 +453,9 @@ while ($pageUrisToCheck.Count -ne 0)
$badLinks[$pageUri] = $badLinksPerPage
}
}
if ($devOpsLogging) {
Write-Host "##[endgroup]"
}

if ($badLinks.Count -gt 0) {
Write-Host "Summary of broken links:"
Expand All @@ -464,7 +470,7 @@ foreach ($pageLink in $badLinks.Keys) {
$linksChecked = $checkedLinks.Count - $cachedLinksCount

if ($badLinks.Count -gt 0) {
LogError "Checked $linksChecked links with $($badLinks.Count) page(s) broken."
Write-Host "Checked $linksChecked links with $($badLinks.Count) broken link(s) found."
}
else {
Write-Host "Checked $linksChecked links. No broken links found."
Expand Down

0 comments on commit 57b036b

Please sign in to comment.