-
Notifications
You must be signed in to change notification settings - Fork 5.6k
adopt new tsp-client config #37022
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
Merged
Merged
adopt new tsp-client config #37022
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5796f44
adopt new tsp-client config
60759cb
adopt new tsp-client config
961b4d7
Update eng/tools/typespec-validation/src/rules/sdk-tspconfig-validati…
JiaqiZhang-Dev 9975794
Update eng/tools/typespec-validation/src/rules/sdk-tspconfig-validati…
JiaqiZhang-Dev bab2df6
Merge branch 'go-validation' of github.com:Azure/azure-rest-api-specs…
cd1860b
Merge branch 'main' into go-validation
tadelesh 311cf73
update
f8b1df8
add containing-module rule
69e7b33
fix
3765403
update existed config
9abee23
suppression
27dd3bf
update suppression
2f73b6c
fix
5cf3816
fix
3fb1e67
update suppression
f681163
update
8731ec9
Merge branch 'main' into go-validation
tadelesh d73d34c
fix
7cd5034
update
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| #!/usr/bin/env pwsh | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Updates TypeSpec Go configuration in tspconfig.yaml files | ||
|
|
||
| .DESCRIPTION | ||
| This script finds and updates the @azure-tools/typespec-go section in tspconfig.yaml files: | ||
| 1. Changes package-dir to emitter-output-dir with new value format | ||
| 2. Updates module config to replace {package-dir} with actual value | ||
| 3. Removes module-version config | ||
|
|
||
| .PARAMETER FilePath | ||
| Path to the tspconfig.yaml file to update. If not specified, searches for files in current directory. | ||
|
|
||
| .PARAMETER Recurse | ||
| Search recursively in subdirectories for tspconfig.yaml files | ||
|
|
||
| .EXAMPLE | ||
| .\update-typespec-go-config.ps1 -FilePath ".\tspconfig.yaml" | ||
| Updates a specific tspconfig.yaml file | ||
|
|
||
| .EXAMPLE | ||
| .\update-typespec-go-config.ps1 -Recurse | ||
| Searches and updates all tspconfig.yaml files in current directory and subdirectories | ||
|
|
||
| .EXAMPLE | ||
| .\update-typespec-go-config.ps1 | ||
| Updates tspconfig.yaml files in current directory only | ||
| #> | ||
|
|
||
| param( | ||
| [Parameter(Mandatory = $false)] | ||
| [string]$FilePath, | ||
|
|
||
| [Parameter(Mandatory = $false)] | ||
| [switch]$Recurse | ||
| ) | ||
|
|
||
| function Update-TypeSpecGoConfig { | ||
| param( | ||
| [Parameter(Mandatory = $true)] | ||
| [string]$ConfigFilePath | ||
| ) | ||
|
|
||
| Write-Host "Processing file: $ConfigFilePath" -ForegroundColor Green | ||
|
|
||
| # Read the file content | ||
| $content = Get-Content -Path $ConfigFilePath -Raw | ||
|
|
||
| # Check if the file contains @azure-tools/typespec-go section | ||
| if ($content -notmatch '@azure-tools/typespec-go') { | ||
| Write-Host " No @azure-tools/typespec-go section found, skipping..." -ForegroundColor Yellow | ||
| return $false | ||
| } | ||
|
|
||
| # Split content into lines for processing | ||
| $lines = Get-Content -Path $ConfigFilePath | ||
| $newLines = @() | ||
| $inGoSection = $false | ||
| $sectionIndent = "" | ||
| $goSectionLines = @() | ||
|
|
||
| for ($i = 0; $i -lt $lines.Count; $i++) { | ||
| $line = $lines[$i] | ||
|
|
||
| # Check if we're entering the typespec-go section | ||
| if ($line -match '^\s*"@azure-tools/typespec-go":\s*$') { | ||
| $inGoSection = $true | ||
| $sectionIndent = $line.Length - $line.TrimStart().Length | ||
| $newLines += $line | ||
| $goSectionLines = @() | ||
| Write-Host " Found @azure-tools/typespec-go section" -ForegroundColor Cyan | ||
| continue | ||
| } | ||
|
|
||
| # Check if we're leaving the current section (next section starts or indentation decreases) | ||
| if ($inGoSection) { | ||
| $currentIndent = $line.Length - $line.TrimStart().Length | ||
| if (($line -match '^\s*"@.*":\s*$' -and $currentIndent -le $sectionIndent) -or | ||
| ($line -match '^\s*[a-zA-Z][^:]*:\s*$' -and $currentIndent -le $sectionIndent)) { | ||
| # Process the collected Go section lines | ||
| $processedLines = ConvertTo-GoSectionLines -Lines @($goSectionLines) | ||
| $newLines += $processedLines | ||
| $inGoSection = $false | ||
| $newLines += $line | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| # Process lines within the typespec-go section | ||
| if ($inGoSection) { | ||
| $goSectionLines += $line | ||
| } else { | ||
| # Keep lines outside the typespec-go section | ||
| $newLines += $line | ||
| } | ||
| } | ||
|
|
||
| # Handle case where Go section is at the end of file | ||
| if ($inGoSection -and $goSectionLines.Count -gt 0) { | ||
| $processedLines = ConvertTo-GoSectionLines -Lines @($goSectionLines) | ||
| $newLines += $processedLines | ||
| } | ||
|
|
||
| # Write the updated content back to the file | ||
| $newContent = $newLines -join "`n" | ||
| if ($newContent -and -not $newContent.EndsWith("`n")) { | ||
| $newContent += "`n" | ||
| } | ||
| Set-Content -Path $ConfigFilePath -Value $newContent -NoNewline | ||
|
|
||
| Write-Host " File updated successfully!" -ForegroundColor Green | ||
| return $true | ||
| } | ||
|
|
||
| function ConvertTo-GoSectionLines { | ||
| param( | ||
| [Parameter(Mandatory = $false)] | ||
| [AllowEmptyCollection()] | ||
| [AllowEmptyString()] | ||
| [string[]]$Lines = @() | ||
| ) | ||
|
|
||
| if ($Lines.Count -eq 0) { | ||
| return @() | ||
| } | ||
|
|
||
| # Filter out any empty string entries that PowerShell might pass | ||
| $cleanLines = @($Lines | Where-Object { $_ -ne $null }) | ||
|
|
||
| if ($cleanLines.Count -eq 0) { | ||
| return @() | ||
| } | ||
|
|
||
| $processedLines = @() | ||
| $packageDirValue = "" | ||
| $moduleValue = "" | ||
|
|
||
| # First pass: extract package-dir and module values | ||
| foreach ($line in $cleanLines) { | ||
| if ($line -match '^\s*package-dir:\s*"?([^"]+)"?\s*$') { | ||
| $packageDirValue = $matches[1] | ||
| Write-Host " Found package-dir: $packageDirValue" -ForegroundColor Cyan | ||
| } | ||
| if ($line -match '^\s*module:\s*"?([^"]+)"?\s*$') { | ||
| $moduleValue = $matches[1] | ||
| Write-Host " Found module: $moduleValue" -ForegroundColor Cyan | ||
| } | ||
| } | ||
|
|
||
| # Second pass: process and transform lines | ||
| foreach ($line in $cleanLines) { | ||
| # Skip empty lines and comments - keep them as is | ||
| if ($line -match '^\s*$' -or $line -match '^\s*#') { | ||
| $processedLines += $line | ||
| continue | ||
| } | ||
|
|
||
| # Transform package-dir to emitter-output-dir | ||
| if ($line -match '^\s*package-dir:\s*"?([^"]+)"?\s*$') { | ||
| $indent = ($line -replace 'package-dir:.*$', '') | ||
| $newLine = $indent + "emitter-output-dir: `"{output-dir}/{service-dir}/$packageDirValue`"" | ||
| $processedLines += $newLine | ||
| Write-Host " Changed package-dir to emitter-output-dir: {output-dir}/{service-dir}/$packageDirValue" -ForegroundColor Green | ||
| continue | ||
| } | ||
|
|
||
| # Update module value | ||
| if ($line -match '^\s*module:\s*"?([^"]+)"?\s*$') { | ||
| if ($packageDirValue -and $moduleValue -match '\{package-dir\}') { | ||
| $newModuleValue = $moduleValue -replace '\{package-dir\}', $packageDirValue | ||
| $indent = ($line -replace 'module:.*$', '') | ||
| $newLine = $indent + "module: `"$newModuleValue`"" | ||
| $processedLines += $newLine | ||
| Write-Host " Updated module to: $newModuleValue" -ForegroundColor Green | ||
| } else { | ||
| $processedLines += $line | ||
| } | ||
| continue | ||
| } | ||
|
|
||
| # Skip module-version line | ||
| if ($line -match '^\s*module-version:') { | ||
| Write-Host " Removed module-version config" -ForegroundColor Green | ||
| continue | ||
| } | ||
|
|
||
| # Keep all other lines in the section | ||
| $processedLines += $line | ||
| } | ||
|
|
||
| return $processedLines | ||
| } | ||
|
|
||
| # Main execution | ||
| try { | ||
| if ($FilePath) { | ||
| # Process specific file | ||
| if (-not (Test-Path $FilePath)) { | ||
| Write-Error "File not found: $FilePath" | ||
| exit 1 | ||
| } | ||
|
|
||
| $updated = Update-TypeSpecGoConfig -ConfigFilePath $FilePath | ||
| if ($updated) { | ||
| Write-Host "`nSuccessfully updated: $FilePath" -ForegroundColor Green | ||
| } | ||
| } else { | ||
| # Find tspconfig.yaml files | ||
| $searchPath = if ($Recurse) { Get-ChildItem -Path "." -Name "tspconfig.yaml" -Recurse } else { Get-ChildItem -Path "." -Name "tspconfig.yaml" } | ||
|
|
||
| if (-not $searchPath) { | ||
| Write-Host "No tspconfig.yaml files found." -ForegroundColor Yellow | ||
| exit 0 | ||
| } | ||
|
|
||
| $updatedCount = 0 | ||
| foreach ($file in $searchPath) { | ||
| $fullPath = Resolve-Path $file | ||
| $updated = Update-TypeSpecGoConfig -ConfigFilePath $fullPath | ||
| if ($updated) { | ||
| $updatedCount++ | ||
| } | ||
| } | ||
|
|
||
| Write-Host "`nProcessing complete. Updated $updatedCount file(s)." -ForegroundColor Green | ||
| } | ||
| } catch { | ||
| Write-Error "An error occurred: $_" | ||
| exit 1 | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.