Skip to content

Commit 3fdd648

Browse files
committed
Sync eng/common directory with azure-sdk-tools repository for Tools PR Azure/azure-sdk-tools#870
1 parent df06c7d commit 3fdd648

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ parameters:
22
Directory: 'not-specified'
33
IgnoreLinksFile: "$(Build.SourcesDirectory)/eng/ignore-links.txt"
44

5-
65
steps:
7-
- task: PowerShell@2
8-
displayName: Link verification check
9-
inputs:
10-
pwsh: true
11-
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.Directory }}
12-
filePath: eng/common/scripts/Verify-Links.ps1
13-
arguments: >
14-
-urls $(dir -r -i *.md)
15-
-rootUrl "file://$(Build.SourcesDirectory)/${{ parameters.Directory }}"
16-
-recursive: $false
17-
-ignoreLinksFile ${{ parameters.IgnoreLinksFile }}
6+
- task: PowerShell@2
7+
displayName: Link verification check
8+
inputs:
9+
pwsh: true
10+
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.Directory }}
11+
filePath: eng/common/scripts/Verify-Links.ps1
12+
arguments: >
13+
-urls $(dir -r -i *.md)
14+
-rootUrl "file://$(Build.SourcesDirectory)/${{ parameters.Directory }}"
15+
-recursive: $false
16+
-ignoreLinksFile ${{ parameters.IgnoreLinksFile }}
17+
-branchReplaceRegex "($env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI.*/blob/)master(/.*)"
18+
-branchReplacementName $env:SYSTEM_PULLREQUEST_SOURCECOMMITID

eng/common/scripts/Verify-Links.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ param (
1313
[string] $rootUrl = "",
1414
# list of http status codes count as broken links. Defaults to 400, 401, 404, SocketError.HostNotFound = 11001, SocketError.NoData = 11004
1515
[array] $errorStatusCodes = @(400, 401, 404, 11001, 11004),
16+
# regex to check if the link needs to be replaced
17+
[string] $branchReplaceRegex = "(https://github.com/.*/blob/)master(/.*)",
18+
# the substitute branch name or SHA commit
19+
[string] $branchReplacementName = "",
1620
# flag to allow checking against azure sdk link guidance.
1721
[bool] $checkLinkGuidance = $false
1822
)
@@ -183,6 +187,14 @@ function CheckLink ([System.Uri]$linkUri)
183187
return $linkValid
184188
}
185189

190+
function ReplaceGithubLink([string]$originLink) {
191+
if (!$branchReplacementName) {
192+
return $originLink
193+
}
194+
$ReplacementPattern = "`${1}$branchReplacementName`$2"
195+
return $originLink -replace $branchReplaceRegex, $ReplacementPattern
196+
}
197+
186198
function GetLinks([System.Uri]$pageUri)
187199
{
188200
if ($pageUri.Scheme.StartsWith("http")) {
@@ -259,6 +271,8 @@ while ($pageUrisToCheck.Count -ne 0)
259271
Write-Host "Found $($linkUris.Count) links on page $pageUri";
260272

261273
foreach ($linkUri in $linkUris) {
274+
$linkUri = ReplaceGithubLink $linkUri
275+
262276
$isLinkValid = CheckLink $linkUri
263277
if (!$isLinkValid) {
264278
$script:badLinks += $linkUri

0 commit comments

Comments
 (0)