Address PR feedback (#1826)
Co-authored-by: Sima Zhu <sizhu@microsoft.com> Co-authored-by: Sima Zhu <48036328+sima-zhu@users.noreply.github.com>
This commit is contained in:
parent
c9e02370fe
commit
d7924ce12f
11
eng/common/pipelines/templates/steps/set-default-branch.yml
Normal file
11
eng/common/pipelines/templates/steps/set-default-branch.yml
Normal file
@ -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'], '')
|
||||
@ -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 }}
|
||||
@ -26,4 +27,4 @@ steps:
|
||||
-branchReplaceRegex "${{ parameters.BranchReplaceRegex }}"
|
||||
-branchReplacementName ${{ parameters.BranchReplacementName }}
|
||||
-devOpsLogging: $true
|
||||
-checkLinkGuidance: ${{ parameters.CheckLinkGuidance }}
|
||||
-checkLinkGuidance: ${{ parameters.CheckLinkGuidance }}
|
||||
@ -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
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user