Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools repository for Tools PR
Browse files Browse the repository at this point in the history
  • Loading branch information
azure-sdk committed Aug 20, 2020
1 parent 5bd1162 commit 29ce83f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
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
17 changes: 9 additions & 8 deletions eng/common/scripts/Verify-Resource-Ref.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

. (Join-Path $PSScriptRoot common.ps1)
Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser
$ymlfiles = Get-ChildItem $RepoRoot -recurse | Where-Object {$_ -like '*.yml'}
$affectedRepos = [System.Collections.ArrayList]::new()
$ymlfiles = Get-ChildItem $RepoRoot | Where-Object {$_ -like '*.yml'}
$affectedRepos = @()

foreach ($file in $ymlfiles)
{
Expand All @@ -20,7 +21,7 @@ foreach ($file in $ymlfiles)
if (-not ($repo.Contains("ref")))
{
$errorMessage = "File: ${file}, Repository: ${repoName}."
[void]$affectedRepos.Add($errorMessage)
$affectedRepos.Add($errorMessage)
}
}
}
Expand All @@ -29,14 +30,14 @@ foreach ($file in $ymlfiles)

if ($affectedRepos.Count -gt 0)
{
Write-Output "Ref not found in the following Repository Resources."
Write-Error "Ref not found in the following Repository Resources."
foreach ($errorMessage in $affectedRepos)
{
Write-Output "`t$errorMessage"
Write-Information $errorMessage
}
Write-Output "Please ensure you add a Ref: when using repository resources"
Write-Output "More Info at https://aka.ms/azsdk/engsys/tools-versioning"
Write-Information "Please ensure you add a Ref: when using repository resources"
Write-Information "More Info at https://aka.ms/azsdk/engsys/tools-versioning"
exit 1
}

Write-Output "All repository resources in yaml files reference a valid tag"
Write-Information "All repository resources in yaml files reference a valid tag"

0 comments on commit 29ce83f

Please sign in to comment.