Skip to content

Commit 7ee5ac5

Browse files
azure-sdkbenbp
andauthored
Fix issue where matrix replace was not using imported display names (Azure#18306)
Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
1 parent 57b45c5 commit 7ee5ac5

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

eng/common/scripts/job-matrix/job-matrix-functions.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function GenerateMatrix(
117117
}
118118

119119
$matrix = FilterMatrix $matrix $filters
120-
$matrix = ProcessReplace $matrix $replace $config.displayNamesLookup
120+
$matrix = ProcessReplace $matrix $replace $combinedDisplayNameLookup
121121
$matrix = FilterMatrixDisplayName $matrix $displayNameFilter
122122
return $matrix
123123
}
@@ -352,7 +352,7 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Array]$n
352352
}
353353
}
354354
if ((!$matrix -and !$importPath) -or !$importPath) {
355-
return $matrix, @()
355+
return $matrix, @(), @{}
356356
}
357357

358358
if (!(Test-Path $importPath)) {
@@ -370,7 +370,7 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Array]$n
370370
$combinedDisplayNameLookup[$lookup.Name] = $lookup.Value
371371
}
372372

373-
return $matrix, $importedMatrix, $importedMatrixConfig.displayNamesLookup
373+
return $matrix, $importedMatrix, $combinedDisplayNameLookup
374374
}
375375

376376
function CombineMatrices([Array]$matrix1, [Array]$matrix2, [Hashtable]$displayNamesLookup = @{})

eng/common/scripts/job-matrix/tests/job-matrix-functions.modification.tests.ps1

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ Describe "Platform Matrix Replace" -Tag "replace" {
403403
{ $parsed = ParseReplacement $query } | Should -Throw
404404
{ $parsed = ParseReplacement $query } | Should -Throw
405405
}
406-
406+
407407
It "Should replace values in a matrix" {
408408
$matrixJson = @'
409409
{
@@ -542,4 +542,31 @@ Describe "Platform Matrix Replace" -Tag "replace" {
542542
$matrix[1].parameters.Foo | Should -Be "foo2"
543543
$matrix[1].parameters.Bar | Should -Be "bar1"
544544
}
545+
546+
It "Should parse replacement syntax and source imported display name lookups" {
547+
$matrixJson = @'
548+
{
549+
"displayNames": {
550+
"replaceme": ""
551+
},
552+
"matrix": {
553+
"$IMPORT": "./test-import-matrix.json",
554+
"replaceme": "replaceme"
555+
}
556+
}
557+
'@
558+
$importConfig = GetMatrixConfigFromJson $matrixJson
559+
$replace = 'Foo=(foo)1/$1ReplacedFoo1', 'B.*=(.*)2/$1ReplacedBar2'
560+
$matrix = GenerateMatrix $importConfig "sparse" -replace $replace
561+
562+
$matrix.Length | Should -Be 3
563+
$matrix[0].name | Should -Be "fooReplacedFoo1_bar1"
564+
$matrix[0].parameters.Foo | Should -Be "fooReplacedFoo1"
565+
$matrix[1].name | Should -Be "foo2_barReplacedBar2"
566+
$matrix[1].parameters.Bar | Should -Be "barReplacedBar2"
567+
$matrix[2].name | Should -Be "importedBazName"
568+
$matrix[2].parameters.Baz | Should -Be "importedBaz"
569+
$matrix[2].parameters.replaceme | Should -Be "replaceme"
570+
}
571+
545572
}

0 commit comments

Comments
 (0)