Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 1461 #17126

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions eng/common/scripts/job-matrix/job-matrix-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function GenerateMatrix(
[Array]$filters = @(),
[Array]$nonSparseParameters = @()
) {
$orderedMatrix, $importedMatrix = ProcessImport $config.orderedMatrix $selectFromMatrixType
$orderedMatrix, $importedMatrix, $importedDisplayNamesLookup = ProcessImport $config.orderedMatrix $selectFromMatrixType
if ($selectFromMatrixType -eq "sparse") {
[Array]$matrix = GenerateSparseMatrix $orderedMatrix $config.displayNamesLookup $nonSparseParameters
} elseif ($selectFromMatrixType -eq "all") {
Expand All @@ -44,7 +44,7 @@ function GenerateMatrix(
# Combine with imported after matrix generation, since a sparse selection should result in a full combination of the
# top level and imported sparse matrices (as opposed to a sparse selection of both matrices).
if ($importedMatrix) {
[Array]$matrix = CombineMatrices $matrix $importedMatrix
[Array]$matrix = CombineMatrices $matrix $importedMatrix $importedDisplayNamesLookup
}

if ($config.exclude) {
Expand Down Expand Up @@ -199,19 +199,19 @@ function ProcessIncludes([MatrixConfig]$config, [Array]$matrix)
function ProcessImport([System.Collections.Specialized.OrderedDictionary]$matrix, [String]$selection)
{
if (!$matrix -or !$matrix.Contains($IMPORT_KEYWORD)) {
return $matrix
return $matrix, @(), @{}
}

$importPath = $matrix[$IMPORT_KEYWORD]
$matrix.Remove($IMPORT_KEYWORD)

$matrixConfig = GetMatrixConfigFromJson (Get-Content $importPath)
$importedMatrix = GenerateMatrix $matrixConfig $selection
$importedMatrixConfig = GetMatrixConfigFromJson (Get-Content $importPath)
$importedMatrix = GenerateMatrix $importedMatrixConfig $selection

return $matrix, $importedMatrix
return $matrix, $importedMatrix, $importedMatrixConfig.displayNamesLookup
}

function CombineMatrices([Array]$matrix1, [Array]$matrix2)
function CombineMatrices([Array]$matrix1, [Array]$matrix2, [Hashtable]$displayNamesLookup = @{})
{
$combined = @()
if (!$matrix1) {
Expand All @@ -223,21 +223,22 @@ function CombineMatrices([Array]$matrix1, [Array]$matrix2)

foreach ($entry1 in $matrix1) {
foreach ($entry2 in $matrix2) {
$entry2name = @()
$newEntry = @{
name = $entry1.name
parameters = CloneOrderedDictionary $entry1.parameters
}
foreach($param in $entry2.parameters.GetEnumerator()) {
if (!$newEntry.Contains($param.Name)) {
if (!$newEntry.parameters.Contains($param.Name)) {
$newEntry.parameters[$param.Name] = $param.Value
$entry2name += CreateDisplayName $param.Value $displayNamesLookup
} else {
Write-Warning "Skipping duplicate parameter `"$($param.Name)`" when combining matrix."
}
}

# The maximum allowed matrix name length is 100 characters
$entry2.name = $entry2.name.TrimStart("job_")
$newEntry.name = $newEntry.name, $entry2.name -join "_"
$newEntry.name = @($newEntry.name, ($entry2name -join "_")) -join "_"
if ($newEntry.name.Length -gt 100) {
$newEntry.name = $newEntry.name[0..99] -join ""
}
Expand Down Expand Up @@ -305,7 +306,7 @@ function GenerateSparseMatrix(

if ($nonSparse) {
[Array]$allOfMatrix = GenerateFullMatrix $nonSparse $displayNamesLookup
return CombineMatrices $allOfMatrix $sparseMatrix
return CombineMatrices $allOfMatrix $sparseMatrix $displayNamesLookup
}

return $sparseMatrix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,25 @@ Describe "Platform Matrix Import" -Tag "import" {
$matrix.Length | Should -Be 7
CompareMatrices $matrix $expected
}

It "Should generate a sparse matrix with an imported a sparse matrix" {
$matrixJson = @'
{
"matrix": {
"$IMPORT": "./test-import-matrix.json",
"Foo": [ "fooOverride1", "fooOverride2" ],
}
}
'@

$importConfig = GetMatrixConfigFromJson $matrixJson
$matrix = GenerateMatrix $importConfig "sparse"

$matrix[0].parameters["Foo"] | Should -Be "fooOverride1"
$matrix[0].name | Should -Be "fooOverride1_bar1"
$matrix[3].parameters["Foo"] | Should -Be "fooOverride2"
$matrix[3].name | Should -Be "fooOverride2_bar1"
$matrix[5].parameters["Foo"] | Should -Be "fooOverride2"
$matrix[5].name | Should -Be "fooOverride2_importedBaz"
}
}