From ac2c03cce921a4b77c31d4d8e0bac302c0b727e9 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Fri, 7 Feb 2025 17:05:04 -0800 Subject: [PATCH] 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 --- .../scripts/Helpers/Package-Helpers.ps1 | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/eng/common/scripts/Helpers/Package-Helpers.ps1 b/eng/common/scripts/Helpers/Package-Helpers.ps1 index b545872db..ee62c0c4e 100644 --- a/eng/common/scripts/Helpers/Package-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Package-Helpers.ps1 @@ -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