Skip to content

Fix batch generation build artifact #27945

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ foreach ($moduleName in $moduleGroup) {
$result.Status = "Failed"
$result.Error = $_.Exception.Message
} finally {
$endTine = Get-Date
$result.DurationSeconds = ($endTine - $startTime).TotalSeconds
$endTime = Get-Date
$result.DurationSeconds = ($endTime - $startTime).TotalSeconds
$results += $result
$result | ConvertTo-Json -Depth 5 | Write-Output
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ foreach ($moduleName in $sortedModuleNames) {
$moduleEndTime = Get-Date
$moduleResult.DurationSeconds = ($moduleEndTime - $moduleStartTime).TotalSeconds
$results += $moduleResult
$moduleResult | ConvertTo-Json -Depth 5 | Write-Output
}

$ArtifactOutputDir = Join-Path $RepoRoot "artifacts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ foreach ($moduleName in $moduleGroup) {
$result.Status = "Failed"
$result.Error = $_.Exception.Message
} finally {
$endTine = Get-Date
$result.DurationSeconds = ($endTine - $startTime).TotalSeconds
$endTime = Get-Date
$result.DurationSeconds = ($endTime - $startTime).TotalSeconds
$results += $result
$result | ConvertTo-Json -Depth 5 | Write-Output
}
}

Expand Down
35 changes: 20 additions & 15 deletions .azure-pipelines/PipelineSteps/BatchGeneration/filter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@ $artifactsDir = Join-Path $RepoRoot 'artifacts'

$changedModulesDict = @{}
$changedSubModulesDict = @{}
if ($env:RUN_TEST_ON_ALL_MODULES -eq "True") {
if ($env:TEST_CHANGED_MODULES_ONLY -eq "True") {
Write-Host "Run test on generated folder changed modules"
# Only generated folder change should trigger the test
for ($i = 0; $i -lt $ChangedFiles.Count; $i++) {
if ($ChangedFiles[$i] -match '^generated/([^/]+)/([^/]+\.Autorest)/') {
$moduleName = $Matches[1]
$subModuleName = $Matches[2]
$subModule = "$moduleName/$subModuleName"

$changedModulesDict[$moduleName] = $true
$changedSubModulesDict[$subModule] = $true
}
}
}
else {
Write-Host "Run test on all modules"
$V4ModulesFile = Join-Path $artifactsDir "generationTargets.json"
$V4ModuleMaps = Get-Content -Raw -Path $V4ModulesFile | ConvertFrom-Json
Expand All @@ -31,20 +45,6 @@ if ($env:RUN_TEST_ON_ALL_MODULES -eq "True") {
}
}
}
else {
Write-Host "Run test on generated folder changed modules"
# Only generated folder change should trigger the test
for ($i = 0; $i -lt $ChangedFiles.Count; $i++) {
if ($ChangedFiles[$i] -match '^generated/([^/]+)/([^/]+\.autorest)/') {
$moduleName = $Matches[2]
$subModuleName = $Matches[3]
$subModule = "$moduleName/$subModuleName"

$changedModulesDict[$moduleName] = $true
$changedSubModulesDict[$subModule] = $true
}
}
}

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

$changedModulesRecordFile = Join-Path $artifactsDir 'filteredChangedModules.txt'
$changedModules | Set-Content -Path $changedModulesRecordFile -Encoding UTF8
$changedSubModulesRecordFile = Join-Path $artifactsDir 'filteredChangedSubModules.txt'
$changedSubModules | Set-Content -Path $changedSubModulesRecordFile -Encoding UTF8

$groupedBuildModules = Group-Modules -Modules $changedModules -MaxParallelJobs $MaxParallelBuildJobs
Write-Matrix -GroupedModules $groupedBuildModules -VariableName 'buildTargets' -RepoRoot $RepoRoot

Expand Down
11 changes: 7 additions & 4 deletions .azure-pipelines/PipelineSteps/BatchGeneration/prepare.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ foreach ($moduleGroup in $groupedModules) {
$index++
}

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

if ($MatrixStr -and $MatrixStr.Length -gt 1) {
$MatrixStr = $MatrixStr.Substring(1)
}
Write-Host "##vso[task.setVariable variable=generationTargets;isOutput=true]{$MatrixStr}"

$V4ModulesRecordFile = Join-Path $artifactsDir 'preparedV4Modules.txt'
$modules | Set-Content -Path $V4ModulesRecordFile -Encoding UTF8
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ foreach ($subModule in $subModuleGroup) {
$endTime = Get-Date
$result.DurationSeconds = ($endTime - $startTime).TotalSeconds
$results += $result
$result | ConvertTo-Json -Depth 5 | Write-Output
}
}

Expand Down
8 changes: 5 additions & 3 deletions .azure-pipelines/PipelineSteps/BatchGeneration/util.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,19 @@ function Write-Matrix {
[string]$RepoRoot
)

Write-Host "$VariableName module groups: $($GroupedModules.Count)"
$GroupedModules | ForEach-Object { $_ -join ', ' } | ForEach-Object { Write-Host $_ }

Write-Host "##[group]$VariableName module groups: $($GroupedModules.Count)"
$targets = @{}
$MatrixStr = ""
$index = 0
foreach ($modules in $GroupedModules) {
$key = ($index + 1).ToString() + "-" + $modules.Count
$MatrixStr = "$MatrixStr,'$key':{'MatrixKey':'$key'}"
$targets[$key] = $modules
$moduleNamesStr = $modules -join ', '
Write-Host "$key : $moduleNamesStr"
$index++
}
Write-Host "##[endgroup]"

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

function Get-Targets {
Expand Down
8 changes: 7 additions & 1 deletion .azure-pipelines/batch-generation.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
parameters:
- name: TestChangedModulesOnly
displayName: 'Only run tests on modules that are changed by regeneration'
type: string
default: 'True'

variables:
IntermediateStepTimeoutInMinutes: 30
GenerateTimeoutInMinutes: 120
Expand Down Expand Up @@ -212,7 +218,7 @@ stages:
-ChangedFiles $changedFiles `
-RepoRoot "$(Build.SourcesDirectory)"
env:
RUN_TEST_ON_ALL_MODULES: $(RUN_TEST_ON_ALL_MODULES)
TEST_CHANGED_MODULES_ONLY: ${{ parameters.TestChangedModulesOnly }}

- task: PublishPipelineArtifact@1
displayName: 'Upload filtered targets'
Expand Down
Loading