Skip to content

Commit 3bb1042

Browse files
authored
Fix batch generation build artifact (#27945)
1 parent fa94f8a commit 3bb1042

File tree

8 files changed

+47
-27
lines changed

8 files changed

+47
-27
lines changed

.azure-pipelines/PipelineSteps/BatchGeneration/analyse-modules.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ foreach ($moduleName in $moduleGroup) {
8282
$result.Status = "Failed"
8383
$result.Error = $_.Exception.Message
8484
} finally {
85-
$endTine = Get-Date
86-
$result.DurationSeconds = ($endTine - $startTime).TotalSeconds
85+
$endTime = Get-Date
86+
$result.DurationSeconds = ($endTime - $startTime).TotalSeconds
8787
$results += $result
88+
$result | ConvertTo-Json -Depth 5 | Write-Output
8889
}
8990
}
9091

.azure-pipelines/PipelineSteps/BatchGeneration/batch-generate-modules.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ foreach ($moduleName in $sortedModuleNames) {
113113
$moduleEndTime = Get-Date
114114
$moduleResult.DurationSeconds = ($moduleEndTime - $moduleStartTime).TotalSeconds
115115
$results += $moduleResult
116+
$moduleResult | ConvertTo-Json -Depth 5 | Write-Output
116117
}
117118

118119
$ArtifactOutputDir = Join-Path $RepoRoot "artifacts"

.azure-pipelines/PipelineSteps/BatchGeneration/build-modules.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ foreach ($moduleName in $moduleGroup) {
3030
$result.Status = "Failed"
3131
$result.Error = $_.Exception.Message
3232
} finally {
33-
$endTine = Get-Date
34-
$result.DurationSeconds = ($endTine - $startTime).TotalSeconds
33+
$endTime = Get-Date
34+
$result.DurationSeconds = ($endTime - $startTime).TotalSeconds
3535
$results += $result
36+
$result | ConvertTo-Json -Depth 5 | Write-Output
3637
}
3738
}
3839

.azure-pipelines/PipelineSteps/BatchGeneration/filter.ps1

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,21 @@ $artifactsDir = Join-Path $RepoRoot 'artifacts'
1515

1616
$changedModulesDict = @{}
1717
$changedSubModulesDict = @{}
18-
if ($env:RUN_TEST_ON_ALL_MODULES -eq "True") {
18+
if ($env:TEST_CHANGED_MODULES_ONLY -eq "True") {
19+
Write-Host "Run test on generated folder changed modules"
20+
# Only generated folder change should trigger the test
21+
for ($i = 0; $i -lt $ChangedFiles.Count; $i++) {
22+
if ($ChangedFiles[$i] -match '^generated/([^/]+)/([^/]+\.Autorest)/') {
23+
$moduleName = $Matches[1]
24+
$subModuleName = $Matches[2]
25+
$subModule = "$moduleName/$subModuleName"
26+
27+
$changedModulesDict[$moduleName] = $true
28+
$changedSubModulesDict[$subModule] = $true
29+
}
30+
}
31+
}
32+
else {
1933
Write-Host "Run test on all modules"
2034
$V4ModulesFile = Join-Path $artifactsDir "generationTargets.json"
2135
$V4ModuleMaps = Get-Content -Raw -Path $V4ModulesFile | ConvertFrom-Json
@@ -31,20 +45,6 @@ if ($env:RUN_TEST_ON_ALL_MODULES -eq "True") {
3145
}
3246
}
3347
}
34-
else {
35-
Write-Host "Run test on generated folder changed modules"
36-
# Only generated folder change should trigger the test
37-
for ($i = 0; $i -lt $ChangedFiles.Count; $i++) {
38-
if ($ChangedFiles[$i] -match '^generated/([^/]+)/([^/]+\.autorest)/') {
39-
$moduleName = $Matches[2]
40-
$subModuleName = $Matches[3]
41-
$subModule = "$moduleName/$subModuleName"
42-
43-
$changedModulesDict[$moduleName] = $true
44-
$changedSubModulesDict[$subModule] = $true
45-
}
46-
}
47-
}
4848

4949
$changedModules = $changedModulesDict.Keys | Sort-Object
5050
$changedSubModules = $changedSubModulesDict.Keys | Sort-Object
@@ -63,6 +63,11 @@ foreach ($subModule in $changedSubModules) {
6363
Write-Host "##[endgroup]"
6464
Write-Host
6565

66+
$changedModulesRecordFile = Join-Path $artifactsDir 'filteredChangedModules.txt'
67+
$changedModules | Set-Content -Path $changedModulesRecordFile -Encoding UTF8
68+
$changedSubModulesRecordFile = Join-Path $artifactsDir 'filteredChangedSubModules.txt'
69+
$changedSubModules | Set-Content -Path $changedSubModulesRecordFile -Encoding UTF8
70+
6671
$groupedBuildModules = Group-Modules -Modules $changedModules -MaxParallelJobs $MaxParallelBuildJobs
6772
Write-Matrix -GroupedModules $groupedBuildModules -VariableName 'buildTargets' -RepoRoot $RepoRoot
6873

.azure-pipelines/PipelineSteps/BatchGeneration/prepare.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ foreach ($moduleGroup in $groupedModules) {
3434
$index++
3535
}
3636

37-
$generationTargetsOutputDir = Join-Path $RepoRoot "artifacts"
38-
if (-not (Test-Path -Path $generationTargetsOutputDir)) {
39-
New-Item -ItemType Directory -Path $generationTargetsOutputDir
37+
$artifactsDir = Join-Path $RepoRoot "artifacts"
38+
if (-not (Test-Path -Path $artifactsDir)) {
39+
New-Item -ItemType Directory -Path $artifactsDir
4040
}
41-
$generationTargetsOutputFile = Join-Path $generationTargetsOutputDir "generationTargets.json"
41+
$generationTargetsOutputFile = Join-Path $artifactsDir "generationTargets.json"
4242
$generationTargets | ConvertTo-Json -Depth 5 | Out-File -FilePath $generationTargetsOutputFile -Encoding utf8
4343

4444
if ($MatrixStr -and $MatrixStr.Length -gt 1) {
4545
$MatrixStr = $MatrixStr.Substring(1)
4646
}
4747
Write-Host "##vso[task.setVariable variable=generationTargets;isOutput=true]{$MatrixStr}"
48+
49+
$V4ModulesRecordFile = Join-Path $artifactsDir 'preparedV4Modules.txt'
50+
$modules | Set-Content -Path $V4ModulesRecordFile -Encoding UTF8

.azure-pipelines/PipelineSteps/BatchGeneration/test-modules.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ foreach ($subModule in $subModuleGroup) {
5656
$endTime = Get-Date
5757
$result.DurationSeconds = ($endTime - $startTime).TotalSeconds
5858
$results += $result
59+
$result | ConvertTo-Json -Depth 5 | Write-Output
5960
}
6061
}
6162

.azure-pipelines/PipelineSteps/BatchGeneration/util.psm1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,19 @@ function Write-Matrix {
6666
[string]$RepoRoot
6767
)
6868

69-
Write-Host "$VariableName module groups: $($GroupedModules.Count)"
70-
$GroupedModules | ForEach-Object { $_ -join ', ' } | ForEach-Object { Write-Host $_ }
71-
69+
Write-Host "##[group]$VariableName module groups: $($GroupedModules.Count)"
7270
$targets = @{}
7371
$MatrixStr = ""
7472
$index = 0
7573
foreach ($modules in $GroupedModules) {
7674
$key = ($index + 1).ToString() + "-" + $modules.Count
7775
$MatrixStr = "$MatrixStr,'$key':{'MatrixKey':'$key'}"
7876
$targets[$key] = $modules
77+
$moduleNamesStr = $modules -join ', '
78+
Write-Host "$key : $moduleNamesStr"
7979
$index++
8080
}
81+
Write-Host "##[endgroup]"
8182

8283
if ($MatrixStr -and $MatrixStr.Length -gt 1) {
8384
$MatrixStr = $MatrixStr.Substring(1)
@@ -91,6 +92,7 @@ function Write-Matrix {
9192
}
9293
$targetsOutputFile = Join-Path $targetsOutputDir "$VariableName.json"
9394
$targets | ConvertTo-Json -Depth 5 | Out-File -FilePath $targetsOutputFile -Encoding utf8
95+
Write-Host
9496
}
9597

9698
function Get-Targets {

.azure-pipelines/batch-generation.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
parameters:
2+
- name: TestChangedModulesOnly
3+
displayName: 'Only run tests on modules that are changed by regeneration'
4+
type: string
5+
default: 'True'
6+
17
variables:
28
IntermediateStepTimeoutInMinutes: 30
39
GenerateTimeoutInMinutes: 120
@@ -212,7 +218,7 @@ stages:
212218
-ChangedFiles $changedFiles `
213219
-RepoRoot "$(Build.SourcesDirectory)"
214220
env:
215-
RUN_TEST_ON_ALL_MODULES: $(RUN_TEST_ON_ALL_MODULES)
221+
TEST_CHANGED_MODULES_ONLY: ${{ parameters.TestChangedModulesOnly }}
216222

217223
- task: PublishPipelineArtifact@1
218224
displayName: 'Upload filtered targets'

0 commit comments

Comments
 (0)