11# Wrapper Script for Readme Verification
22[CmdletBinding ()]
33param (
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"
1385pip 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"
1491pip 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