From 48ef687a8f941a6ab755b1d4e56701edcb8e29cf Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Thu, 2 Jun 2022 13:18:44 -0700 Subject: [PATCH] Fix issue where matrix replace was not using imported display names (#3694) Co-authored-by: Ben Broderick Phillips --- .../job-matrix/job-matrix-functions.ps1 | 6 ++-- ...ob-matrix-functions.modification.tests.ps1 | 29 ++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/eng/common/scripts/job-matrix/job-matrix-functions.ps1 b/eng/common/scripts/job-matrix/job-matrix-functions.ps1 index 7d3675213..8822d7ce7 100644 --- a/eng/common/scripts/job-matrix/job-matrix-functions.ps1 +++ b/eng/common/scripts/job-matrix/job-matrix-functions.ps1 @@ -117,7 +117,7 @@ function GenerateMatrix( } $matrix = FilterMatrix $matrix $filters - $matrix = ProcessReplace $matrix $replace $config.displayNamesLookup + $matrix = ProcessReplace $matrix $replace $combinedDisplayNameLookup $matrix = FilterMatrixDisplayName $matrix $displayNameFilter return $matrix } @@ -352,7 +352,7 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Array]$n } } if ((!$matrix -and !$importPath) -or !$importPath) { - return $matrix, @() + return $matrix, @(), @{} } if (!(Test-Path $importPath)) { @@ -370,7 +370,7 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Array]$n $combinedDisplayNameLookup[$lookup.Name] = $lookup.Value } - return $matrix, $importedMatrix, $importedMatrixConfig.displayNamesLookup + return $matrix, $importedMatrix, $combinedDisplayNameLookup } function CombineMatrices([Array]$matrix1, [Array]$matrix2, [Hashtable]$displayNamesLookup = @{}) diff --git a/eng/common/scripts/job-matrix/tests/job-matrix-functions.modification.tests.ps1 b/eng/common/scripts/job-matrix/tests/job-matrix-functions.modification.tests.ps1 index 08979caaa..9dca8eba0 100644 --- a/eng/common/scripts/job-matrix/tests/job-matrix-functions.modification.tests.ps1 +++ b/eng/common/scripts/job-matrix/tests/job-matrix-functions.modification.tests.ps1 @@ -403,7 +403,7 @@ Describe "Platform Matrix Replace" -Tag "replace" { { $parsed = ParseReplacement $query } | Should -Throw { $parsed = ParseReplacement $query } | Should -Throw } - + It "Should replace values in a matrix" { $matrixJson = @' { @@ -542,4 +542,31 @@ Describe "Platform Matrix Replace" -Tag "replace" { $matrix[1].parameters.Foo | Should -Be "foo2" $matrix[1].parameters.Bar | Should -Be "bar1" } + + It "Should parse replacement syntax and source imported display name lookups" { + $matrixJson = @' +{ + "displayNames": { + "replaceme": "" + }, + "matrix": { + "$IMPORT": "./test-import-matrix.json", + "replaceme": "replaceme" + } +} +'@ + $importConfig = GetMatrixConfigFromJson $matrixJson + $replace = 'Foo=(foo)1/$1ReplacedFoo1', 'B.*=(.*)2/$1ReplacedBar2' + $matrix = GenerateMatrix $importConfig "sparse" -replace $replace + + $matrix.Length | Should -Be 3 + $matrix[0].name | Should -Be "fooReplacedFoo1_bar1" + $matrix[0].parameters.Foo | Should -Be "fooReplacedFoo1" + $matrix[1].name | Should -Be "foo2_barReplacedBar2" + $matrix[1].parameters.Bar | Should -Be "barReplacedBar2" + $matrix[2].name | Should -Be "importedBazName" + $matrix[2].parameters.Baz | Should -Be "importedBaz" + $matrix[2].parameters.replaceme | Should -Be "replaceme" + } + }