azure-sdk-for-cpp/eng/common/scripts/Verify-Resource-Ref.ps1
Azure SDK Bot 0456c58298
Sync eng/common directory with azure-sdk-tools for PR 3568 (#3804)
* Skip yml files for which parsing failed

* Update eng/common/scripts/Verify-Resource-Ref.ps1

Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>
2022-07-06 14:00:13 -07:00

51 lines
1.4 KiB
PowerShell

. (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()
foreach ($file in $ymlfiles)
{
Write-Host "Verifying '${file}'"
$ymlContent = Get-Content $file.FullName -Raw
try
{
$ymlObject = ConvertFrom-Yaml $ymlContent -Ordered
}
catch
{
Write-Host "Skipping $($file.FullName) because the file does not contain valid yml."
continue
}
if ($ymlObject -and ($ymlObject.Contains("resources")))
{
if ($ymlObject["resources"]["repositories"])
{
$repositories = $ymlObject["resources"]["repositories"]
foreach ($repo in $repositories)
{
$repoName = $repo["repository"]
if (-not ($repo.Contains("ref")))
{
$errorMessage = "File: ${file}, Repository: ${repoName}."
[void]$affectedRepos.Add($errorMessage)
}
}
}
}
}
if ($affectedRepos.Count -gt 0)
{
Write-Output "Ref not found in the following Repository Resources."
foreach ($errorMessage in $affectedRepos)
{
Write-Output "`t$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"
exit 1
}
Write-Output "All repository resources in yaml files reference a valid tag"