36
36
[int ]$Parallelization = [Environment ]::ProcessorCount
37
37
)
38
38
39
+ $sdkFolder = Join-Path - Path $PSScriptRoot " .." " .." " sdk"
40
+
39
41
class GenerationInformation {
40
42
# The directory where the library is located. Used for logging and validation.
41
43
[string ]$LibraryFolder
@@ -59,11 +61,10 @@ class GenerationInformation {
59
61
function Find-GenerationInformation {
60
62
param (
61
63
[System.Collections.ArrayList ]$GenerationInformations ,
62
- [string ]$ServiceDirectory ,
63
- [string ]$RegenerationType
64
+ [string ]$LibraryFolder
64
65
)
65
66
66
- $path = " sdk/ $ServiceDirectory "
67
+ $path = Join-Path - Path $sdkFolder $LibraryFolder
67
68
if ($RegenerationType -eq ' Swagger' -or $RegenerationType -eq ' All' ) {
68
69
# Search for 'Update-Codegeneration.ps1' script in the specified service directory.
69
70
Get-ChildItem - Path $path - Filter " Update-Codegeneration.ps1" - Recurse | ForEach-Object {
@@ -99,46 +100,42 @@ foreach ($serviceDirectory in $ServiceDirectories.Split(',')) {
99
100
if ($serviceDirectory -match ' \w+/\w+' ) {
100
101
# The service directory is a specific library, e.g., "communication/azure-communication-chat"
101
102
# Search the directory directly for an "Update-Codegeneration.ps1" script.
102
- Find-GenerationInformation $generationInformations $serviceDirectory $RegenerationType
103
+ Find-GenerationInformation $generationInformations $serviceDirectory
103
104
} else {
104
105
# The service directory is a top-level service, e.g., "storage"
105
106
# Search for all libraries under the service directory.
106
- foreach ($libraryFolder in Get-ChildItem - Path " sdk/$serviceDirectory " - Directory) {
107
- Find-GenerationInformation $generationInformations " $serviceDirectory /$ ( $libraryFolder.Name ) " $RegenerationType
107
+ $searchPath = Join-Path - Path $sdkFolder $serviceDirectory
108
+ Get-ChildItem - Path $searchPath - Directory | ForEach-Object {
109
+ Find-GenerationInformation $generationInformations " $serviceDirectory /$ ( $_.Name ) "
108
110
}
109
111
}
110
112
}
111
113
112
114
if ($generationInformations.Count -eq 0 ) {
113
115
$kind = $RegenerationType -eq ' All' ? ' Swagger or TypeSpec' : $RegenerationType
114
- Write-Host @"
115
- ======================================
116
- No $kind generation files to regenerate in directories: $ServiceDirectories .
117
- ======================================
118
- "@
116
+ Write-Host " No $kind generation files to regenerate in directories: $ServiceDirectories ."
119
117
exit 0
120
118
}
121
119
122
120
if ($RegenerationType -eq ' Swagger' -or $RegenerationType -eq ' All' ) {
123
121
# Ensure Autorest is installed.
124
122
$output = (& npm install - g autorest 2>&1 )
125
123
if ($LASTEXITCODE -ne 0 ) {
126
- Write-Error " Failed to install Autorest for Swagger regeneration."
127
- Write-Error $output
124
+ Write-Error " Failed to install Autorest for Swagger regeneration.`n $output "
128
125
exit 1
129
126
}
130
127
}
131
128
132
129
if ($RegenerationType -eq ' TypeSpec' -or $RegenerationType -eq ' All' ) {
133
130
$output = (& npm install - g @azure - tools/ typespec- client- generator- cli 2>&1 )
134
131
if ($LASTEXITCODE -ne 0 ) {
135
- Write-Error " Error installing @azure-tools/typespec-client-generator-cli"
136
- Write-Error " $output "
132
+ Write-Error " Error installing @azure-tools/typespec-client-generator-cli`n $output "
137
133
exit 1
138
134
}
139
135
}
140
136
141
137
$generateScript = {
138
+ $separatorBar = " ======================================"
142
139
$directory = $_.LibraryFolder
143
140
$updateCodegenScript = $_.ScriptPath
144
141
@@ -147,85 +144,58 @@ $generateScript = {
147
144
$generateOutput = (& $updateCodegenScript 6>&1 )
148
145
149
146
if ($LastExitCode -ne 0 ) {
150
- Write-Host @"
151
- ======================================
152
- Error running Swagger regeneration $updateCodegenScript
153
- ======================================
154
- $ ( [String ]::Join(" `n " , $generateOutput ))
155
- "@
147
+ Write-Host " $separatorBar `n Error running Swagger regeneration $updateCodegenScript `n $ ( [String ]::Join(" `n " , $generateOutput )) `n $separatorBar "
156
148
throw
157
149
} else {
158
150
# prevent warning related to EOL differences which triggers an exception for some reason
159
151
(& git - c core.safecrlf= false diff -- ignore- space- at- eol -- exit-code -- " $directory /*.java" ) | Out-Null
160
152
161
153
if ($LastExitCode -ne 0 ) {
162
154
$status = (git status - s " $directory " | Out-String )
163
- Write-Host @"
164
- ======================================
165
- The following Swagger generated files in directoy $directory are out of date:
166
- ======================================
167
- $status
168
- "@
155
+ Write-Host " $separatorBar `n The following Swagger generated files in directoy $directory are out of date`n $status `n $separatorBar "
169
156
throw
170
157
} else {
171
- Write-Host @"
172
- ======================================
173
- Successfully ran Swagger regneration with no diff $updateCodegenScript
174
- ======================================
175
- "@
158
+ Write-Host " $separatorBar `n Successfully ran Swagger regneration with no diff $updateCodegenScript `n $separatorBar "
176
159
}
177
160
}
178
161
} elseif ($_.Type -eq ' TypeSpec' ) {
179
- Push-Location $Directory
162
+ Push-Location $directory
180
163
try {
181
- $generateOutput = (& tsp- client update 2>&1 )
182
- if ($LastExitCode -ne 0 ) {
183
- Write-Host @"
184
- ======================================
185
- Error running TypeSpec regeneration in directory $Directory
186
- ======================================
187
- $ ( [String ]::Join(" `n " , $generateOutput ))
188
- "@
189
- throw
164
+ try {
165
+ $generateOutput = (& tsp- client update 2>&1 )
166
+ if ($LastExitCode -ne 0 ) {
167
+ Write-Host " $separatorBar `n Error running TypeSpec regeneration in directory $directory `n $ ( [String ]::Join(" `n " , $generateOutput )) `n $separatorBar "
168
+ throw
169
+ }
170
+ } finally {
171
+ Get-ChildItem - Path $directory - Filter TempTypeSpecFiles - Recurse - Directory | ForEach-Object {
172
+ Remove-Item - Path $_.FullName - Recurse - Force | Out-Null
173
+ }
190
174
}
191
175
192
176
# Update code snippets before comparing the diff
193
177
$mvnOutput = (& mvn -- no- transfer- progress codesnippet:update-codesnippet 2>&1 )
194
178
if ($LastExitCode -ne 0 ) {
195
- Write-Host @"
196
- ======================================
197
- Error updating TypeSpec codesnippets in directory $Directory
198
- ======================================
199
- $ ( [String ]::Join(" `n " , $mvnOutput ))
200
- "@
179
+ Write-Host " $separatorBar `n Error updating TypeSpec codesnippets in directory $directory `n $ ( [String ]::Join(" `n " , $mvnOutput )) `n $separatorBar "
201
180
throw
202
181
}
203
182
} finally {
204
183
Pop-Location
205
184
}
206
185
207
186
# prevent warning related to EOL differences which triggers an exception for some reason
208
- (& git - c core.safecrlf= false diff -- ignore- space- at- eol -- exit-code -- " $Directory /*.java" " :(exclude)**/src/test/**" " :
187
+ (& git - c core.safecrlf= false diff -- ignore- space- at- eol -- exit-code -- " $directory /*.java" " :(exclude)**/src/test/**" " :
209
188
(exclude)**/src/samples/**" " :(exclude)**/src/main/**/implementation/**" " :(exclude)**/src/main/**/resourcemanager/**/*Manager.java" ) | Out-Null
210
189
211
190
if ($LastExitCode -ne 0 ) {
212
- $status = (git status - s " $Directory " | Out-String )
213
- Write-Host @"
214
- ======================================
215
- The following TypeSpec files in directoy $Directory are out of date:
216
- ======================================
217
- $status
218
- "@
191
+ $status = (git status - s " $directory " | Out-String )
192
+ Write-Host " $separatorBar `n The following TypeSpec files in directoy $directory are out of date`n $status `n $separatorBar "
219
193
throw
220
194
} else {
221
- Write-Host @"
222
- ======================================
223
- Successfully ran TypeSpec update in directory with no diff $Directory
224
- ======================================
225
- "@
195
+ Write-Host " $separatorBar `n Successfully ran TypeSpec update in directory with no diff $directory `n $separatorBar "
226
196
}
227
197
} else {
228
- Write-Error " Unknown generation type: $ ( $_.Type ) , directory: $directory "
198
+ Write-Host " $separatorBar `n Unknown generation type: $ ( $_.Type ) , directory: $directory `n $separatorBar "
229
199
throw
230
200
}
231
201
}
0 commit comments