Skip to content

Commit 3441543

Browse files
Sync eng/common directory with azure-sdk-tools for PR 10593 (Azure#41010)
* Improve link checking for github links Use locally cloned repos to check github links to avoid rate-limiting. * Add default clone path to the link checker template --------- Co-authored-by: Wes Haggard <[email protected]>
1 parent 9fe57d9 commit 3441543

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

eng/common/pipelines/templates/steps/verify-links.yml

+1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ steps:
3030
-branchReplacementName ${{ parameters.BranchReplacementName }}
3131
-devOpsLogging: $true
3232
-checkLinkGuidance: ${{ parameters.CheckLinkGuidance }}
33+
-localGithubClonedRoot "$(Pipeline.Workspace)"
3334
-inputCacheFile "https://azuresdkartifacts.blob.core.windows.net/verify-links-cache/verify-links-cache.txt"

eng/common/scripts/Verify-Links.ps1

+11-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ param (
7272
[string] $userAgent,
7373
[string] $inputCacheFile,
7474
[string] $outputCacheFile,
75+
[string] $localGithubClonedRoot = "",
7576
[string] $requestTimeoutSec = 15
7677
)
7778

@@ -80,6 +81,14 @@ Set-StrictMode -Version 3.0
8081
$ProgressPreference = "SilentlyContinue"; # Disable invoke-webrequest progress dialog
8182

8283
function ProcessLink([System.Uri]$linkUri) {
84+
# To help improve performance and rate limiting issues with github links we try to resolve them based on a local clone if one exists.
85+
if ($localGithubClonedRoot -and $linkUri -match '^https://github.com/Azure/(?<repo>[^/]+)/(?:blob|tree)/(main|.*_[^/]+|.*/v[^/]+)/(?<path>.*)$') {
86+
$localPath = Join-Path $localGithubClonedRoot $matches['repo'] $matches['path']
87+
if (Test-Path $localPath) {
88+
return $true
89+
}
90+
return ProcessStandardLink $linkUri
91+
}
8392
if ($linkUri -match '^https?://?github\.com/(?<account>)[^/]+/(?<repo>)[^/]+/wiki/.+') {
8493
# in an unauthenticated session, urls for missing pages will redirect to the wiki root
8594
return ProcessRedirectLink $linkUri -invalidStatusCodes 302
@@ -507,6 +516,7 @@ if ($inputCacheFile)
507516
$goodLinks = $cacheContent.Split("`n").Where({ $_.Trim() -ne "" -and !$_.StartsWith("#") })
508517

509518
foreach ($goodLink in $goodLinks) {
519+
$goodLink = $goodLink.Trim()
510520
$checkedLinks[$goodLink] = $true
511521
}
512522
}
@@ -587,7 +597,7 @@ try {
587597

588598
if ($outputCacheFile)
589599
{
590-
$goodLinks = $checkedLinks.Keys.Where({ "True" -eq $checkedLinks[$_].ToString() }) | Sort-Object
600+
$goodLinks = $checkedLinks.Keys.Where({ "True" -eq $checkedLinks[$_].ToString()}) | Sort-Object -Unique
591601

592602
Write-Host "Writing the list of validated links to $outputCacheFile"
593603
$goodLinks | Set-Content $outputCacheFile

0 commit comments

Comments
 (0)