From c516bc82ea6c59e87441dc00618bc22436459e64 Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Tue, 28 Jun 2022 10:56:38 -0700 Subject: [PATCH 1/4] Update verify-readme to take a single or multiple paths --- .../templates/steps/verify-readme.yml | 21 +++- eng/common/scripts/Verify-Readme.ps1 | 109 ++++++++++++++++-- 2 files changed, 116 insertions(+), 14 deletions(-) diff --git a/eng/common/pipelines/templates/steps/verify-readme.yml b/eng/common/pipelines/templates/steps/verify-readme.yml index 9d8d92fb7cb7..8c56e9969200 100644 --- a/eng/common/pipelines/templates/steps/verify-readme.yml +++ b/eng/common/pipelines/templates/steps/verify-readme.yml @@ -1,8 +1,20 @@ parameters: - ScanPath: $(Build.SourcesDirectory) - RepoRoot: $(Build.SourcesDirectory) - SettingsPath: '$(Build.SourcesDirectory)/eng/.docsettings.yml' - DocWardenVersion : '0.7.2' +- name: ScanPath + type: string + default: '' + # Where ScanPath takes a single path, ScanPaths takes a comma separated list of paths to scan +- name: ScanPaths + type: string + default: '' +- name: RepoRoot + type: string + default: $(Build.SourcesDirectory) +- name: SettingsPath + type: string + default: '$(Build.SourcesDirectory)/eng/.docsettings.yml' +- name: DocWardenVersion + type: string + default: '0.7.2' steps: - task: PowerShell@2 @@ -12,6 +24,7 @@ steps: arguments: > -DocWardenVersion ${{ parameters.DocWardenVersion }} -ScanPath ${{ parameters.ScanPath }} + -ScanPaths '${{ parameters.ScanPaths }}' -RepoRoot ${{ parameters.RepoRoot }} -SettingsPath ${{ parameters.SettingsPath }} pwsh: true \ No newline at end of file diff --git a/eng/common/scripts/Verify-Readme.ps1 b/eng/common/scripts/Verify-Readme.ps1 index c0259934048b..9db196f8aa2b 100644 --- a/eng/common/scripts/Verify-Readme.ps1 +++ b/eng/common/scripts/Verify-Readme.ps1 @@ -1,24 +1,113 @@ # Wrapper Script for Readme Verification [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $false)] [string]$DocWardenVersion, - [Parameter(Mandatory = $true)] - [string]$ScanPath, [string]$RepoRoot, + [string]$ScanPath, + [AllowEmptyCollection()] + [array] $ScanPaths, [Parameter(Mandatory = $true)] [string]$SettingsPath ) +. (Join-Path $PSScriptRoot common.ps1) +$script:FoundError = $false +function Test-Readme-Files { + param( + [string]$SettingsPath, + [string]$ScanPath, + [string]$RepoRoot) + + Write-Host "Scanning..." + + if ($RepoRoot) + { + Write-Host "ward scan -d $ScanPath -u $RepoRoot -c $SettingsPath" + ward scan -d $ScanPath -u $RepoRoot -c $SettingsPath + } + else + { + Write-Host "ward scan -d $ScanPath -c $SettingsPath" + ward scan -d $ScanPath -c $SettingsPath + } + # ward scan is what returns the non-zero exit code on failure. + # Since it's being called from a function, that error needs to + # be propagated back so the script can exit appropriately + if ($LASTEXITCODE -ne 0) { + $script:FoundError = $true + } +} + +# Verify all of the inputs before running anything +if ([String]::IsNullOrWhiteSpace($DocWardenVersion)) { + LogError "DocWardenVersion cannot be null or empty" + $script:FoundError = $true +} + +# verify the doc settings file exists +if (!(Test-Path -Path $SettingsPath -PathType leaf)) { + LogError "Setting file, $SettingsPath, does not exist" + $script:FoundError = $true +} + +# Verify that either ScanPath or ScanPaths were set but not both or neither +if (![String]::IsNullOrWhiteSpace($ScanPath) -and $ScanPaths.Count -gt 0) { + LogError "Only ScanPath or ScanPaths can be set but not both." + $script:FoundError = $true +} elseif ([String]::IsNullOrWhiteSpace($ScanPath) -and $ScanPaths.Count -eq 0) { + LogError "ScanPath or ScanPaths, one or the other, must be set." + $script:FoundError = $true +} + +# Exit out now if there were any argument issues +if ($script:FoundError) { + LogError "There were argument failures, please see above for specifics" + exit 1 +} + +# Echo back the settings +Write-Host "DocWardenVersion=$DocWardenVersion" +Write-Host "SettingsPath=$SettingsPath" + +if ($RepoRoot) { + Write-Host "RepoRoot=$RepoRoot" +} +if (![String]::IsNullOrWhiteSpace($ScanPath)) { + Write-Host "ScanPath=$ScanPath" +} +if ($ScanPaths.Count -gt 0) { + Write-Host "ScanPaths=" + foreach ($path in $ScanPaths) { + Write-Host " $path" + } +} + + +Write-Host "Installing setup tools and DocWarden" +Write-Host "pip install setuptools wheel --quiet" pip install setuptools wheel --quiet +if ($LASTEXITCODE -ne 0) { + LogError "pip install setuptools wheel --quiet failed with exit code $LASTEXITCODE" + exit 1 +} +Write-Host "pip install doc-warden==$DocWardenVersion --quiet" pip install doc-warden==$DocWardenVersion --quiet - -if ($RepoRoot) -{ - ward scan -d $ScanPath -u $RepoRoot -c $SettingsPath +if ($LASTEXITCODE -ne 0) { + LogError "pip install doc-warden==$DocWardenVersion --quiet failed with exit code $LASTEXITCODE" + exit 1 } -else -{ - ward scan -d $ScanPath -c $SettingsPath + +# Finally, do the scanning +if ($ScanPaths.Count -gt 0) { + foreach ($path in $ScanPaths) { + Test-Readme-Files $SettingsPath $path $RepoRoot + } +} else { + Test-Readme-Files $SettingsPath $ScanPath $RepoRoot } +if ($script:FoundError) { + LogError "There were README verification failures, scroll up to see the issue(s)" + exit 1 +} \ No newline at end of file From 7f79249e30ff317424f61293259e200d9aaf405c Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Tue, 28 Jun 2022 13:27:03 -0700 Subject: [PATCH 2/4] chance ScanPaths to a comma delimited list and coalesce ScanPath/ScanPaths into a single variable for the script --- .../templates/steps/verify-readme.yml | 7 ++-- eng/common/scripts/Verify-Readme.ps1 | 41 +++++++------------ 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/eng/common/pipelines/templates/steps/verify-readme.yml b/eng/common/pipelines/templates/steps/verify-readme.yml index 8c56e9969200..a258ae5aceb7 100644 --- a/eng/common/pipelines/templates/steps/verify-readme.yml +++ b/eng/common/pipelines/templates/steps/verify-readme.yml @@ -14,7 +14,7 @@ parameters: default: '$(Build.SourcesDirectory)/eng/.docsettings.yml' - name: DocWardenVersion type: string - default: '0.7.2' + default: '' steps: - task: PowerShell@2 @@ -22,9 +22,8 @@ steps: inputs: filePath: "eng/common/scripts/Verify-Readme.ps1" arguments: > - -DocWardenVersion ${{ parameters.DocWardenVersion }} - -ScanPath ${{ parameters.ScanPath }} - -ScanPaths '${{ parameters.ScanPaths }}' + -DocWardenVersion '${{ parameters.DocWardenVersion }}'' + -ScanPaths '${{ coalesce(parameters.ScanPath, parameters.ScanPaths) }}' -RepoRoot ${{ parameters.RepoRoot }} -SettingsPath ${{ parameters.SettingsPath }} pwsh: true \ No newline at end of file diff --git a/eng/common/scripts/Verify-Readme.ps1 b/eng/common/scripts/Verify-Readme.ps1 index 9db196f8aa2b..c82bb9321868 100644 --- a/eng/common/scripts/Verify-Readme.ps1 +++ b/eng/common/scripts/Verify-Readme.ps1 @@ -4,13 +4,12 @@ param ( [Parameter(Mandatory = $false)] [string]$DocWardenVersion, [string]$RepoRoot, - [string]$ScanPath, - [AllowEmptyCollection()] - [array] $ScanPaths, + [string]$ScanPaths, [Parameter(Mandatory = $true)] [string]$SettingsPath ) . (Join-Path $PSScriptRoot common.ps1) +$DefaultDocWardenVersion = "0.7.2" $script:FoundError = $false function Test-Readme-Files { @@ -41,8 +40,7 @@ function Test-Readme-Files { # Verify all of the inputs before running anything if ([String]::IsNullOrWhiteSpace($DocWardenVersion)) { - LogError "DocWardenVersion cannot be null or empty" - $script:FoundError = $true + $DocWardenVersion = $DefaultDocWardenVersion } # verify the doc settings file exists @@ -52,12 +50,15 @@ if (!(Test-Path -Path $SettingsPath -PathType leaf)) { } # Verify that either ScanPath or ScanPaths were set but not both or neither -if (![String]::IsNullOrWhiteSpace($ScanPath) -and $ScanPaths.Count -gt 0) { - LogError "Only ScanPath or ScanPaths can be set but not both." - $script:FoundError = $true -} elseif ([String]::IsNullOrWhiteSpace($ScanPath) -and $ScanPaths.Count -eq 0) { - LogError "ScanPath or ScanPaths, one or the other, must be set." - $script:FoundError = $true +if ([String]::IsNullOrWhiteSpace($ScanPaths)) { + LogError "ScanPaths cannot be empty." +} else { + foreach ($path in $ScanPaths.Split(',')) { + if (!(Test-Path -Path $path -PathType Container)) { + LogError "path, $path, doesn't exist or isn't a directory" + $script:FoundError = $true + } + } } # Exit out now if there were any argument issues @@ -73,16 +74,8 @@ Write-Host "SettingsPath=$SettingsPath" if ($RepoRoot) { Write-Host "RepoRoot=$RepoRoot" } -if (![String]::IsNullOrWhiteSpace($ScanPath)) { - Write-Host "ScanPath=$ScanPath" -} -if ($ScanPaths.Count -gt 0) { - Write-Host "ScanPaths=" - foreach ($path in $ScanPaths) { - Write-Host " $path" - } -} +Write-Host "ScanPath=$ScanPaths" Write-Host "Installing setup tools and DocWarden" Write-Host "pip install setuptools wheel --quiet" @@ -99,12 +92,8 @@ if ($LASTEXITCODE -ne 0) { } # Finally, do the scanning -if ($ScanPaths.Count -gt 0) { - foreach ($path in $ScanPaths) { - Test-Readme-Files $SettingsPath $path $RepoRoot - } -} else { - Test-Readme-Files $SettingsPath $ScanPath $RepoRoot +foreach ($path in $ScanPaths.Split(',')) { + Test-Readme-Files $SettingsPath $path $RepoRoot } if ($script:FoundError) { From f5bdd6b89973327ac60a8ba6656943e8ac628a86 Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Tue, 28 Jun 2022 13:43:02 -0700 Subject: [PATCH 3/4] VS Code was nice enough to add an extra single quote when adding a quote to the end of the line' --- eng/common/pipelines/templates/steps/verify-readme.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/verify-readme.yml b/eng/common/pipelines/templates/steps/verify-readme.yml index a258ae5aceb7..7b9217ade3e2 100644 --- a/eng/common/pipelines/templates/steps/verify-readme.yml +++ b/eng/common/pipelines/templates/steps/verify-readme.yml @@ -22,7 +22,7 @@ steps: inputs: filePath: "eng/common/scripts/Verify-Readme.ps1" arguments: > - -DocWardenVersion '${{ parameters.DocWardenVersion }}'' + -DocWardenVersion '${{ parameters.DocWardenVersion }}' -ScanPaths '${{ coalesce(parameters.ScanPath, parameters.ScanPaths) }}' -RepoRoot ${{ parameters.RepoRoot }} -SettingsPath ${{ parameters.SettingsPath }} From a32c05ec4f9a4dd7c93c19930a41b5ac403f6363 Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Tue, 28 Jun 2022 15:15:54 -0700 Subject: [PATCH 4/4] Capture ScanPaths.Split into an array so we don't have to call Split again --- eng/common/scripts/Verify-Readme.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/Verify-Readme.ps1 b/eng/common/scripts/Verify-Readme.ps1 index c82bb9321868..4e2cd6522497 100644 --- a/eng/common/scripts/Verify-Readme.ps1 +++ b/eng/common/scripts/Verify-Readme.ps1 @@ -49,11 +49,14 @@ if (!(Test-Path -Path $SettingsPath -PathType leaf)) { $script:FoundError = $true } +$scanPathsArray = @() + # Verify that either ScanPath or ScanPaths were set but not both or neither if ([String]::IsNullOrWhiteSpace($ScanPaths)) { LogError "ScanPaths cannot be empty." } else { - foreach ($path in $ScanPaths.Split(',')) { + $scanPathsArray = $ScanPaths.Split(',') + foreach ($path in $scanPathsArray) { if (!(Test-Path -Path $path -PathType Container)) { LogError "path, $path, doesn't exist or isn't a directory" $script:FoundError = $true @@ -92,7 +95,7 @@ if ($LASTEXITCODE -ne 0) { } # Finally, do the scanning -foreach ($path in $ScanPaths.Split(',')) { +foreach ($path in $scanPathsArray) { Test-Readme-Files $SettingsPath $path $RepoRoot }