Skip to content
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
11 changes: 11 additions & 0 deletions eng/common/pipelines/templates/steps/set-default-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
WorkingDirectory: '$(System.DefaultWorkingDirectory)'
RemoteRepo: 'origin'
steps:
- pwsh: |
$setDefaultBranch = (git remote show ${{ parameters.RemoteRepo }} | Out-String) -replace "(?ms).*HEAD branch: (\w+).*", '$1'
Write-Host "Setting DefaultBranch=$setDefaultBranch"
echo "##vso[task.setvariable variable=DefaultBranch]$setDefaultBranch"
displayName: "Setup Default Branch"
workingDirectory: ${{ parameters.workingDirectory }}
condition: eq(variables['DefaultBranch'], '')
5 changes: 3 additions & 2 deletions eng/common/pipelines/templates/steps/verify-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ parameters:
Recursive: $false
CheckLinkGuidance: $true
Urls: '(Get-ChildItem -Path ./ -Recurse -Include *.md)'
BranchReplaceRegex: "^(${env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI}.*/(?:blob|tree)/)master(/.*)$"
BranchReplaceRegex: "^(${env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI}.*/(?:blob|tree)/)$(DefaultBranch)(/.*)$"
BranchReplacementName: "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}"
Condition: succeeded() # If you want to run on failure for the link checker, set it to `Condition: succeededOrFailed()`.

steps:
- template: /eng/common/pipelines/templates/steps/set-default-branch.yml
- task: PowerShell@2
displayName: Link verification check
condition: ${{ parameters.Condition }}
Expand All @@ -26,4 +27,4 @@ steps:
-branchReplaceRegex "${{ parameters.BranchReplaceRegex }}"
-branchReplacementName ${{ parameters.BranchReplacementName }}
-devOpsLogging: $true
-checkLinkGuidance: ${{ parameters.CheckLinkGuidance }}
-checkLinkGuidance: ${{ parameters.CheckLinkGuidance }}
68 changes: 56 additions & 12 deletions eng/common/scripts/Verify-Links.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,69 @@
<#
.SYNOPSIS
Check broken links.

.DESCRIPTION
The Verify-Links.ps1 script will check whether the files contain any broken links.

.PARAMETER urls
Specify url list to verify links. Can either be a http address or a local file request. Local file paths support md and html files.

.PARAMETER ignoreLinksFile
Specifies the file that contains a set of links to ignore when verifying.

.PARAMETER devOpsLogging
Switch that will enable devops specific logging for warnings

.PARAMETER recursive
Check the links recurisvely based on recursivePattern.

.PARAMETER baseUrl
Recursively check links for all links verified that begin with this baseUrl, defaults to the folder the url is contained in.

.PARAMETER rootUrl
Path to the root of the site for resolving rooted relative links, defaults to host root for http and file directory for local files.

.PARAMETER errorStatusCodes
List of http status codes that count as broken links. Defaults to 400, 401, 404, SocketError.HostNotFound = 11001, SocketError.NoData = 11004.

.PARAMETER branchReplaceRegex
Regex to check if the link needs to be replaced. E.g. ^(https://github.com/.*/(?:blob|tree)/)master(/.*)$

.PARAMETER branchReplacementName
The substitute branch name or SHA commit.

.PARAMETER checkLinkGuidance
Flag to allow checking against azure sdk link guidance. Check link guidance here: https://aka.ms/azsdk/guideline/links.

.PARAMETER userAgent
UserAgent to be configured for web requests. Defaults to current Chrome version.

.INPUTS
None. No required inputs.

.OUTPUTS
None. Verify-Links.ps1 does not generate any output.

.EXAMPLE
PS> .\Verify-Links.ps1

.EXAMPLE
PS> .\Verify-Links.ps1 -urls C:\README.md

.EXAMPLE
PS> .\Verify-Links -urls C:\README.md -checkLinkGuidance $true
#>
param (
# url list to verify links. Can either be a http address or a local file request. Local file paths support md and html files.
[string[]] $urls,
# file that contains a set of links to ignore when verifying
[string] $ignoreLinksFile = "$PSScriptRoot/ignore-links.txt",
# switch that will enable devops specific logging for warnings
[switch] $devOpsLogging = $false,
# check the links recurisvely based on recursivePattern
[switch] $recursive = $true,
# recusiving check links for all links verified that begin with this baseUrl, defaults to the folder the url is contained in
[string] $baseUrl = "",
# path to the root of the site for resolving rooted relative links, defaults to host root for http and file directory for local files
[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|tree)/)master(/.*)$",
# the substitute branch name or SHA commit
[string] $branchReplaceRegex = "",
[string] $branchReplacementName = "",
# flag to allow checking against azure sdk link guidance. Check link guidance here: https://aka.ms/azsdk/guideline/links
[bool] $checkLinkGuidance = $false,
# UserAgent to be configured for web request. Default to current Chrome version.
[string] $userAgent
)

Expand Down