Skip to content

Commit 485de47

Browse files
Update for PR test matrix (Azure#44081)
* Update for PR test matrix * add PR to 'Initialize project list variable for PR test run' since this task is specific to PRs * updates for feedback * Update eng/pipelines/scripts/generate-project-list.ps1 committing suggestion Co-authored-by: Wes Haggard <[email protected]> * remove extra end } --------- Co-authored-by: Wes Haggard <[email protected]>
1 parent 043d043 commit 485de47

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

eng/pipelines/scripts/generate-project-list.ps1

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ $projectList = @()
22
$artifactsList = @()
33
$additionalModulesList = @()
44

5+
. "${PSScriptRoot}/../../common/scripts/common.ps1"
6+
57
if ($env:ARTIFACTSJSON -and $env:ARTIFACTSJSON -notlike '*ArtifactsJson*') {
68
$artifacts = $env:ARTIFACTSJSON | ConvertFrom-Json
79
foreach ($artifact in $artifacts) {
@@ -23,7 +25,29 @@ if ($env:ADDITIONALMODULESJSON -and $env:ADDITIONALMODULESJSON -notlike '*Additi
2325
# which means this is running as part of the pullrequest pipeline and the project list needs to
2426
# be figured out from the packageInfo files.
2527
if ($projectList.Length -eq 0 -and $ENV:PACKAGEINFODIR) {
26-
[array]$packageInfoFiles = Get-ChildItem -Path $ENV:PACKAGEINFODIR "*.json"
28+
# This is the case where this is being called as part of the set of test matrix runs.
29+
# The ArtifactPackageNames environment variable will be set if this is being called
30+
# as one of the test matrix runs. In this case, the project and additional modules lists
31+
# need to be filtered by the ArtifactPackageNames otherwise there will be artifacts on
32+
# the maven command line, for a matrix, that don't belong to the matrx if the PR has
33+
# changes to multiple libraries that have different test matrices.
34+
if (-not [string]::IsNullOrEmpty($ENV:ARTIFACTPACKAGENAMES)) {
35+
Write-Host "ArtifactPackageNames is set to: $($ENV:ARTIFACTPACKAGENAMES)"
36+
# The ArtifactPackageNames is a comma separated list
37+
foreach ($artifactPackageName in $ENV:ARTIFACTPACKAGENAMES.Split(',')) {
38+
# There should only be 1 PackageInfo file for each ArtifactPackageName.
39+
[array]$packageInfoFiles = Get-ChildItem -Path $ENV:PACKAGEINFODIR "$($artifactPackageName).json"
40+
if ($packageInfoFiles) {
41+
if ($packageInfoFiles.Length -gt 1) {
42+
LogWarning "Multiple PackageInfo files found for $artifactPackageName, using the first one."
43+
}
44+
} else {
45+
LogError "No PackageInfo file found for $artifactPackageName"
46+
}
47+
}
48+
} else {
49+
[array]$packageInfoFiles = Get-ChildItem -Path $ENV:PACKAGEINFODIR "*.json"
50+
}
2751
foreach($packageInfoFile in $packageInfoFiles) {
2852
$packageInfoJson = Get-Content $packageInfoFile -Raw
2953
$packageInfo = ConvertFrom-Json $packageInfoJson

eng/pipelines/templates/steps/generate-project-list-and-cache-maven-repository.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ steps:
3333
ServiceDirectory: ${{parameters.ServiceDirectory}}
3434
ExcludePaths: ${{parameters.ExcludePaths}}
3535

36-
# Create the ProjectList and ProjectListSha256 variables.
37-
# The ProjectList is used by subsequent steps and tasks to run CI.
38-
# The ProjectListSha256 is used by the cache key, previously the cache key was using ProjectList but it was found
39-
# that long cache keys cause caching to fail.
36+
# Create the ProjectList and ProjectListSha256 variables.
37+
# The ProjectList is used by subsequent steps and tasks to run CI.
38+
# The ProjectListSha256 is used by the cache key, previously the cache key was using ProjectList but it was found
39+
# that long cache keys cause caching to fail.
40+
41+
# ArtifactPackageNames is set by the generate test matrix and is only set for test runs. This needs to be
42+
# used to correctly set the project list and additional modules for what should be running for this particular
43+
# matrix run. The reason for this is that different service directories, like clientcore, have their own
44+
# default test matrix as compared to something like azure-template, which uses the default test matrix
4045
- task: PowerShell@2
4146
displayName: Initialize project list variable
4247
inputs:
@@ -46,6 +51,19 @@ steps:
4651
ARTIFACTSJSON: $(ArtifactsJson)
4752
ADDITIONALMODULESJSON: $(AdditionalModulesJson)
4853
PACKAGEINFODIR: $(Build.ArtifactStagingDirectory)/PackageInfo
54+
condition: eq(variables['ArtifactPackageNames'], '')
55+
56+
- task: PowerShell@2
57+
displayName: Initialize project list variable for PR test run
58+
inputs:
59+
pwsh: true
60+
filePath: eng/pipelines/scripts/generate-project-list.ps1
61+
env:
62+
ARTIFACTSJSON: $(ArtifactsJson)
63+
ADDITIONALMODULESJSON: $(AdditionalModulesJson)
64+
PACKAGEINFODIR: $(Build.ArtifactStagingDirectory)/PackageInfo
65+
ARTIFACTPACKAGENAMES: $(ArtifactPackageNames)
66+
condition: ne(variables['ArtifactPackageNames'], '')
4967

5068
# The Cache task, when restoring, can have a miss and still pass but, if nothing is built, the
5169
# Post-Job Cache will fail because there's no .m2/repository

0 commit comments

Comments
 (0)