Skip to content

Add batch generation parameter #28064

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 8 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
2 changes: 1 addition & 1 deletion .azure-pipelines/PipelineSteps/BatchGeneration/filter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $artifactsDir = Join-Path $RepoRoot 'artifacts'

$changedModulesDict = @{}
$changedSubModulesDict = @{}
if ($env:TEST_CHANGED_MODULES_ONLY -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ $notificationContent = $notificationTemplate -replace "{{ pipelineName }}", $pip
-replace "{{ pipelineUrl }}", $pipelineUrl `
-replace "{{ runUrl }}", $runUrl

$notificationReceivers = if ($env:NotificationReceiversOverride -and $env:NotificationReceiversOverride -ne 'none') { $env:NotificationReceiversOverride } else { $env:FailedJobNotificationReceivers }
Write-Host "Notification receivers: $notificationReceivers"

Send-Teams `
-to $env:FailedJobNotificationReceivers `
-to $notificationReceivers `
-title "Batch Generation Job Failed" `
-content $notificationContent
15 changes: 15 additions & 0 deletions .azure-pipelines/PipelineSteps/BatchGeneration/util.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ function Get-BatchGenerationModuleMap {
[string]$srcPath
)
$skippedModules = $env:SKIPPED_MODULES -split ',' | ForEach-Object { $_.Trim() }
$selectedTargetModules = @{}
if ($env:SELECTED_TARGET_MODULES -ne "none") {
$env:SELECTED_TARGET_MODULES -split ',' | ForEach-Object {
$key = $_.Trim()
if ($key -ne '') {
$selectedTargetModules[$key] = $true
}
}
}
$result = @{}
$modules = Get-ChildItem -Path $srcPath -Directory

Expand All @@ -11,6 +20,12 @@ function Get-BatchGenerationModuleMap {
Write-Warning "Skipping module: $($module.Name) as it is in the skipped modules list."
continue
}

if ($selectedTargetModules.Count -gt 0 -and -not $selectedTargetModules.ContainsKey($module.Name)) {
Write-Warning "Skipping module: $($module.Name) as it is not in the selected target modules list."
continue
}

$subModules = Get-ChildItem -Path $module.FullName -Directory | Where-Object {
$_.Name -like '*.autorest'
}
Expand Down
44 changes: 41 additions & 3 deletions .azure-pipelines/batch-generation.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
parameters:
- name: TestChangedModulesOnly
displayName: 'Only run tests on modules that are changed by regeneration'
type: boolean
default: true
# Selected modules to generate, build, analyze and test
- name: SelectedTargetModules
type: string
default: 'True'
default: 'None'
- name: NotificationReceiversOverride
type: string
default: 'None'
# branch from when creating the generation branch
- name: GenerationBaseBranch
type: string
default: 'main'
- name: PrepareModulesOnGenerationBranch
type: boolean
default: false

variables:
IntermediateStepTimeoutInMinutes: 30
Expand Down Expand Up @@ -39,6 +52,22 @@ stages:
pool: ${{ variables.WindowsAgentPoolName }}
steps:

- task: PowerShell@2
name: showVariables
displayName: 'Show Variables'
inputs:
targetType: inline
pwsh: true
script: |
Write-Host "Pipeline variable SkippedModules: $($env:SkippedModules)"
Write-Host "Pipeline variable FailedJobNotificationReceivers: $($env:FailedJobNotificationReceivers)"

Write-Host "Parameter TestChangedModulesOnly: ${{ parameters.TestChangedModulesOnly }}"
Write-Host "Parameter SelectedTargetModules: ${{ parameters.SelectedTargetModules }}"
Write-Host "Parameter NotificationReceiversOverride: ${{ parameters.NotificationReceiversOverride }}"
Write-Host "Parameter GenerationBaseBranch: ${{ parameters.GenerationBaseBranch }}"
Write-Host "Parameter PrepareModulesOnGenerationBranch: ${{ parameters.PrepareModulesOnGenerationBranch }}"

# TODO: (Bernard) Uncomment the no checkout step after automatically install repo into agents
# - checkout: none
- checkout: self
Expand All @@ -59,7 +88,7 @@ stages:
$token = "$(GitHubToken)"

$createBranchPath = Join-Path "$(Build.SourcesDirectory)" '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'create-branch.ps1'
& $createBranchPath -Owner 'Azure' -Repo 'azure-powershell' -BaseBranch "$(GenerationBaseBranch)" -NewBranch $generationBranch -Token $token
& $createBranchPath -Owner 'Azure' -Repo 'azure-powershell' -BaseBranch "${{ parameters.GenerationBaseBranch }}" -NewBranch $generationBranch -Token $token
Write-Host "##vso[task.setvariable variable=GenerationBranch;isOutput=true]$generationBranch"

- task: PowerShell@2
Expand All @@ -82,10 +111,18 @@ stages:
targetType: inline
pwsh: true
script: |
if ($env:PREPARE_MODULES_ON_GENERATION_BRANCH -eq 'true') {
Write-Host "Checkout to GenerationBranch: $(checkout.GenerationBranch)"
git fetch origin "$(checkout.GenerationBranch)"
git checkout "$(checkout.GenerationBranch)"
}

$prepareModulesPath = Join-Path "$(Build.SourcesDirectory)" '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'prepare.ps1'
& $prepareModulesPath -RepoRoot "$(Build.SourcesDirectory)" -MaxParallelJobs "${{ variables.MaxParallelGenerateJobs }}"
env:
SKIPPED_MODULES: $(SkippedModules)
SELECTED_TARGET_MODULES: ${{ parameters.SelectedTargetModules }}
PREPARE_MODULES_ON_GENERATION_BRANCH: ${{ parameters.PrepareModulesOnGenerationBranch }}

- task: PublishPipelineArtifact@1
displayName: 'Upload generated targets'
Expand Down Expand Up @@ -515,3 +552,4 @@ stages:
env:
TEAMS_URL: $(TEAMS_URL)
FailedJobNotificationReceivers: $(FailedJobNotificationReceivers)
NotificationReceiversOverride: ${{ parameters.NotificationReceiversOverride }}
Loading