Skip to content

Commit 0db8f23

Browse files
azure-sdkweshaggardCopilot
authored
Sync eng/common directory with azure-sdk-tools for PR 10611 (Azure#50004)
* Allow links to use the checked out repo for validation * Update eng/common/scripts/Verify-Links.ps1 Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Wes Haggard <[email protected]> Co-authored-by: Wes Haggard <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent e5b8a70 commit 0db8f23

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ steps:
3030
-branchReplacementName ${{ parameters.BranchReplacementName }}
3131
-devOpsLogging: $true
3232
-checkLinkGuidance: ${{ parameters.CheckLinkGuidance }}
33-
-localGithubClonedRoot "$(Pipeline.Workspace)"
33+
-localBuildRepoName "$env:BUILD_REPOSITORY_NAME"
34+
-localBuildRepoPath $(Build.SourcesDirectory)
3435
-inputCacheFile "https://azuresdkartifacts.blob.core.windows.net/verify-links-cache/verify-links-cache.txt"

eng/common/scripts/Verify-Links.ps1

+24-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@
4545
.PARAMETER outputCacheFile
4646
Path to a file that the script will output all the validated links after running all checks.
4747
48+
.PARAMETER localGithubClonedRoot
49+
Path to the root of a local github clone. This is used to resolve links to local files in the repo instead of making web requests.
50+
51+
.PARAMETER localBuildRepoName
52+
The name of the repo that is being built. This is used to resolve links to local files in the repo instead of making web requests.
53+
54+
.PARAMETER localBuildRepoPath
55+
The path to the local build repo. This is used to resolve links to local files in the repo instead of making web requests.
56+
4857
.PARAMETER requestTimeoutSec
4958
The number of seconds before we timeout when sending an individual web request. Default is 15 seconds.
5059
@@ -73,7 +82,9 @@ param (
7382
[string] $inputCacheFile,
7483
[string] $outputCacheFile,
7584
[string] $localGithubClonedRoot = "",
76-
[string] $requestTimeoutSec = 15
85+
[string] $localBuildRepoName = "",
86+
[string] $localBuildRepoPath = "",
87+
[string] $requestTimeoutSec = 15
7788
)
7889

7990
Set-StrictMode -Version 3.0
@@ -82,8 +93,17 @@ $ProgressPreference = "SilentlyContinue"; # Disable invoke-webrequest progress d
8293

8394
function ProcessLink([System.Uri]$linkUri) {
8495
# 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']
96+
if (($localGithubClonedRoot -or $localBuildRepoName) -and $linkUri -match '^https://github.com/(?<org>Azure)/(?<repo>[^/]+)/(?:blob|tree)/(main|.*_[^/]+|.*/v[^/]+)/(?<path>.*)$') {
97+
98+
if ($localBuildRepoName -eq ($matches['org'] + "/" + $matches['repo'])) {
99+
# If the link is to the current repo, use the local build path
100+
$localPath = Join-Path $localBuildRepoPath $matches['path']
101+
}
102+
else {
103+
# Otherwise use the local github clone path
104+
$localPath = Join-Path $localGithubClonedRoot $matches['repo'] $matches['path']
105+
}
106+
87107
if (Test-Path $localPath) {
88108
return $true
89109
}
@@ -165,7 +185,7 @@ $emptyLinkMessage = "There is at least one empty link in the page. Please replac
165185
if (!$userAgent) {
166186
$userAgent = "Chrome/87.0.4280.88"
167187
}
168-
function NormalizeUrl([string]$url){
188+
function NormalizeUrl([string]$url) {
169189
if (Test-Path $url) {
170190
$url = "file://" + (Resolve-Path $url).ToString();
171191
}

0 commit comments

Comments
 (0)