Sync eng/common directory with azure-sdk-tools for PR 9799 (#6402)

* resolve issue with matrix collation when multiple matrix configs are being resolved

---------

Co-authored-by: Scott Beddall <scbedd@microsoft.com>
This commit is contained in:
Azure SDK Bot 2025-02-07 17:05:04 -08:00 committed by GitHub
parent b7bd086776
commit ac2c03cce9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -210,14 +210,33 @@ function Group-ByObjectKey {
$groupedDictionary = @{}
foreach ($item in $Items) {
$key = Get-ObjectKey $item."$GroupByProperty"
# if the item is an array, we need to group by each element in the array
# however if it's an empty array we want to treat it as a single item
if ($item."$GroupByProperty" -and $item."$GroupByProperty" -is [array]) {
foreach ($GroupByPropertyValue in $item."$GroupByProperty") {
$key = Get-ObjectKey $GroupByPropertyValue
if (-not $groupedDictionary.ContainsKey($key)) {
$groupedDictionary[$key] = @()
if (-not $groupedDictionary.ContainsKey($key)) {
$groupedDictionary[$key] = @()
}
$groupedDictionary[$key] += $item
}
}
else {
if ($item."$GroupByProperty") {
$key = Get-ObjectKey $item."$GroupByProperty"
}
else {
$key = "unset"
}
# Add the current item to the array for this key
$groupedDictionary[$key] += $item
if (-not $groupedDictionary.ContainsKey($key)) {
$groupedDictionary[$key] = @()
}
$groupedDictionary[$key] += $item
}
}
return $groupedDictionary