Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 870 #489

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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