Skip to content

Commit

Permalink
Fix issue where matrix replace was not using imported display names (#…
Browse files Browse the repository at this point in the history
…29195)

Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
  • Loading branch information
azure-sdk and benbp authored Jun 2, 2022
1 parent 8448649 commit f907d90
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 3 additions & 3 deletions eng/common/scripts/job-matrix/job-matrix-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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 = @{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @'
{
Expand Down Expand Up @@ -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"
}

}

0 comments on commit f907d90

Please sign in to comment.