Skip to content

Commit 83b93ec

Browse files
Sync eng/common directory with azure-sdk-tools for PR 10593 (#34268)
Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#10593 See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow) --------- Co-authored-by: Wes Haggard <[email protected]>
1 parent 9a75be2 commit 83b93ec

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 1 deletion
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)