Skip to content

Commit

Permalink
handle additional matrix config list
Browse files Browse the repository at this point in the history
  • Loading branch information
scbedd authored and azure-sdk committed Oct 30, 2024
1 parent f8dfcde commit 641433d
Showing 1 changed file with 32 additions and 59 deletions.
91 changes: 32 additions & 59 deletions eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Helper functions for retrieving useful information from azure-sdk-for-* repo
. "${PSScriptRoot}\logging.ps1"
. "${PSScriptRoot}\Helpers\Package-Helpers.ps1"
class PackageProps
{
class PackageProps {
[string]$Name
[string]$Version
[string]$DevVersion
Expand All @@ -23,13 +22,11 @@ class PackageProps
[HashTable]$ArtifactDetails
[HashTable[]]$CIMatrixConfigs

PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory)
{
PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory) {
$this.Initialize($name, $version, $directoryPath, $serviceDirectory)
}

PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory, [string]$group = "")
{
PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory, [string]$group = "") {
$this.Initialize($name, $version, $directoryPath, $serviceDirectory, $group)
}

Expand All @@ -38,35 +35,29 @@ class PackageProps
[string]$version,
[string]$directoryPath,
[string]$serviceDirectory
)
{
) {
$this.Name = $name
$this.Version = $version
$this.DirectoryPath = $directoryPath
$this.ServiceDirectory = $serviceDirectory
$this.IncludedForValidation = $false

if (Test-Path (Join-Path $directoryPath "README.md"))
{
if (Test-Path (Join-Path $directoryPath "README.md")) {
$this.ReadMePath = Join-Path $directoryPath "README.md"
}
else
{
else {
$this.ReadMePath = $null
}

if (Test-Path (Join-Path $directoryPath "CHANGELOG.md"))
{
if (Test-Path (Join-Path $directoryPath "CHANGELOG.md")) {
$this.ChangeLogPath = Join-Path $directoryPath "CHANGELOG.md"
# Get release date for current version and set in package property
$changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $this.ChangeLogPath -VersionString $this.Version
if ($changeLogEntry -and $changeLogEntry.ReleaseStatus)
{
$this.ReleaseStatus = $changeLogEntry.ReleaseStatus.Trim().Trim("()")
if ($changeLogEntry -and $changeLogEntry.ReleaseStatus) {
$this.ReleaseStatus = $changeLogEntry.ReleaseStatus.Trim().Trim("()")
}
}
else
{
else {
$this.ChangeLogPath = $null
}

Expand All @@ -79,8 +70,7 @@ class PackageProps
[string]$directoryPath,
[string]$serviceDirectory,
[string]$group
)
{
) {
$this.Initialize($name, $version, $directoryPath, $serviceDirectory)
$this.Group = $group
}
Expand All @@ -99,14 +89,14 @@ class PackageProps
if ($artifactForCurrentPackage) {
$result = [PSCustomObject]@{
ArtifactConfig = [HashTable]$artifactForCurrentPackage
MatrixConfigs = @()
MatrixConfigs = @()
}

# if we know this is the matrix for our file, we should now see if there is a custom matrix config for the package
$matrixConfigList = GetValueSafelyFrom-Yaml $content @("extends", "parameters", "MatrixConfigs")

if ($matrixConfigList) {
$result.MatrixConfigs = matrixConfigList
$result.MatrixConfigs = $matrixConfigList
}

return $result
Expand All @@ -115,14 +105,14 @@ class PackageProps
return $null
}

[void]InitializeCIArtifacts(){
[void]InitializeCIArtifacts() {
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..")

$ciFolderPath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory)
$ciFiles = Get-ChildItem -Path $ciFolderPath -Filter "ci*.yml" -File

if (-not $this.ArtifactDetails) {
foreach($ciFile in $ciFiles) {
foreach ($ciFile in $ciFiles) {
$ciArtifactResult = $this.ParseYmlForArtifact($ciFile.FullName)
if ($ciArtifactResult) {
$this.ArtifactDetails = [Hashtable]$ciArtifactResult.ArtifactConfig
Expand All @@ -140,8 +130,7 @@ class PackageProps
# Returns important properties of the package relative to the language repo
# Returns a PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
# Note: python is required for parsing python package properties.
function Get-PkgProperties
{
function Get-PkgProperties {
Param
(
[Parameter(Mandatory = $true)]
Expand All @@ -152,10 +141,8 @@ function Get-PkgProperties
$allPkgProps = Get-AllPkgProperties -ServiceDirectory $ServiceDirectory
$pkgProps = $allPkgProps.Where({ $_.Name -eq $PackageName -or $_.ArtifactName -eq $PackageName });

if ($pkgProps.Count -ge 1)
{
if ($pkgProps.Count -gt 1)
{
if ($pkgProps.Count -ge 1) {
if ($pkgProps.Count -gt 1) {
Write-Host "Found more than one project with the name [$PackageName], choosing the first one under $($pkgProps[0].DirectoryPath)"
}
return $pkgProps[0]
Expand All @@ -175,14 +162,12 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
$additionalValidationPackages = @()
$lookup = @{}

foreach ($pkg in $allPackageProperties)
{
foreach ($pkg in $allPackageProperties) {
$pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)"
$lookupKey = ($pkg.DirectoryPath).Replace($RepoRoot, "").TrimStart('\/')
$lookup[$lookupKey] = $pkg

foreach ($file in $targetedFiles)
{
foreach ($file in $targetedFiles) {
$filePath = Resolve-Path (Join-Path $RepoRoot $file)
$shouldInclude = $filePath -like "$pkgDirectory*"
if ($shouldInclude) {
Expand All @@ -207,8 +192,7 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
}
}

if ($AdditionalValidationPackagesFromPackageSetFn -and (Test-Path "Function:$AdditionalValidationPackagesFromPackageSetFn"))
{
if ($AdditionalValidationPackagesFromPackageSetFn -and (Test-Path "Function:$AdditionalValidationPackagesFromPackageSetFn")) {
$packagesWithChanges += &$AdditionalValidationPackagesFromPackageSetFn $packagesWithChanges $diff $allPackageProperties
}

Expand All @@ -218,25 +202,19 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
# Takes ServiceName and Repo Root Directory
# Returns important properties for each package in the specified service, or entire repo if the serviceName is not specified
# Returns a Table of service key to array values of PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
function Get-AllPkgProperties ([string]$ServiceDirectory = $null)
{
function Get-AllPkgProperties ([string]$ServiceDirectory = $null) {
$pkgPropsResult = @()

if (Test-Path "Function:Get-AllPackageInfoFromRepo")
{
if (Test-Path "Function:Get-AllPackageInfoFromRepo") {
$pkgPropsResult = Get-AllPackageInfoFromRepo -ServiceDirectory $serviceDirectory
}
else
{
if ([string]::IsNullOrEmpty($ServiceDirectory))
{
foreach ($dir in (Get-ChildItem (Join-Path $RepoRoot "sdk") -Directory))
{
else {
if ([string]::IsNullOrEmpty($ServiceDirectory)) {
foreach ($dir in (Get-ChildItem (Join-Path $RepoRoot "sdk") -Directory)) {
$pkgPropsResult += Get-PkgPropsForEntireService -serviceDirectoryPath $dir.FullName
}
}
else
{
else {
$pkgPropsResult = Get-PkgPropsForEntireService -serviceDirectoryPath (Join-Path $RepoRoot "sdk" $ServiceDirectory)
}
}
Expand All @@ -246,29 +224,24 @@ function Get-AllPkgProperties ([string]$ServiceDirectory = $null)

# Given the metadata url under https://github.com/Azure/azure-sdk/tree/main/_data/releases/latest,
# the function will return the csv metadata back as part of the response.
function Get-CSVMetadata ([string]$MetadataUri=$MetadataUri)
{
function Get-CSVMetadata ([string]$MetadataUri = $MetadataUri) {
$metadataResponse = Invoke-RestMethod -Uri $MetadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv
return $metadataResponse
}

function Get-PkgPropsForEntireService ($serviceDirectoryPath)
{
function Get-PkgPropsForEntireService ($serviceDirectoryPath) {
$projectProps = @() # Properties from every project in the service
$serviceDirectory = $serviceDirectoryPath -replace '^.*[\\/]+sdk[\\/]+([^\\/]+).*$', '$1'

if (!$GetPackageInfoFromRepoFn -or !(Test-Path "Function:$GetPackageInfoFromRepoFn"))
{
if (!$GetPackageInfoFromRepoFn -or !(Test-Path "Function:$GetPackageInfoFromRepoFn")) {
LogError "The function for '$GetPackageInfoFromRepoFn' was not found.`
Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.`
See https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md#code-structure"
}

foreach ($directory in (Get-ChildItem $serviceDirectoryPath -Directory))
{
foreach ($directory in (Get-ChildItem $serviceDirectoryPath -Directory)) {
$pkgProps = &$GetPackageInfoFromRepoFn $directory.FullName $serviceDirectory
if ($null -ne $pkgProps)
{
if ($null -ne $pkgProps) {
$projectProps += $pkgProps
}
}
Expand Down

0 comments on commit 641433d

Please sign in to comment.