Skip to content

Commit ece7ad9

Browse files
authored
Add batch generation parameter (#28064)
1 parent ecc95b3 commit ece7ad9

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $artifactsDir = Join-Path $RepoRoot 'artifacts'
1515

1616
$changedModulesDict = @{}
1717
$changedSubModulesDict = @{}
18-
if ($env:TEST_CHANGED_MODULES_ONLY -eq "True") {
18+
if ($env:TEST_CHANGED_MODULES_ONLY -eq 'true') {
1919
Write-Host "Run test on generated folder changed modules"
2020
# Only generated folder change should trigger the test
2121
for ($i = 0; $i -lt $ChangedFiles.Count; $i++) {

.azure-pipelines/PipelineSteps/BatchGeneration/notify-failed-job.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ $notificationContent = $notificationTemplate -replace "{{ pipelineName }}", $pip
1515
-replace "{{ pipelineUrl }}", $pipelineUrl `
1616
-replace "{{ runUrl }}", $runUrl
1717

18+
$notificationReceivers = if ($env:NotificationReceiversOverride -and $env:NotificationReceiversOverride -ne 'none') { $env:NotificationReceiversOverride } else { $env:FailedJobNotificationReceivers }
19+
Write-Host "Notification receivers: $notificationReceivers"
20+
1821
Send-Teams `
19-
-to $env:FailedJobNotificationReceivers `
22+
-to $notificationReceivers `
2023
-title "Batch Generation Job Failed" `
2124
-content $notificationContent

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ function Get-BatchGenerationModuleMap {
33
[string]$srcPath
44
)
55
$skippedModules = $env:SKIPPED_MODULES -split ',' | ForEach-Object { $_.Trim() }
6+
$selectedTargetModules = @{}
7+
if ($env:SELECTED_TARGET_MODULES -ne "none") {
8+
$env:SELECTED_TARGET_MODULES -split ',' | ForEach-Object {
9+
$key = $_.Trim()
10+
if ($key -ne '') {
11+
$selectedTargetModules[$key] = $true
12+
}
13+
}
14+
}
615
$result = @{}
716
$modules = Get-ChildItem -Path $srcPath -Directory
817

@@ -11,6 +20,12 @@ function Get-BatchGenerationModuleMap {
1120
Write-Warning "Skipping module: $($module.Name) as it is in the skipped modules list."
1221
continue
1322
}
23+
24+
if ($selectedTargetModules.Count -gt 0 -and -not $selectedTargetModules.ContainsKey($module.Name)) {
25+
Write-Warning "Skipping module: $($module.Name) as it is not in the selected target modules list."
26+
continue
27+
}
28+
1429
$subModules = Get-ChildItem -Path $module.FullName -Directory | Where-Object {
1530
$_.Name -like '*.autorest'
1631
}

.azure-pipelines/batch-generation.yml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
parameters:
22
- name: TestChangedModulesOnly
3-
displayName: 'Only run tests on modules that are changed by regeneration'
3+
type: boolean
4+
default: true
5+
# Selected modules to generate, build, analyze and test
6+
- name: SelectedTargetModules
47
type: string
5-
default: 'True'
8+
default: 'None'
9+
- name: NotificationReceiversOverride
10+
type: string
11+
default: 'None'
12+
# branch from when creating the generation branch
13+
- name: GenerationBaseBranch
14+
type: string
15+
default: 'main'
16+
- name: PrepareModulesOnGenerationBranch
17+
type: boolean
18+
default: false
619

720
variables:
821
IntermediateStepTimeoutInMinutes: 30
@@ -39,6 +52,22 @@ stages:
3952
pool: ${{ variables.WindowsAgentPoolName }}
4053
steps:
4154

55+
- task: PowerShell@2
56+
name: showVariables
57+
displayName: 'Show Variables'
58+
inputs:
59+
targetType: inline
60+
pwsh: true
61+
script: |
62+
Write-Host "Pipeline variable SkippedModules: $($env:SkippedModules)"
63+
Write-Host "Pipeline variable FailedJobNotificationReceivers: $($env:FailedJobNotificationReceivers)"
64+
65+
Write-Host "Parameter TestChangedModulesOnly: ${{ parameters.TestChangedModulesOnly }}"
66+
Write-Host "Parameter SelectedTargetModules: ${{ parameters.SelectedTargetModules }}"
67+
Write-Host "Parameter NotificationReceiversOverride: ${{ parameters.NotificationReceiversOverride }}"
68+
Write-Host "Parameter GenerationBaseBranch: ${{ parameters.GenerationBaseBranch }}"
69+
Write-Host "Parameter PrepareModulesOnGenerationBranch: ${{ parameters.PrepareModulesOnGenerationBranch }}"
70+
4271
# TODO: (Bernard) Uncomment the no checkout step after automatically install repo into agents
4372
# - checkout: none
4473
- checkout: self
@@ -59,7 +88,7 @@ stages:
5988
$token = "$(GitHubToken)"
6089
6190
$createBranchPath = Join-Path "$(Build.SourcesDirectory)" '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'create-branch.ps1'
62-
& $createBranchPath -Owner 'Azure' -Repo 'azure-powershell' -BaseBranch "$(GenerationBaseBranch)" -NewBranch $generationBranch -Token $token
91+
& $createBranchPath -Owner 'Azure' -Repo 'azure-powershell' -BaseBranch "${{ parameters.GenerationBaseBranch }}" -NewBranch $generationBranch -Token $token
6392
Write-Host "##vso[task.setvariable variable=GenerationBranch;isOutput=true]$generationBranch"
6493
6594
- task: PowerShell@2
@@ -82,10 +111,18 @@ stages:
82111
targetType: inline
83112
pwsh: true
84113
script: |
114+
if ($env:PREPARE_MODULES_ON_GENERATION_BRANCH -eq 'true') {
115+
Write-Host "Checkout to GenerationBranch: $(checkout.GenerationBranch)"
116+
git fetch origin "$(checkout.GenerationBranch)"
117+
git checkout "$(checkout.GenerationBranch)"
118+
}
119+
85120
$prepareModulesPath = Join-Path "$(Build.SourcesDirectory)" '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'prepare.ps1'
86121
& $prepareModulesPath -RepoRoot "$(Build.SourcesDirectory)" -MaxParallelJobs "${{ variables.MaxParallelGenerateJobs }}"
87122
env:
88123
SKIPPED_MODULES: $(SkippedModules)
124+
SELECTED_TARGET_MODULES: ${{ parameters.SelectedTargetModules }}
125+
PREPARE_MODULES_ON_GENERATION_BRANCH: ${{ parameters.PrepareModulesOnGenerationBranch }}
89126

90127
- task: PublishPipelineArtifact@1
91128
displayName: 'Upload generated targets'
@@ -515,3 +552,4 @@ stages:
515552
env:
516553
TEAMS_URL: $(TEAMS_URL)
517554
FailedJobNotificationReceivers: $(FailedJobNotificationReceivers)
555+
NotificationReceiversOverride: ${{ parameters.NotificationReceiversOverride }}

0 commit comments

Comments
 (0)