parameters:
- name: PackagePropertiesFolder
  type: string
- name: RepoRoot
  type: string
  default: $(Build.SourcesDirectory)
- name: SettingsPath
  type: string
  default: '$(Build.SourcesDirectory)/eng/.docsettings.yml'
- name: DocWardenVersion
  type: string
  default: ''
- name: Condition
  type: string
  default: succeeded()

steps:
- pwsh: |
    $packageProperties = Get-ChildItem -Recurse "${{ parameters.PackagePropertiesFolder }}" *.json

    $paths = @()

    foreach($propertiesFile in $packageProperties) {
      $PackageProp = Get-Content -Path $propertiesFile | ConvertFrom-Json

      $paths += (Join-Path "$(Build.SourcesDirectory)" $PackageProp.DirectoryPath)
    }

    $scanPaths = $paths -join ","
    Write-Host "##vso[task.setvariable variable=ScanPathArgument;]$scanPaths"
  displayName: Populate Scan Paths
  condition: ${{ parameters.Condition }}

- task: PowerShell@2
  displayName: "Verify Readmes"
  condition: ${{ parameters.Condition }}
  inputs:
    filePath: "eng/common/scripts/Verify-Readme.ps1"
    arguments: >
      -DocWardenVersion '${{ parameters.DocWardenVersion }}'
      -ScanPaths '$(ScanPathArgument)'
      -RepoRoot ${{ parameters.RepoRoot }}
      -SettingsPath ${{ parameters.SettingsPath }}
    pwsh: true
