Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 1521 (#17597)
Browse files Browse the repository at this point in the history
* Fix issue where 2d index arrays with length 1 get flattened by powershell

* Pass NonSparseParameters to imported matrix generation

Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
  • Loading branch information
azure-sdk and benbp authored Mar 26, 2021
1 parent 68b8d77 commit 7284d8d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
4 changes: 4 additions & 0 deletions eng/common/scripts/job-matrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ Importing can be useful, for example, in cases where there is a shared base matr
once for each instance of a language version. Importing does not support overriding duplicate parameters. To achieve
this, use the [Replace](#replace-values) argument instead.

The `Selection` and `NonSparseParameters` parameters are respected when generating an imported matrix.

The processing order is as follows:

Given a matrix and import matrix like below:
Expand Down Expand Up @@ -494,6 +496,8 @@ Given a matrix like below with `JavaTestVersion` marked as a non-sparse paramete
A matrix with 6 entries will be generated: A sparse matrix of Agent, AZURE_TEST_HTTP_CLIENTS and ArmTemplateParameters
(3 total entries) will be multipled by the two `JavaTestVersion` parameters `1.8` and `1.11`.
NOTE: NonSparseParameters are also applied when generating an imported matrix.
#### Under the hood
The script generates an N-dimensional matrix with dimensions equal to the parameter array lengths. For example,
Expand Down
14 changes: 9 additions & 5 deletions eng/common/scripts/job-matrix/job-matrix-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ function GenerateMatrix(
[Array]$replace = @(),
[Array]$nonSparseParameters = @()
) {
$matrixParameters, $importedMatrix, $combinedDisplayNameLookup = ProcessImport $config.matrixParameters $selectFromMatrixType $config.displayNamesLookup
$matrixParameters, $importedMatrix, $combinedDisplayNameLookup = `
ProcessImport $config.matrixParameters $selectFromMatrixType $nonSparseParameters $config.displayNamesLookup
if ($selectFromMatrixType -eq "sparse") {
$matrix = GenerateSparseMatrix $matrixParameters $config.displayNamesLookup $nonSparseParameters
} elseif ($selectFromMatrixType -eq "all") {
Expand Down Expand Up @@ -340,7 +341,7 @@ function ProcessReplace
return $replaceMatrix
}

function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Hashtable]$displayNamesLookup)
function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Array]$nonSparseParameters, [Hashtable]$displayNamesLookup)
{
$importPath = ""
$matrix = $matrix | ForEach-Object {
Expand All @@ -355,7 +356,10 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Hashtabl
}

$importedMatrixConfig = GetMatrixConfigFromJson (Get-Content $importPath)
$importedMatrix = GenerateMatrix $importedMatrixConfig $selection
$importedMatrix = GenerateMatrix `
-config $importedMatrixConfig `
-selectFromMatrixType $selection `
-nonSparseParameters $nonSparseParameters

$combinedDisplayNameLookup = $importedMatrixConfig.displayNamesLookup
foreach ($lookup in $displayNamesLookup.GetEnumerator()) {
Expand Down Expand Up @@ -437,7 +441,7 @@ function GenerateSparseMatrix(
$matrix = GenerateFullMatrix $parameters $displayNamesLookup

$sparseMatrix = @()
$indexes = GetSparseMatrixIndexes $dimensions
[array]$indexes = GetSparseMatrixIndexes $dimensions
foreach ($idx in $indexes) {
$sparseMatrix += GetNdMatrixElement $idx $matrix $dimensions
}
Expand Down Expand Up @@ -469,7 +473,7 @@ function GetSparseMatrixIndexes([Array]$dimensions)
$indexes += ,$idx
}

return $indexes
return ,$indexes
}

function GenerateFullMatrix(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,46 @@ Describe "Platform Matrix nonSparse" -Tag "nonsparse" {
$matrix = GenerateMatrix $config "sparse" -nonSparseParameters "testField3","testField4"
$matrix.Length | Should -Be 8
}

It "Should apply nonSparseParameters to an imported matrix" {
$matrixJson = @'
{
"matrix": {
"$IMPORT": "./test-import-matrix.json",
"TestField1": "test1"
},
"exclude": [ { "Baz": "importedBaz" } ]
}
'@

$expectedMatrix = @'
[
{
"parameters": { "TestField1": "test1", "Foo": "foo1", "Bar": "bar1" },
"name": "test1_foo1_bar1"
},
{
"parameters": { "TestField1": "test1", "Foo": "foo1", "Bar": "bar2" },
"name": "test1_foo1_bar2"
},
{
"parameters": { "TestField1": "test1", "Foo": "foo2", "Bar": "bar1" },
"name": "test1_foo2_bar1"
},
{
"parameters": { "TestField1": "test1", "Foo": "foo2", "Bar": "bar2" },
"name": "test1_foo2_bar2"
}
]
'@

$importConfig = GetMatrixConfigFromJson $matrixJson
$matrix = GenerateMatrix $importConfig "sparse" -nonSparseParameters "Foo"
$expected = $expectedMatrix | ConvertFrom-Json -AsHashtable

$matrix.Length | Should -Be 4
CompareMatrices $matrix $expected
}
}

Describe "Platform Matrix Import" -Tag "import" {
Expand Down Expand Up @@ -129,6 +169,39 @@ Describe "Platform Matrix Import" -Tag "import" {
CompareMatrices $matrix $expected
}

It "Should import a matrix and combine with length=1 vectors" {
$matrixJson = @'
{
"matrix": {
"$IMPORT": "./test-import-matrix.json",
"TestField1": "test1",
"TestField2": "test2"
},
"exclude": [ { "Baz": "importedBaz" } ]
}
'@

$expectedMatrix = @'
[
{
"parameters": { "TestField1": "test1", "TestField2": "test2", "Foo": "foo1", "Bar": "bar1" },
"name": "test1_test2_foo1_bar1"
},
{
"parameters": { "TestField1": "test1", "TestField2": "test2", "Foo": "foo2", "Bar": "bar2" },
"name": "test1_test2_foo2_bar2"
}
]
'@

$importConfig = GetMatrixConfigFromJson $matrixJson
$matrix = GenerateMatrix $importConfig "sparse"
$expected = $expectedMatrix | ConvertFrom-Json -AsHashtable

$matrix.Length | Should -Be 2
CompareMatrices $matrix $expected
}

It "Should generate a matrix with nonSparseParameters and an imported sparse matrix" {
$matrixJson = @'
{
Expand Down

0 comments on commit 7284d8d

Please sign in to comment.