Skip to content

Commit a2f8838

Browse files
Sync eng/common directory with azure-sdk-tools for PR 3510 (Azure#18491)
* Update verify-readme to take a single or multiple paths * chance ScanPaths to a comma delimited list and coalesce ScanPath/ScanPaths into a single variable for the script * VS Code was nice enough to add an extra single quote when adding a quote to the end of the line' * Capture ScanPaths.Split into an array so we don't have to call Split again Co-authored-by: James Suplizio <jasupliz@microsoft.com>
1 parent 9c52fb6 commit a2f8838

File tree

2 files changed

+109
-16
lines changed

2 files changed

+109
-16
lines changed
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
parameters:
2-
ScanPath: $(Build.SourcesDirectory)
3-
RepoRoot: $(Build.SourcesDirectory)
4-
SettingsPath: '$(Build.SourcesDirectory)/eng/.docsettings.yml'
5-
DocWardenVersion : '0.7.2'
2+
- name: ScanPath
3+
type: string
4+
default: ''
5+
# Where ScanPath takes a single path, ScanPaths takes a comma separated list of paths to scan
6+
- name: ScanPaths
7+
type: string
8+
default: ''
9+
- name: RepoRoot
10+
type: string
11+
default: $(Build.SourcesDirectory)
12+
- name: SettingsPath
13+
type: string
14+
default: '$(Build.SourcesDirectory)/eng/.docsettings.yml'
15+
- name: DocWardenVersion
16+
type: string
17+
default: ''
618

719
steps:
820
- task: PowerShell@2
921
displayName: "Verify Readmes"
1022
inputs:
1123
filePath: "eng/common/scripts/Verify-Readme.ps1"
1224
arguments: >
13-
-DocWardenVersion ${{ parameters.DocWardenVersion }}
14-
-ScanPath ${{ parameters.ScanPath }}
25+
-DocWardenVersion '${{ parameters.DocWardenVersion }}'
26+
-ScanPaths '${{ coalesce(parameters.ScanPath, parameters.ScanPaths) }}'
1527
-RepoRoot ${{ parameters.RepoRoot }}
1628
-SettingsPath ${{ parameters.SettingsPath }}
1729
pwsh: true
Lines changed: 91 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,105 @@
11
# Wrapper Script for Readme Verification
22
[CmdletBinding()]
33
param (
4-
[Parameter(Mandatory = $true)]
4+
[Parameter(Mandatory = $false)]
55
[string]$DocWardenVersion,
6-
[Parameter(Mandatory = $true)]
7-
[string]$ScanPath,
86
[string]$RepoRoot,
7+
[string]$ScanPaths,
98
[Parameter(Mandatory = $true)]
109
[string]$SettingsPath
1110
)
11+
. (Join-Path $PSScriptRoot common.ps1)
12+
$DefaultDocWardenVersion = "0.7.2"
13+
$script:FoundError = $false
14+
15+
function Test-Readme-Files {
16+
param(
17+
[string]$SettingsPath,
18+
[string]$ScanPath,
19+
[string]$RepoRoot)
20+
21+
Write-Host "Scanning..."
22+
23+
if ($RepoRoot)
24+
{
25+
Write-Host "ward scan -d $ScanPath -u $RepoRoot -c $SettingsPath"
26+
ward scan -d $ScanPath -u $RepoRoot -c $SettingsPath
27+
}
28+
else
29+
{
30+
Write-Host "ward scan -d $ScanPath -c $SettingsPath"
31+
ward scan -d $ScanPath -c $SettingsPath
32+
}
33+
# ward scan is what returns the non-zero exit code on failure.
34+
# Since it's being called from a function, that error needs to
35+
# be propagated back so the script can exit appropriately
36+
if ($LASTEXITCODE -ne 0) {
37+
$script:FoundError = $true
38+
}
39+
}
40+
41+
# Verify all of the inputs before running anything
42+
if ([String]::IsNullOrWhiteSpace($DocWardenVersion)) {
43+
$DocWardenVersion = $DefaultDocWardenVersion
44+
}
45+
46+
# verify the doc settings file exists
47+
if (!(Test-Path -Path $SettingsPath -PathType leaf)) {
48+
LogError "Setting file, $SettingsPath, does not exist"
49+
$script:FoundError = $true
50+
}
51+
52+
$scanPathsArray = @()
1253

54+
# Verify that either ScanPath or ScanPaths were set but not both or neither
55+
if ([String]::IsNullOrWhiteSpace($ScanPaths)) {
56+
LogError "ScanPaths cannot be empty."
57+
} else {
58+
$scanPathsArray = $ScanPaths.Split(',')
59+
foreach ($path in $scanPathsArray) {
60+
if (!(Test-Path -Path $path -PathType Container)) {
61+
LogError "path, $path, doesn't exist or isn't a directory"
62+
$script:FoundError = $true
63+
}
64+
}
65+
}
66+
67+
# Exit out now if there were any argument issues
68+
if ($script:FoundError) {
69+
LogError "There were argument failures, please see above for specifics"
70+
exit 1
71+
}
72+
73+
# Echo back the settings
74+
Write-Host "DocWardenVersion=$DocWardenVersion"
75+
Write-Host "SettingsPath=$SettingsPath"
76+
77+
if ($RepoRoot) {
78+
Write-Host "RepoRoot=$RepoRoot"
79+
}
80+
81+
Write-Host "ScanPath=$ScanPaths"
82+
83+
Write-Host "Installing setup tools and DocWarden"
84+
Write-Host "pip install setuptools wheel --quiet"
1385
pip install setuptools wheel --quiet
86+
if ($LASTEXITCODE -ne 0) {
87+
LogError "pip install setuptools wheel --quiet failed with exit code $LASTEXITCODE"
88+
exit 1
89+
}
90+
Write-Host "pip install doc-warden==$DocWardenVersion --quiet"
1491
pip install doc-warden==$DocWardenVersion --quiet
15-
16-
if ($RepoRoot)
17-
{
18-
ward scan -d $ScanPath -u $RepoRoot -c $SettingsPath
92+
if ($LASTEXITCODE -ne 0) {
93+
LogError "pip install doc-warden==$DocWardenVersion --quiet failed with exit code $LASTEXITCODE"
94+
exit 1
1995
}
20-
else
21-
{
22-
ward scan -d $ScanPath -c $SettingsPath
96+
97+
# Finally, do the scanning
98+
foreach ($path in $scanPathsArray) {
99+
Test-Readme-Files $SettingsPath $path $RepoRoot
23100
}
24101

102+
if ($script:FoundError) {
103+
LogError "There were README verification failures, scroll up to see the issue(s)"
104+
exit 1
105+
}

0 commit comments

Comments
 (0)