Skip to content

Commit 3ba619d

Browse files
committed
Sync eng/common directory with azure-sdk-tools repository for Tools PR 895
1 parent 8c7babc commit 3ba619d

File tree

5 files changed

+62
-44
lines changed

5 files changed

+62
-44
lines changed

eng/common/TestResources/New-TestResources.ps1.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ It is passed as to the ARM
197197
template as 'testApplicationOid'
198198
199199
For more information on the relationship between AAD Applications and Service
200-
Principals see: https://docs.microsoft.com/en-us/azure/active-directory/develop/app-objects-and-service-principals
200+
Principals see: https://docs.microsoft.com/azure/active-directory/develop/app-objects-and-service-principals
201201
202202
```yaml
203203
Type: String
@@ -457,6 +457,3 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
457457
## NOTES
458458
459459
## RELATED LINKS
460-
461-
[Remove-TestResources.ps1]()
462-

eng/common/TestResources/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ New-MarkdownHelp -Command .\New-TestResources.ps1 -OutputFolder . -Force
125125

126126
PowerShell markdown documentation created with [platyPS][].
127127

128-
[New-TestResources.ps1]: ./New-TestResources.ps1.md
129-
[Remove-TestResources.ps1]: ./Remove-TestResources.ps1.md
128+
[New-TestResources.ps1]: https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/TestResources/New-TestResources.ps1.md
129+
[Remove-TestResources.ps1]: https://github.com/Azure/azure-sdk-tools/blob/master/eng/common/TestResources/Remove-TestResources.ps1.md
130130
[PowerShell]: https://github.com/PowerShell/PowerShell
131131
[PowerShellAz]: https://docs.microsoft.com/powershell/azure/install-az-ps
132132
[platyPS]: https://github.com/PowerShell/platyPS

eng/common/TestResources/Remove-TestResources.ps1.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,3 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
272272
## NOTES
273273
274274
## RELATED LINKS
275-
276-
[New-TestResources.ps1]()
277-
Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
parameters:
22
Directory: 'not-specified'
3-
IgnoreLinksFile: "$(Build.SourcesDirectory)/eng/ignore-links.txt"
4-
3+
IgnoreLinksFile: '$(Build.SourcesDirectory)/eng/ignore-links.txt'
4+
WorkingDirectory: '$(System.DefaultWorkingDirectory)'
5+
ScriptDirectory: 'eng/common/scripts'
6+
Recursive: $false
7+
CheckLinkGuidance: $true
8+
Urls: '(Get-ChildItem -Path ./ -Recurse -Include *.md)'
9+
BranchReplaceRegex: "^(${env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI}.*/(?:blob|tree)/)master(/.*)$"
10+
BranchReplacementName: "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}"
11+
512
steps:
6-
- task: PowerShell@2
7-
displayName: Link verification check
8-
inputs:
9-
pwsh: true
10-
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.Directory }}
11-
filePath: eng/common/scripts/Verify-Links.ps1
12-
arguments: >
13-
-urls $(dir -r -i *.md)
14-
-rootUrl "file://$(Build.SourcesDirectory)/${{ parameters.Directory }}"
15-
-recursive: $false
16-
-ignoreLinksFile ${{ parameters.IgnoreLinksFile }}
17-
-branchReplaceRegex "^($env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI.*/(?:blob|tree)/)master(/.*)$"
18-
-branchReplacementName $env:SYSTEM_PULLREQUEST_SOURCECOMMITID
19-
-devOpsLogging: $true
13+
- task: PowerShell@2
14+
displayName: Link verification check
15+
inputs:
16+
pwsh: true
17+
workingDirectory: '${{ parameters.WorkingDirectory }}/${{ parameters.Directory }}'
18+
filePath: ${{ parameters.ScriptDirectory }}/Verify-Links.ps1
19+
arguments: >
20+
-urls ${{ parameters.Urls }}
21+
-rootUrl "file://${{ parameters.WorkingDirectory }}/${{ parameters.Directory }}"
22+
-recursive: ${{ parameters.Recursive }}
23+
-ignoreLinksFile ${{ parameters.IgnoreLinksFile }}
24+
-branchReplaceRegex "${{ parameters.BranchReplaceRegex }}"
25+
-branchReplacementName ${{ parameters.BranchReplacementName }}
26+
-devOpsLogging: $true
27+
-checkLinkGuidance: ${{ parameters.CheckLinkGuidance }}

eng/common/scripts/Verify-Links.ps1

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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.
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.
33
[string[]] $urls,
44
# file that contains a set of links to ignore when verifying
55
[string] $ignoreLinksFile = "$PSScriptRoot/ignore-links.txt",
@@ -17,14 +17,14 @@ param (
1717
[string] $branchReplaceRegex = "^(https://github.com/.*/(?:blob|tree)/)master(/.*)$",
1818
# the substitute branch name or SHA commit
1919
[string] $branchReplacementName = "",
20-
# flag to allow checking against azure sdk link guidance.
20+
# flag to allow checking against azure sdk link guidance. Check link guidance here: https://aka.ms/azsdk/guideline/links
2121
[bool] $checkLinkGuidance = $false
2222
)
2323

2424
$ProgressPreference = "SilentlyContinue"; # Disable invoke-webrequest progress dialog
2525
# Regex of the locale keywords.
2626
$locale = "/en-us/"
27-
27+
$emptyLinkMessage = "There is at least one empty link in the page. Please replace with absolute link. Check here for more infomation: https://aka.ms/azsdk/guideline/links"
2828
function NormalizeUrl([string]$url){
2929
if (Test-Path $url) {
3030
$url = "file://" + (Resolve-Path $url).ToString();
@@ -85,16 +85,18 @@ function ResolveUri ([System.Uri]$referralUri, [string]$link)
8585
$linkUri = [System.Uri]$link;
8686
# Our link guidelines do not allow relative links so only resolve them when we are not
8787
# validating links against our link guidelines (i.e. !$checkLinkGuideance)
88-
if(!$checkLinkGuidance) {
89-
if (!$linkUri.IsAbsoluteUri) {
88+
if ($checkLinkGuidance -and !$linkUri.IsAbsoluteUri) {
89+
return $linkUri
90+
}
91+
92+
if (!$linkUri.IsAbsoluteUri) {
9093
# For rooted paths resolve from the baseUrl
91-
if ($link.StartsWith("/")) {
92-
Write-Verbose "rooturl = $rootUrl"
93-
$linkUri = new-object System.Uri([System.Uri]$rootUrl, ".$link");
94-
}
95-
else {
96-
$linkUri = new-object System.Uri($referralUri, $link);
97-
}
94+
if ($link.StartsWith("/")) {
95+
Write-Verbose "rooturl = $rootUrl"
96+
$linkUri = new-object System.Uri([System.Uri]$rootUrl, ".$link");
97+
}
98+
else {
99+
$linkUri = new-object System.Uri($referralUri, $link);
98100
}
99101
}
100102

@@ -134,6 +136,10 @@ function ParseLinks([string]$baseUri, [string]$htmlContent)
134136

135137
function CheckLink ([System.Uri]$linkUri)
136138
{
139+
if(!$linkUri.ToString().Trim()) {
140+
LogWarning "Found Empty link. Please use absolute link instead. Check here for more infomation: https://aka.ms/azsdk/guideline/links"
141+
return $false
142+
}
137143
if ($checkedLinks.ContainsKey($linkUri)) {
138144
if (!$checkedLinks[$linkUri]) {
139145
LogWarning "broken link $linkUri"
@@ -193,11 +199,19 @@ function CheckLink ([System.Uri]$linkUri)
193199
}
194200
}
195201

196-
# Check if link uri includes locale info.
197-
if ($checkLinkGuidance -and ($linkUri -match $locale)) {
198-
LogWarning "DO NOT include locale $locale information in links: $linkUri."
199-
$linkValid = $false
202+
if ($checkLinkGuidance) {
203+
# Check if the url is relative links, suppress the archor link validation.
204+
if (!$linkUri.IsAbsoluteUri -and !$linkUri.ToString().StartsWith("#")) {
205+
LogWarning "DO NOT use relative link $linkUri. Please use absolute link instead. Check here for more infomation: https://aka.ms/azsdk/guideline/links"
206+
$linkValid = $false
207+
}
208+
# Check if link uri includes locale info.
209+
if ($linkUri -match $locale) {
210+
LogWarning "DO NOT include locale $locale information in links: $linkUri. Check here for more information: https://aka.ms/azsdk/guideline/links"
211+
$linkValid = $false
212+
}
200213
}
214+
201215
$checkedLinks[$linkUri] = $linkValid
202216
return $linkValid
203217
}
@@ -270,7 +284,6 @@ $checkedPages = @{};
270284
$checkedLinks = @{};
271285
$badLinks = @{};
272286
$pageUrisToCheck = new-object System.Collections.Queue
273-
274287
foreach ($url in $urls) {
275288
$uri = NormalizeUrl $url
276289
$pageUrisToCheck.Enqueue($uri);
@@ -286,9 +299,12 @@ while ($pageUrisToCheck.Count -ne 0)
286299
Write-Host "Found $($linkUris.Count) links on page $pageUri";
287300
$badLinksPerPage = @();
288301
foreach ($linkUri in $linkUris) {
289-
$linkUri = ReplaceGithubLink $linkUri
290-
$isLinkValid = CheckLink $linkUri
302+
$replacedLink = ReplaceGithubLink $linkUri
303+
$isLinkValid = CheckLink $replacedLink
291304
if (!$isLinkValid -and !$badLinksPerPage.Contains($linkUri)) {
305+
if (!$linkUri.ToString().Trim()) {
306+
$linkUri = $emptyLinkMessage
307+
}
292308
$badLinksPerPage += $linkUri
293309
}
294310
if ($recursive -and $isLinkValid) {

0 commit comments

Comments
 (0)