Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 2967 (#2166)
Browse files Browse the repository at this point in the history
* Fix bug where job matrices with leading numbers generated duplicate job names

* Fail matrix generation when config path or import paths are not found

Co-authored-by: Ben Broderick Phillips <[email protected]>
  • Loading branch information
azure-sdk and benbp authored Apr 1, 2022
1 parent d353a56 commit 1ecee5d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
4 changes: 4 additions & 0 deletions eng/common/scripts/job-matrix/Create-JobMatrix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ param (

. $PSScriptRoot/job-matrix-functions.ps1

if (!(Test-Path $ConfigPath)) {
Write-Error "ConfigPath '$ConfigPath' does not exist."
exit 1
}
$config = GetMatrixConfigFromJson (Get-Content $ConfigPath)
# Strip empty string filters in order to be able to use azure pipelines yaml join()
$Filters = $Filters | Where-Object { $_ }
Expand Down
13 changes: 7 additions & 6 deletions eng/common/scripts/job-matrix/job-matrix-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Array]$n
return $matrix, @()
}

if (!(Test-Path $importPath)) {
Write-Error "`$IMPORT path '$importPath' does not exist."
exit 1
}
$importedMatrixConfig = GetMatrixConfigFromJson (Get-Content $importPath)
$importedMatrix = GenerateMatrix `
-config $importedMatrixConfig `
Expand Down Expand Up @@ -515,15 +519,12 @@ function CreateMatrixCombinationScalar([MatrixParameter[]]$permutation, [Hashtab

# The maximum allowed matrix name length is 100 characters
$name = $names -join "_"
if ($name -and $name[0] -match "^[0-9]") {
$name = "job_" + $name # Azure Pipelines only supports job names starting with letters
}
if ($name.Length -gt 100) {
$name = $name[0..99] -join ""
}
$stripped = $name -replace "^[^A-Za-z]*", "" # strip leading digits
if ($stripped -eq "") {
$name = "job_" + $name # Handle names that consist entirely of numbers
} else {
$name = $stripped
}

return @{
name = $name
Expand Down
40 changes: 38 additions & 2 deletions eng/common/scripts/job-matrix/tests/job-matrix-functions.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ Describe "Platform Matrix Generation With Object Fields" -Tag "objectfields" {
}
}

Describe "Platform Matrix Display Names" -Tag "displaynames" {
Describe "Platform Matrix Job and Display Names" -Tag "displaynames" {
BeforeEach {
$matrixConfigForGenerate = @"
{
Expand Down Expand Up @@ -601,7 +601,6 @@ Describe "Platform Matrix Display Names" -Tag "displaynames" {
It "Should enforce valid display name format" {
$generateconfig.displayNamesLookup["net461"] = '123.Some.456.Invalid_format-name$(foo)'
$generateconfig.displayNamesLookup["netcoreapp2.1"] = (New-Object string[] 150) -join "a"
$dimensions = GetMatrixDimensions $generateConfig.matrixParameters
$matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup

$matrix[0].name | Should -Be "ubuntu1804_123some456invalid_formatnamefoo_TestObjectValueName"
Expand All @@ -611,6 +610,43 @@ Describe "Platform Matrix Display Names" -Tag "displaynames" {
$matrix[1].name | Should -BeLike "ubuntu1804_aaaaaaaaaaaaaaaaa*"
}

It "Should create a valid display name when there are leading numbers" {
$generateconfig.displayNamesLookup["ubuntu-18.04"] = '123_ubuntu1804'
$matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup

$matrix[0].name | Should -Be "job_123_ubuntu1804_net461_TestObjectValueName"
}

It "Should create a valid job name when there are leading numbers" {
$matrixConfigForGenerate = @"
{
"matrix": {
"numField1": [1, 2, 3],
"letterField": ["a", "b", "c"]
}
}
"@
$generateConfig = GetMatrixConfigFromJson $matrixConfigForGenerate
$matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup
$matrix[0].name | Should -Be "job_1_a"
}

It "Should create a valid job name when parameter values are all numbers" {
$matrixConfigForGenerate = @"
{
"matrix": {
"numField1": ["1", "2", "3"],
"numField2": [4, 5, 6]
}
}
"@
$generateConfig = GetMatrixConfigFromJson $matrixConfigForGenerate
$matrix = GenerateSparseMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup
$matrix[0].name | Should -Be "job_1_4"
$matrix[1].name | Should -Be "job_2_5"
$matrix[2].name | Should -Be "job_3_6"
}

It "Should generate a display name with null and object values" {
$matrix = GenerateMatrix $generateConfig "sparse"
$matrix[0].name | Should -Be "ubuntu1804_net461_TestObjectValueName"
Expand Down

0 comments on commit 1ecee5d

Please sign in to comment.