Skip to content

Commit a35bf66

Browse files
azure-sdksima-zhu
andauthored
Address PR feedback (Azure#19738)
Co-authored-by: Sima Zhu <[email protected]>
1 parent b25e4ce commit a35bf66

File tree

3 files changed

+70
-14
lines changed

3 files changed

+70
-14
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
WorkingDirectory: '$(System.DefaultWorkingDirectory)'
3+
RemoteRepo: 'origin'
4+
steps:
5+
- pwsh: |
6+
$setDefaultBranch = (git remote show ${{ parameters.RemoteRepo }} | Out-String) -replace "(?ms).*HEAD branch: (\w+).*", '$1'
7+
Write-Host "Setting DefaultBranch=$setDefaultBranch"
8+
echo "##vso[task.setvariable variable=DefaultBranch]$setDefaultBranch"
9+
displayName: "Setup Default Branch"
10+
workingDirectory: ${{ parameters.workingDirectory }}
11+
condition: eq(variables['DefaultBranch'], '')

eng/common/pipelines/templates/steps/verify-links.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ parameters:
66
Recursive: $false
77
CheckLinkGuidance: $true
88
Urls: '(Get-ChildItem -Path ./ -Recurse -Include *.md)'
9-
BranchReplaceRegex: "^(${env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI}.*/(?:blob|tree)/)master(/.*)$"
9+
BranchReplaceRegex: "^(${env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI}.*/(?:blob|tree)/)$(DefaultBranch)(/.*)$"
1010
BranchReplacementName: "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}"
1111
Condition: succeeded() # If you want to run on failure for the link checker, set it to `Condition: succeededOrFailed()`.
1212

1313
steps:
14+
- template: /eng/common/pipelines/templates/steps/set-default-branch.yml
1415
- task: PowerShell@2
1516
displayName: Link verification check
1617
condition: ${{ parameters.Condition }}
@@ -26,4 +27,4 @@ steps:
2627
-branchReplaceRegex "${{ parameters.BranchReplaceRegex }}"
2728
-branchReplacementName ${{ parameters.BranchReplacementName }}
2829
-devOpsLogging: $true
29-
-checkLinkGuidance: ${{ parameters.CheckLinkGuidance }}
30+
-checkLinkGuidance: ${{ parameters.CheckLinkGuidance }}

eng/common/scripts/Verify-Links.ps1

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,69 @@
1+
<#
2+
.SYNOPSIS
3+
Check broken links.
4+
5+
.DESCRIPTION
6+
The Verify-Links.ps1 script will check whether the files contain any broken links.
7+
8+
.PARAMETER urls
9+
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.
10+
11+
.PARAMETER ignoreLinksFile
12+
Specifies the file that contains a set of links to ignore when verifying.
13+
14+
.PARAMETER devOpsLogging
15+
Switch that will enable devops specific logging for warnings
16+
17+
.PARAMETER recursive
18+
Check the links recurisvely based on recursivePattern.
19+
20+
.PARAMETER baseUrl
21+
Recursively check links for all links verified that begin with this baseUrl, defaults to the folder the url is contained in.
22+
23+
.PARAMETER rootUrl
24+
Path to the root of the site for resolving rooted relative links, defaults to host root for http and file directory for local files.
25+
26+
.PARAMETER errorStatusCodes
27+
List of http status codes that count as broken links. Defaults to 400, 401, 404, SocketError.HostNotFound = 11001, SocketError.NoData = 11004.
28+
29+
.PARAMETER branchReplaceRegex
30+
Regex to check if the link needs to be replaced. E.g. ^(https://github.com/.*/(?:blob|tree)/)master(/.*)$
31+
32+
.PARAMETER branchReplacementName
33+
The substitute branch name or SHA commit.
34+
35+
.PARAMETER checkLinkGuidance
36+
Flag to allow checking against azure sdk link guidance. Check link guidance here: https://aka.ms/azsdk/guideline/links.
37+
38+
.PARAMETER userAgent
39+
UserAgent to be configured for web requests. Defaults to current Chrome version.
40+
41+
.INPUTS
42+
None. No required inputs.
43+
44+
.OUTPUTS
45+
None. Verify-Links.ps1 does not generate any output.
46+
47+
.EXAMPLE
48+
PS> .\Verify-Links.ps1
49+
50+
.EXAMPLE
51+
PS> .\Verify-Links.ps1 -urls C:\README.md
52+
53+
.EXAMPLE
54+
PS> .\Verify-Links -urls C:\README.md -checkLinkGuidance $true
55+
#>
156
param (
2-
# url list to verify links. Can either be a http address or a local file request. Local file paths support md and html files.
357
[string[]] $urls,
4-
# file that contains a set of links to ignore when verifying
558
[string] $ignoreLinksFile = "$PSScriptRoot/ignore-links.txt",
6-
# switch that will enable devops specific logging for warnings
759
[switch] $devOpsLogging = $false,
8-
# check the links recurisvely based on recursivePattern
960
[switch] $recursive = $true,
10-
# recusiving check links for all links verified that begin with this baseUrl, defaults to the folder the url is contained in
1161
[string] $baseUrl = "",
12-
# path to the root of the site for resolving rooted relative links, defaults to host root for http and file directory for local files
1362
[string] $rootUrl = "",
14-
# list of http status codes count as broken links. Defaults to 400, 401, 404, SocketError.HostNotFound = 11001, SocketError.NoData = 11004
1563
[array] $errorStatusCodes = @(400, 401, 404, 11001, 11004),
16-
# regex to check if the link needs to be replaced
17-
[string] $branchReplaceRegex = "^(https://github.com/.*/(?:blob|tree)/)master(/.*)$",
18-
# the substitute branch name or SHA commit
64+
[string] $branchReplaceRegex = "",
1965
[string] $branchReplacementName = "",
20-
# flag to allow checking against azure sdk link guidance. Check link guidance here: https://aka.ms/azsdk/guideline/links
2166
[bool] $checkLinkGuidance = $false,
22-
# UserAgent to be configured for web request. Default to current Chrome version.
2367
[string] $userAgent
2468
)
2569

0 commit comments

Comments
 (0)