Sync eng/common directory with azure-sdk-tools repository for Tools PR https://github.com/Azure/azure-sdk-tools/pull/870 (#489)
This commit is contained in:
parent
44aa04cd88
commit
995d58d305
@ -2,16 +2,17 @@ parameters:
|
||||
Directory: 'not-specified'
|
||||
IgnoreLinksFile: "$(Build.SourcesDirectory)/eng/ignore-links.txt"
|
||||
|
||||
|
||||
steps:
|
||||
- task: PowerShell@2
|
||||
displayName: Link verification check
|
||||
inputs:
|
||||
pwsh: true
|
||||
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.Directory }}
|
||||
filePath: eng/common/scripts/Verify-Links.ps1
|
||||
arguments: >
|
||||
-urls $(dir -r -i *.md)
|
||||
-rootUrl "file://$(Build.SourcesDirectory)/${{ parameters.Directory }}"
|
||||
-recursive: $false
|
||||
-ignoreLinksFile ${{ parameters.IgnoreLinksFile }}
|
||||
- task: PowerShell@2
|
||||
displayName: Link verification check
|
||||
inputs:
|
||||
pwsh: true
|
||||
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.Directory }}
|
||||
filePath: eng/common/scripts/Verify-Links.ps1
|
||||
arguments: >
|
||||
-urls $(dir -r -i *.md)
|
||||
-rootUrl "file://$(Build.SourcesDirectory)/${{ parameters.Directory }}"
|
||||
-recursive: $false
|
||||
-ignoreLinksFile ${{ parameters.IgnoreLinksFile }}
|
||||
-branchReplaceRegex "($env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI.*/blob/)master(/.*)"
|
||||
-branchReplacementName $env:SYSTEM_PULLREQUEST_SOURCECOMMITID
|
||||
|
||||
@ -13,6 +13,10 @@ param (
|
||||
[string] $rootUrl = "",
|
||||
# list of http status codes count as broken links. Defaults to 400, 401, 404, SocketError.HostNotFound = 11001, SocketError.NoData = 11004
|
||||
[array] $errorStatusCodes = @(400, 401, 404, 11001, 11004),
|
||||
# regex to check if the link needs to be replaced
|
||||
[string] $branchReplaceRegex = "(https://github.com/.*/blob/)master(/.*)",
|
||||
# the substitute branch name or SHA commit
|
||||
[string] $branchReplacementName = "",
|
||||
# flag to allow checking against azure sdk link guidance.
|
||||
[bool] $checkLinkGuidance = $false
|
||||
)
|
||||
@ -183,6 +187,14 @@ function CheckLink ([System.Uri]$linkUri)
|
||||
return $linkValid
|
||||
}
|
||||
|
||||
function ReplaceGithubLink([string]$originLink) {
|
||||
if (!$branchReplacementName) {
|
||||
return $originLink
|
||||
}
|
||||
$ReplacementPattern = "`${1}$branchReplacementName`$2"
|
||||
return $originLink -replace $branchReplaceRegex, $ReplacementPattern
|
||||
}
|
||||
|
||||
function GetLinks([System.Uri]$pageUri)
|
||||
{
|
||||
if ($pageUri.Scheme.StartsWith("http")) {
|
||||
@ -259,6 +271,8 @@ while ($pageUrisToCheck.Count -ne 0)
|
||||
Write-Host "Found $($linkUris.Count) links on page $pageUri";
|
||||
|
||||
foreach ($linkUri in $linkUris) {
|
||||
$linkUri = ReplaceGithubLink $linkUri
|
||||
|
||||
$isLinkValid = CheckLink $linkUri
|
||||
if (!$isLinkValid) {
|
||||
$script:badLinks += $linkUri
|
||||
|
||||
Loading…
Reference in New Issue
Block a user