Skip to content

Commit da6c9aa

Browse files
committed
Batch generation
1 parent 606a9be commit da6c9aa

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
[CmdletBinding(DefaultParameterSetName="AllSet")]
2+
param (
3+
[string]$RepoRoot,
4+
[int]$MaxParallelJobs = 3
5+
)
6+
7+
$moduleRoot = Join-Path $RepoRoot 'src'
8+
$subModules = @()
9+
10+
Get-ChildItem -Path $moduleRoot -Directory | ForEach-Object {
11+
$module = $_
12+
Get-ChildItem -Path $module.FullName -Directory | Where-Object {
13+
$_.Name -like '*.autorest'
14+
} | ForEach-Object {
15+
$sub_module = $_
16+
$subModules += ,@($module.Name, $sub_module.Name)
17+
}
18+
}
19+
20+
$subModules = @(
21+
# V3
22+
@("Cdn","Cdn.Autorest"),
23+
@("ImageBuilder", "ImageBuilder.Autorest"),
24+
25+
# V4
26+
@("Chaos", "Chaos.Autorest"),
27+
@("DeviceRegistry", "DeviceRegistry.Autorest"),
28+
@("Astro", "Astro.Autorest"),
29+
30+
# V4 Multi sub-modules
31+
@("Communication","EmailService.Autorest"),
32+
@("Communication", "EmailServicedata.Autorest")
33+
)
34+
35+
Write-Host "Total matched sub modules: $($subModules.Count)"
36+
37+
function Split-List {
38+
param (
39+
[array]$subModules,
40+
[int]$maxParallelJobs
41+
)
42+
43+
$count = $subModules.Count
44+
$n = [Math]::Min($count, $maxParallelJobs)
45+
if ($n -eq 0) {
46+
return @()
47+
}
48+
49+
$result = @()
50+
$sizePerGroup = [Math]::Ceiling($count / $n)
51+
52+
for ($i = 0; $i -lt $count; $i += $sizePerGroup) {
53+
$group = $subModules[$i..([Math]::Min($i + $sizePerGroup - 1, $count - 1))]
54+
$result += ,$group
55+
}
56+
57+
return $result
58+
}
59+
60+
$devidedSubModules = Split-List -subModules $subModules -maxParallelJobs $MaxParallelJobs
61+
62+
Write-Host "Total matched devides: $($devidedSubModules.Count)"
63+
64+
$index = 0
65+
foreach ($subModules in $devidedSubModules) {
66+
Write-Host "Outer Group ${index}:"
67+
$subIndex = 0
68+
foreach ($subModule in $subModules) {
69+
Write-Host "Inner Group ${subIndex}: $($subModule -join ',')"
70+
$subIndex++
71+
}
72+
73+
$moduleNames = $subModules | ForEach-Object { $_[0] }
74+
75+
$MatrixStr="$MatrixStr,'" + $($index + 1) + "-" + $($subModules.Count) + "':{'Target':$($moduleNames -join ',')}"
76+
77+
$index++
78+
}
79+
80+
$MatrixStr=$MatrixStr.Substring(1)
81+
Write-Host "##vso[task.setVariable variable=Targets;isOutput=true]{$MatrixStr}"

.azure-pipelines/batch-generation.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
variables:
2+
3+
BuildTimeoutInMinutes: 120
4+
AnalysisTimeoutInMinutes: 120
5+
MaxParallelJobs: 3
6+
7+
trigger: none
8+
9+
jobs:
10+
- job: prepare
11+
displayName: Generate Matrix
12+
pool: pool-ubuntu-2004
13+
steps:
14+
- checkout: self
15+
persistCredentials: true
16+
clean: true
17+
ref: refs/heads/main
18+
19+
- task: PowerShell@2
20+
displayName: 'Create Batch Generation Branch'
21+
inputs:
22+
targetType: inline
23+
script: |
24+
$newBranch = "batch-generation/branch-$(Build.BuildId)"
25+
git checkout -b $newBranch
26+
git push origin $newBranch
27+
28+
- task: PowerShell@2
29+
name: mtrx
30+
displayName: 'Generate Matrix'
31+
inputs:
32+
targetType: inline
33+
script: |
34+
$prepareModulesPath = Join-Path "$(Build.SourcesDirectory)" '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'prepare.ps1'
35+
& $prepareModulesPath -RepoRoot "$(Build.SourcesDirectory)" -MaxParallelJobs "${{ variables.MaxParallelJobs }}"
36+
37+
38+
- job: build
39+
displayName: "Build:"
40+
dependsOn: prepare
41+
timeoutInMinutes: 120
42+
pool: pool-windows-2019
43+
strategy:
44+
matrix: $[ dependencies.prepare.outputs['mtrx.Targets'] ]
45+
maxParallel: 15
46+
47+
steps:
48+
- checkout: self
49+
persistCredentials: true
50+
clean: true
51+
ref: "batch-generation/branch-$(Build.BuildId)"
52+
53+
- task: PowerShell@2
54+
name: build
55+
displayName: 'Build Targets'
56+
inputs:
57+
targetType: inline
58+
script: |
59+
Write-Host "Building targets: ${Target}"
60+
$buildModulesPath = Join-Path "$(Build.SourcesDirectory)" 'tools' 'BuildScripts' 'BuildModules.ps1'
61+
& $buildModulesPath -TargetModule $($Target -split ',')
62+

.azure-pipelines/test.ps1

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
$RepoRoot = Get-Location
3+
$buildProjPath = Join-Path $RepoRoot 'build.proj'
4+
5+
$filesChangedOutputPath = Join-Path $RepoRoot 'artifacts' 'FilesChanged.txt'
6+
$subTasksFilePath = Join-Path $RepoRoot 'artifacts' 'SubTasksFile.txt'
7+
$IsSecurityCheck = $null
8+
9+
dotnet msbuild $buildProjPath /t:FilterBuild "/p:FilesChangedOutputPath=$FilesChangedOutputPath;SubTasksFilePath=$SubTasksFilePath;IsSecurityCheck=$IsSecurityCheck"

0 commit comments

Comments
 (0)