...

Text file src/github.com/Azure/azure-sdk-for-go/eng/common/scripts/Verify-Resource-Ref.ps1

Documentation: github.com/Azure/azure-sdk-for-go/eng/common/scripts

     1. (Join-Path $PSScriptRoot common.ps1)
     2Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser
     3$ymlfiles = Get-ChildItem $RepoRoot -recurse | Where-Object {$_ -like '*.yml'}
     4$affectedRepos = [System.Collections.ArrayList]::new()
     5
     6foreach ($file in $ymlfiles)
     7{
     8  Write-Host "Verifying '${file}'"
     9  $ymlContent = Get-Content $file.FullName -Raw
    10  $ymlObject = ConvertFrom-Yaml $ymlContent -Ordered
    11
    12  if ($ymlObject.Contains("resources"))
    13  {
    14    if ($ymlObject["resources"]["repositories"])
    15    {
    16      $repositories = $ymlObject["resources"]["repositories"]
    17      foreach ($repo in $repositories)
    18      {
    19        $repoName = $repo["repository"]
    20        if (-not ($repo.Contains("ref")))
    21        {
    22          $errorMessage = "File: ${file}, Repository: ${repoName}."
    23          [void]$affectedRepos.Add($errorMessage)
    24        }
    25      }
    26    }
    27  }
    28}
    29
    30if ($affectedRepos.Count -gt 0)
    31{
    32    Write-Output "Ref not found in the following Repository Resources."
    33    foreach ($errorMessage in $affectedRepos)
    34    {
    35        Write-Output "`t$errorMessage"
    36    }
    37    Write-Output "Please ensure you add a Ref: when using repository resources"
    38    Write-Output "More Info at https://aka.ms/azsdk/engsys/tools-versioning"
    39    exit 1
    40}
    41
    42Write-Output "All repository resources in yaml files reference a valid tag"

View as plain text