Skip to content

Commit 9d33608

Browse files
azure-powershell-botazurepowershell
andauthored
Sync tools folder from main branch to generation branch (#24630)
Co-authored-by: azurepowershell <[email protected]>
1 parent a71c1b2 commit 9d33608

File tree

2 files changed

+231
-1
lines changed

2 files changed

+231
-1
lines changed

.azure-pipelines/refresh-autorest.yml

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
parameters:
2+
- name: targetBranch
3+
displayName: Target branch where the PR will be submitted
4+
type: string
5+
default: main
6+
7+
- name: scope
8+
displayName: Select target Autorest modules
9+
type: string
10+
default: autorest-all
11+
values:
12+
- autorest-all
13+
- autorest-v3-only
14+
- autorest-v4-only
15+
- autorest-selected
16+
17+
- name: selectedServices
18+
displayName: Input service names you want to refresh separated by semi-colon (;). Wildcard match is supported.
19+
type: string
20+
default: ' '
21+
22+
- name: changeLogMessage
23+
displayName: Input change log message for the Autorest modules
24+
type: string
25+
26+
pr: none
27+
trigger: none
28+
29+
jobs:
30+
- job:
31+
displayName: Refresh Autorest Modules
32+
timeoutInMinutes: 360
33+
pool: pool-windows-2019
34+
steps:
35+
- template: util/get-github-pat-steps.yml
36+
37+
- task: NodeTool@0
38+
displayName: Use Node 14.15.5
39+
inputs:
40+
versionSpec: 14.15.5
41+
42+
- task: Npm@1
43+
displayName: Install Autorest
44+
inputs:
45+
command: custom
46+
verbose: false
47+
customCommand: install autorest@latest -g
48+
49+
- task: PowerShell@2
50+
displayName: Get services list
51+
inputs:
52+
pwsh: true
53+
targetType: inline
54+
workingDirectory: ./src
55+
script: |
56+
$autorestPaths = @()
57+
$autorestModules = Get-ChildItem -Filter "*.Autorest" -Directory -Recurse | Select-Object -ExpandProperty FullName
58+
if ("${{ parameters.scope }}" -eq "autorest-v3-v4") {
59+
$autorestPaths = $autorestModules
60+
}
61+
elseif ("${{ parameters.scope }}" -eq "autorest-selected") {
62+
$selectedModulesList = '${{ parameters.selectedServices }}'
63+
if (![System.String]::IsNullOrWhiteSpace($selectedModulesList)) {
64+
$selectedModulePatterns = $selectedModulesList -split ";"
65+
$autorestPaths = $selectedModulePatterns | Foreach-Object {
66+
$modulePattern = $_.Trim()
67+
$autorestModules | Where-Object {
68+
$modulePath = Split-Path -Path $_ -Parent
69+
$moduleName = (Get-Item -Path $modulePath).Name
70+
$moduleName -like $modulePattern
71+
}
72+
}
73+
}
74+
}
75+
else {
76+
$isV3Only = "${{ parameters.scope }}" -eq "autorest-v3-only"
77+
$isV4Only = "${{ parameters.scope }}" -eq "autorest-v4-only"
78+
$readmeMDs = $autorestModules | Get-ChildItem -Filter "README.md" -File
79+
$readmeMDs | Foreach-Object {
80+
$content = Get-Content -Path $_ -Raw
81+
$pattern = 'use-extension:\s*"@autorest/powershell":\s*"([^"]+)"'
82+
if ($content -match $pattern) {
83+
$version = $Matches[1].Substring(0, 1)
84+
if (($version -eq "3" -and $isV3Only) -or ($version -eq "4" -and $isV4Only)) {
85+
$autorestPaths += $_.Directory.FullName
86+
}
87+
}
88+
elseif ($isV4Only) {
89+
$autorestPaths += $_.Directory.FullName
90+
}
91+
}
92+
}
93+
94+
$autorestPaths = $autorestPaths | Sort-Object -Unique
95+
Write-Host "##[section]Autorest modules to refresh: `n`t$($autorestPaths -join "`n`t")"
96+
$autorestPathsList = $autorestPaths -join ";"
97+
Write-Host "##vso[task.setvariable variable=selectedAutorestPaths;isreadonly=true]$autorestPathsList"
98+
99+
- task: PowerShell@2
100+
displayName: Generate & Build
101+
inputs:
102+
pwsh: true
103+
targetType: inline
104+
script: |
105+
# Autorest and build the modules
106+
'$(selectedAutorestPaths)'.Split(";") | Foreach-Object {
107+
Write-Host "##[group]Start generating module $_"
108+
109+
Set-Location -Path $_
110+
111+
Write-Host "##[section]Start running autorest command."
112+
autorest --max-memory-size=8192
113+
Write-Host "##[section]Finish running autorest command."
114+
115+
Write-Host "##[section]Start building the module."
116+
./build-module.ps1
117+
Write-Host "##[section]Finish building the module."
118+
119+
Write-Host "##[endgroup]"
120+
Write-Host
121+
}
122+
123+
# Backup the modules in the artifacts folder and restore the changes
124+
$modules = '$(selectedAutorestPaths)' -split ";" | Foreach-Object { Split-Path -Path $_ -Parent } | Select-Object -Unique
125+
$modules | Foreach-Object {
126+
Write-Host "##[group]Start backing up module $_"
127+
128+
Set-Location -Path $_
129+
$servicePath = Get-Item -Path .
130+
$serviceName = $servicePath.Name
131+
132+
Write-Host "##[section]Start copying content to artifacts."
133+
New-Item -Path ../../artifacts/src/$serviceName -ItemType Directory
134+
Copy-Item -Path ./* -Destination ../../artifacts/src/$serviceName -Recurse
135+
Write-Host "##[section]Finish copying content to artifacts."
136+
137+
Set-Location ..
138+
139+
Write-Host "##[section]Start restoring the changes."
140+
Remove-Item -Path ./$serviceName -Recurse -Force
141+
git checkout $serviceName/
142+
Write-Host "##[section]Finish restoring the changes."
143+
144+
Write-Host "##[endgroup]"
145+
Write-Host
146+
}
147+
148+
Set-Location ..
149+
git checkout -b 'codegen/${{ parameters.scope }}' 'origin/${{ parameters.targetBranch }}'
150+
151+
- task: PowerShell@2
152+
displayName: Migrate from generation to target branch
153+
inputs:
154+
pwsh: true
155+
targetType: inline
156+
script: |
157+
Install-Module -Name PowerShellGet -RequiredVersion 2.2.3 -Force
158+
Install-Module -Name platyPS -RequiredVersion 0.14.2 -Force
159+
Install-Module -Name Az.Accounts -Force
160+
Import-Module ./tools/Gen2Master/MoveFromGeneration2Master.ps1
161+
162+
$modules = '$(selectedAutorestPaths)' -split ";" | Foreach-Object { Split-Path -Path $_ -Parent } | Select-Object -Unique
163+
$modules | Foreach-Object {
164+
Write-Host "##[group]Start migrating module $_"
165+
166+
Set-Location -Path $_
167+
$servicePath = Get-Item -Path .
168+
$serviceName = $servicePath.Name
169+
170+
Write-Host "##[section]Start migrating from generation to target."
171+
Move-Generation2Master -SourcePath ../../artifacts/src/$serviceName -DestPath .
172+
Write-Host "##[section]Finish migrating from generation to target."
173+
174+
Write-Host "##[section]Start updating change log for module."
175+
$changeLog = $servicePath | Get-ChildItem -Filter "ChangeLog.md" -File -Recurse | Select-Object -First 1
176+
$changeLogPath = $changeLog.FullName
177+
$changeLogMessage = '${{ parameters.changeLogMessage }}'
178+
(Get-Content -Path $changeLogPath -Raw) -replace "`n## Upcoming Release", ("`n## Upcoming Release`n" + "* $changeLogMessage") | Set-Content -Path $changeLogPath -NoNewline
179+
Write-Host "##[section]Finish updating change log for module."
180+
181+
Write-Host "##[endgroup]"
182+
Write-Host
183+
}
184+
185+
- task: PowerShell@2
186+
displayName: Create PR to target branch
187+
inputs:
188+
pwsh: true
189+
targetType: inline
190+
script: |
191+
$sourceBranch = '$(Build.SourceBranch)'.Replace("refs/heads/", "")
192+
$headBranch = 'codegen/${{ parameters.scope }}'
193+
$baseBranch = '${{ parameters.targetBranch }}'
194+
git config user.email "[email protected]"
195+
git config user.name "azure-powershell-bot"
196+
git add src
197+
git add tools/CreateMappings_rules.json
198+
git commit -m "Refresh ${{ parameters.scope }} modules from $sourceBranch to $baseBranch"
199+
git remote set-url origin https://azure-powershell-bot:$(GithubToken)@github.com/Azure/azure-powershell.git
200+
git push origin $headBranch --force
201+
202+
$title = "Refresh ${{ parameters.scope }} modules from $sourceBranch to $baseBranch"
203+
$description = "Refresh ${{ parameters.scope }} modules from $sourceBranch to $baseBranch."
204+
if ("${{ parameters.scope }}" -eq "autorest-selected") {
205+
$description = "$description `nSelected services are: ${{ parameters.selectedServices }}."
206+
}
207+
208+
./tools/Github/CreatePR.ps1 -Title $title -HeadBranch $headBranch -BaseBranch $baseBranch -BotAccessToken $(GithubToken) -Description $description

tools/StaticAnalysis/GeneratedSdkAnalyzer/SDKGeneratedCodeVerify.ps1

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ try {
8686
Write-Host "Preparing Autorest..."
8787
npx autorest --reset
8888
foreach ($_ in $ChangedSdks) {
89+
# If it is Resources.Management.Sdk, flag and will use tag for sdk generation
90+
$IsResources = $false;
91+
if ($_ -match "Resources.Management.Sdk")
92+
{
93+
$IsResources = $true;
94+
}
95+
8996
# Extract Module Name
9097
$ModuleName = "Az." + ($_ -split "\/|\\")[1]
9198

@@ -107,7 +114,22 @@ try {
107114
if ([regex]::Matches($readMeContent, '\s*powershell\s*:\s*true\s*') -and [regex]::Matches($readMeContent, '\s*isSdkGenerator\s*:\s*true\s*'))
108115
{
109116
Write-Host "Using autorest powershell v4:`nRe-generating SDK under Generated folder for $ModuleName..."
110-
npx autorest
117+
if ($IsResources)
118+
{
119+
Write-Host "Specific generation for Resources.Management.Sdk"
120+
rm -r Generated/*
121+
npx autorest --use:@autorest/powershell@4.x --tag=package-privatelinks-2020-05
122+
npx autorest --use:@autorest/powershell@4.x --tag=package-subscriptions-2021-01
123+
npx autorest --use:@autorest/powershell@4.x --tag=package-features-2021-07
124+
npx autorest --use:@autorest/powershell@4.x --tag=package-deploymentscripts-2020-10
125+
npx autorest --use:@autorest/powershell@4.x --tag=package-resources-2021-04
126+
npx autorest --use:@autorest/powershell@4.x --tag=package-deploymentstacks-2022-08-preview
127+
npx autorest --use:@autorest/powershell@4.x --tag=package-templatespecs-2021-05
128+
}
129+
else
130+
{
131+
npx autorest
132+
}
111133
}
112134
elseif ([regex]::Matches($readMeContent, '\s*csharp\s*:\s*true\s*'))
113135
{

0 commit comments

Comments
 (0)