Skip to content

Commit 3ebe98f

Browse files
authored
Merge branch 'Azure:main' into main
2 parents fef67e0 + 6f62052 commit 3ebe98f

File tree

5,393 files changed

+576049
-246326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,393 files changed

+576049
-246326
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/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/prepare.ps1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $utilFilePath = Join-Path $RepoRoot '.azure-pipelines' 'PipelineSteps' 'BatchGen
88
Import-Module $utilFilePath -Force
99

1010
$srcPath = Join-Path $RepoRoot 'src'
11-
$moduleMap = Get-AutorestV4ModuleMap -srcPath $srcPath
11+
$moduleMap = Get-BatchGenerationModuleMap -srcPath $srcPath
1212
Write-Host "Total matched modules: $($moduleMap.Count)"
1313

1414
$modules = @($moduleMap.Keys | Sort-Object)
@@ -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: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
1-
function Get-AutorestV4ModuleMap {
1+
function Get-BatchGenerationModuleMap {
22
param (
33
[string]$srcPath
44
)
5-
5+
$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 = @{}
16+
$modules = Get-ChildItem -Path $srcPath -Directory
717

8-
Get-ChildItem -Path $srcPath -Directory | ForEach-Object {
9-
$module = $_
18+
foreach($module in $modules) {
19+
if ($skippedModules -contains $module.Name) {
20+
Write-Warning "Skipping module: $($module.Name) as it is in the skipped modules list."
21+
continue
22+
}
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+
}
1028

11-
Get-ChildItem -Path $module.FullName -Directory | Where-Object {
29+
$subModules = Get-ChildItem -Path $module.FullName -Directory | Where-Object {
1230
$_.Name -like '*.autorest'
13-
} | ForEach-Object {
14-
$subModule = $_
15-
31+
}
32+
foreach ($subModule in $subModules) {
33+
$tspPath = Join-Path $subModule.FullName 'tsp-location.yaml'
34+
if (Test-Path $tspPath){
35+
Write-Warning "tsp-location.yaml found in $($subModule.FullName), skipping."
36+
continue
37+
}
38+
1639
$readmePath = Join-Path $subModule.FullName 'README.md'
1740

1841
if (Test-Path $readmePath) {
@@ -66,18 +89,19 @@ function Write-Matrix {
6689
[string]$RepoRoot
6790
)
6891

69-
Write-Host "$VariableName module groups: $($GroupedModules.Count)"
70-
$GroupedModules | ForEach-Object { $_ -join ', ' } | ForEach-Object { Write-Host $_ }
71-
92+
Write-Host "##[group]$VariableName module groups: $($GroupedModules.Count)"
7293
$targets = @{}
7394
$MatrixStr = ""
7495
$index = 0
7596
foreach ($modules in $GroupedModules) {
7697
$key = ($index + 1).ToString() + "-" + $modules.Count
7798
$MatrixStr = "$MatrixStr,'$key':{'MatrixKey':'$key'}"
7899
$targets[$key] = $modules
100+
$moduleNamesStr = $modules -join ', '
101+
Write-Host "$key : $moduleNamesStr"
79102
$index++
80103
}
104+
Write-Host "##[endgroup]"
81105

82106
if ($MatrixStr -and $MatrixStr.Length -gt 1) {
83107
$MatrixStr = $MatrixStr.Substring(1)
@@ -91,6 +115,7 @@ function Write-Matrix {
91115
}
92116
$targetsOutputFile = Join-Path $targetsOutputDir "$VariableName.json"
93117
$targets | ConvertTo-Json -Depth 5 | Out-File -FilePath $targetsOutputFile -Encoding utf8
118+
Write-Host
94119
}
95120

96121
function Get-Targets {

.azure-pipelines/batch-generation.yml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
parameters:
2+
- name: TestChangedModulesOnly
3+
type: boolean
4+
default: true
5+
# Selected modules to generate, build, analyze and test
6+
- name: SelectedTargetModules
7+
type: string
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
19+
120
variables:
221
IntermediateStepTimeoutInMinutes: 30
322
GenerateTimeoutInMinutes: 120
@@ -33,6 +52,22 @@ stages:
3352
pool: ${{ variables.WindowsAgentPoolName }}
3453
steps:
3554

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+
3671
# TODO: (Bernard) Uncomment the no checkout step after automatically install repo into agents
3772
# - checkout: none
3873
- checkout: self
@@ -53,7 +88,7 @@ stages:
5388
$token = "$(GitHubToken)"
5489
5590
$createBranchPath = Join-Path "$(Build.SourcesDirectory)" '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'create-branch.ps1'
56-
& $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
5792
Write-Host "##vso[task.setvariable variable=GenerationBranch;isOutput=true]$generationBranch"
5893
5994
- task: PowerShell@2
@@ -76,8 +111,18 @@ stages:
76111
targetType: inline
77112
pwsh: true
78113
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+
79120
$prepareModulesPath = Join-Path "$(Build.SourcesDirectory)" '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'prepare.ps1'
80121
& $prepareModulesPath -RepoRoot "$(Build.SourcesDirectory)" -MaxParallelJobs "${{ variables.MaxParallelGenerateJobs }}"
122+
env:
123+
SKIPPED_MODULES: $(SkippedModules)
124+
SELECTED_TARGET_MODULES: ${{ parameters.SelectedTargetModules }}
125+
PREPARE_MODULES_ON_GENERATION_BRANCH: ${{ parameters.PrepareModulesOnGenerationBranch }}
81126

82127
- task: PublishPipelineArtifact@1
83128
displayName: 'Upload generated targets'
@@ -212,7 +257,7 @@ stages:
212257
-ChangedFiles $changedFiles `
213258
-RepoRoot "$(Build.SourcesDirectory)"
214259
env:
215-
RUN_TEST_ON_ALL_MODULES: $(RUN_TEST_ON_ALL_MODULES)
260+
TEST_CHANGED_MODULES_ONLY: ${{ parameters.TestChangedModulesOnly }}
216261

217262
- task: PublishPipelineArtifact@1
218263
displayName: 'Upload filtered targets'
@@ -507,3 +552,4 @@ stages:
507552
env:
508553
TEAMS_URL: $(TEAMS_URL)
509554
FailedJobNotificationReceivers: $(FailedJobNotificationReceivers)
555+
NotificationReceiversOverride: ${{ parameters.NotificationReceiversOverride }}

0 commit comments

Comments
 (0)