Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools repository for Tools PR
Browse files Browse the repository at this point in the history
  • Loading branch information
azure-sdk committed Aug 20, 2020
1 parent 44aa04c commit 995d58d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
25 changes: 13 additions & 12 deletions eng/common/pipelines/templates/steps/verify-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions eng/common/scripts/Verify-Links.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 995d58d

Please sign in to comment.