Skip to content

Commit 507ed3f

Browse files
azure-sdkbenbp
andauthored
Sync eng/common directory with azure-sdk-tools for PR 2967 (Azure#23792)
* 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]>
1 parent ea6b6f4 commit 507ed3f

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

eng/common/scripts/job-matrix/Create-JobMatrix.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ param (
1919

2020
. $PSScriptRoot/job-matrix-functions.ps1
2121

22+
if (!(Test-Path $ConfigPath)) {
23+
Write-Error "ConfigPath '$ConfigPath' does not exist."
24+
exit 1
25+
}
2226
$config = GetMatrixConfigFromJson (Get-Content $ConfigPath)
2327
# Strip empty string filters in order to be able to use azure pipelines yaml join()
2428
$Filters = $Filters | Where-Object { $_ }

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Array]$n
355355
return $matrix, @()
356356
}
357357

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

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

528529
return @{
529530
name = $name

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ Describe "Platform Matrix Generation With Object Fields" -Tag "objectfields" {
572572
}
573573
}
574574

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

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

613+
It "Should create a valid display name when there are leading numbers" {
614+
$generateconfig.displayNamesLookup["ubuntu-18.04"] = '123_ubuntu1804'
615+
$matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup
616+
617+
$matrix[0].name | Should -Be "job_123_ubuntu1804_net461_TestObjectValueName"
618+
}
619+
620+
It "Should create a valid job name when there are leading numbers" {
621+
$matrixConfigForGenerate = @"
622+
{
623+
"matrix": {
624+
"numField1": [1, 2, 3],
625+
"letterField": ["a", "b", "c"]
626+
}
627+
}
628+
"@
629+
$generateConfig = GetMatrixConfigFromJson $matrixConfigForGenerate
630+
$matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup
631+
$matrix[0].name | Should -Be "job_1_a"
632+
}
633+
634+
It "Should create a valid job name when parameter values are all numbers" {
635+
$matrixConfigForGenerate = @"
636+
{
637+
"matrix": {
638+
"numField1": ["1", "2", "3"],
639+
"numField2": [4, 5, 6]
640+
}
641+
}
642+
"@
643+
$generateConfig = GetMatrixConfigFromJson $matrixConfigForGenerate
644+
$matrix = GenerateSparseMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup
645+
$matrix[0].name | Should -Be "job_1_4"
646+
$matrix[1].name | Should -Be "job_2_5"
647+
$matrix[2].name | Should -Be "job_3_6"
648+
}
649+
614650
It "Should generate a display name with null and object values" {
615651
$matrix = GenerateMatrix $generateConfig "sparse"
616652
$matrix[0].name | Should -Be "ubuntu1804_net461_TestObjectValueName"

0 commit comments

Comments
 (0)