diff --git a/packages/http-client-csharp/eng/scripts/RegenPreview.ps1 b/packages/http-client-csharp/eng/scripts/RegenPreview.ps1 index 30a83af5d45..dbe6eb3c3da 100644 --- a/packages/http-client-csharp/eng/scripts/RegenPreview.ps1 +++ b/packages/http-client-csharp/eng/scripts/RegenPreview.ps1 @@ -38,9 +38,10 @@ - Use -Azure to regenerate Azure-branded libraries (@azure-typespec/http-client-csharp) - Use -Unbranded to regenerate unbranded libraries (@typespec/http-client-csharp) - Use -Mgmt to regenerate management plane libraries (@azure-typespec/http-client-csharp-mgmt) + - Use -Libraries to regenerate specific comma-separated library names - Filters can be combined (e.g. -Azure -Unbranded) to regenerate libraries from multiple generators - Omit all filter parameters to regenerate all libraries (default) - - Use -Select for interactive selection (can be combined with generator filters) + - Use -Select for interactive selection (can be combined with generator filters) .PARAMETER SdkLibraryRepoPath Required. The local file system path to the SDK repository (azure-sdk-for-net or openai-dotnet). @@ -67,11 +68,17 @@ If no generator filter is specified, all libraries are regenerated. Not applicable in OpenAI mode. +.PARAMETER Libraries + Optional. Azure SDK Mode only. Comma-separated names of libraries to regenerate. + Can be combined with Select, Azure, Unbranded, and Mgmt filters. + Mutually exclusive with Spector. + Not applicable in OpenAI mode. + .PARAMETER Spector Optional. Azure SDK Mode only. When specified, regenerates the Azure spector test scenarios in azure-sdk-for-net instead of regenerating SDK libraries. This builds the local unbranded generator, wires it into the Azure generator, and runs the Azure generator's Generate.ps1 to regenerate spector test projects. - Mutually exclusive with Select, Azure, Unbranded, and Mgmt parameters. + Mutually exclusive with Select, Azure, Unbranded, Mgmt, and Libraries parameters. Not applicable in OpenAI mode. .EXAMPLE @@ -106,6 +113,10 @@ # Regenerate both Azure-branded and unbranded libraries .\RegenPreview.ps1 -SdkLibraryRepoPath "C:\repos\azure-sdk-for-net" -Azure -Unbranded +.EXAMPLE + # Regenerate specific libraries + .\RegenPreview.ps1 -SdkLibraryRepoPath "C:\repos\azure-sdk-for-net" -Libraries "Azure.ResourceManager.AppContainers, Azure.Data.AppConfig" + .EXAMPLE # Regenerate Azure spector test scenarios using local changes .\RegenPreview.ps1 -SdkLibraryRepoPath "C:\repos\azure-sdk-for-net" -Spector @@ -127,6 +138,9 @@ param( [Parameter(Mandatory=$false)] [switch]$Mgmt, + [Parameter(Mandatory=$false)] + [string]$Libraries, + [Parameter(Mandatory=$false)] [switch]$Spector ) @@ -136,18 +150,32 @@ Set-StrictMode -Version 3.0 # Detect OpenAI mode $isOpenAIMode = $SdkLibraryRepoPath -like "*openai-dotnet*" +$hasLibraryFilter = $PSBoundParameters.ContainsKey('Libraries') +$libraryNames = @( + if ($Libraries) { + $Libraries -split ',' | + ForEach-Object { $_.Trim() } | + Where-Object { $_ } | + Select-Object -Unique + } +) # Validate mutually exclusive parameters +if ($hasLibraryFilter -and $libraryNames.Count -eq 0) { + Write-Error "The -Libraries parameter must specify at least one library name." + exit 1 +} + if ($isOpenAIMode) { # In OpenAI mode, no filter parameters are allowed - if ($Select -or $Azure -or $Unbranded -or $Mgmt -or $Spector) { - Write-Error "OpenAI mode detected. The -Select, -Azure, -Unbranded, -Mgmt, and -Spector parameters are not applicable when regenerating OpenAI libraries." + if ($Select -or $Azure -or $Unbranded -or $Mgmt -or $hasLibraryFilter -or $Spector) { + Write-Error "OpenAI mode detected. The -Select, -Azure, -Unbranded, -Mgmt, -Libraries, and -Spector parameters are not applicable when regenerating OpenAI libraries." exit 1 } } else { # -Spector is mutually exclusive with all other filter parameters - if ($Spector -and ($Select -or $Azure -or $Unbranded -or $Mgmt)) { - Write-Error "The -Spector parameter is mutually exclusive with -Select, -Azure, -Unbranded, and -Mgmt." + if ($Spector -and ($Select -or $Azure -or $Unbranded -or $Mgmt -or $hasLibraryFilter)) { + Write-Error "The -Spector parameter is mutually exclusive with -Select, -Azure, -Unbranded, -Mgmt, and -Libraries." exit 1 } } @@ -173,6 +201,12 @@ if ($isOpenAIMode) { # Display active mode $modeText = if ($Spector) { "Regenerate Azure spector test scenarios" + } elseif ($hasLibraryFilter) { + if ($Select) { + "Interactively select from specified libraries: $($libraryNames -join ', ')" + } else { + "Regenerate specified libraries: $($libraryNames -join ', ')" + } } elseif ($Azure -or $Unbranded -or $Mgmt) { $generatorNames = @() if ($Azure) { $generatorNames += "Azure" } @@ -559,9 +593,19 @@ try { -Azure:$Azure ` -Unbranded:$Unbranded ` -Mgmt:$Mgmt) + $filteredLibraries = @(Filter-LibrariesByName ` + -Libraries $filteredLibraries ` + -LibraryNames $libraryNames) + + if ($hasLibraryFilter) { + $missingLibraryNames = @($libraryNames | Where-Object { $_ -notin $filteredLibraries.Library }) + if ($missingLibraryNames.Count -gt 0) { + throw "Libraries not found matching the specified filters: $($missingLibraryNames -join ', ')" + } + } if (-not $filteredLibraries -or $filteredLibraries.Count -eq 0) { - Write-Host "No libraries found matching the specified generator filter" -ForegroundColor Yellow + Write-Host "No libraries found matching the specified filters" -ForegroundColor Yellow exit 0 } @@ -790,6 +834,16 @@ try { -Azure:$Azure ` -Unbranded:$Unbranded ` -Mgmt:$Mgmt + $librariesToAnalyze = @(Filter-LibrariesByName ` + -Libraries $librariesToAnalyze ` + -LibraryNames $libraryNames) + } + + if ($hasLibraryFilter -and -not $Select) { + $missingLibraryNames = @($libraryNames | Where-Object { $_ -notin $librariesToAnalyze.Library }) + if ($missingLibraryNames.Count -gt 0) { + throw "Libraries not found matching the specified filters: $($missingLibraryNames -join ', ')" + } } # Determine which generators are actually needed @@ -927,9 +981,12 @@ try { -Azure:$Azure ` -Unbranded:$Unbranded ` -Mgmt:$Mgmt + $libraries = @(Filter-LibrariesByName ` + -Libraries $libraries ` + -LibraryNames $libraryNames) if ($libraries.Count -eq 0) { - Write-Host "No libraries found matching the specified generator filter" -ForegroundColor Yellow + Write-Host "No libraries found matching the specified filters" -ForegroundColor Yellow Write-Host "Skipping regeneration step..." -ForegroundColor Gray } else { $filterParts = @() diff --git a/packages/http-client-csharp/eng/scripts/RegenPreview.psm1 b/packages/http-client-csharp/eng/scripts/RegenPreview.psm1 index 2b131e6d5c8..af1d00126e2 100644 --- a/packages/http-client-csharp/eng/scripts/RegenPreview.psm1 +++ b/packages/http-client-csharp/eng/scripts/RegenPreview.psm1 @@ -468,6 +468,34 @@ function Filter-LibrariesByGenerator { return @($filtered.ToArray()) } +function Filter-LibrariesByName { + <# + .SYNOPSIS + Filters libraries by name. + + .PARAMETER Libraries + Array of library objects to filter. Each object should have a 'Library' property. + + .PARAMETER LibraryNames + Names of the libraries to include. If no names are specified, all libraries are returned. + #> + param( + [Parameter(Mandatory=$true)] + [array]$Libraries, + + [Parameter(Mandatory=$false)] + [string[]]$LibraryNames + ) + + $ErrorActionPreference = 'Stop' + + if (-not $LibraryNames -or $LibraryNames.Count -eq 0) { + return @($Libraries) + } + + return @($Libraries | Where-Object { $_.Library -in $LibraryNames }) +} + function Update-OpenAIGenerator { <# .SYNOPSIS @@ -978,4 +1006,4 @@ function Update-AzureSpectorScenarios { return $generationOutput } -Export-ModuleMember -Function "Update-MgmtGenerator", "Update-AzureGenerator", "Filter-LibrariesByGenerator", "Update-OpenAIGenerator", "Add-LocalNuGetSource", "Update-AzureSpectorScenarios" +Export-ModuleMember -Function "Update-MgmtGenerator", "Update-AzureGenerator", "Filter-LibrariesByGenerator", "Filter-LibrariesByName", "Update-OpenAIGenerator", "Add-LocalNuGetSource", "Update-AzureSpectorScenarios" diff --git a/packages/http-client-csharp/eng/scripts/docs/RegenPreview.md b/packages/http-client-csharp/eng/scripts/docs/RegenPreview.md index f9f42de05b1..d7513081d8b 100644 --- a/packages/http-client-csharp/eng/scripts/docs/RegenPreview.md +++ b/packages/http-client-csharp/eng/scripts/docs/RegenPreview.md @@ -18,7 +18,7 @@ When making changes to the TypeSpec HTTP Client C# generator, it may be helpful 1. Building local versions of the generator packages 2. Updating the Azure SDK for .NET repository to use these local packages -3. Regenerating all libraries (or selected libraries if `-Select` is specified) +3. Regenerating all libraries (or specific libraries if `-Select` or `-Libraries` is specified) 4. Cleaning up all modifications after validation ### OpenAI Mode @@ -93,7 +93,7 @@ This will: - Regenerate the OpenAI library - Restore all modified generator metadata files on success -**Note**: OpenAI mode is automatically detected when the repository path contains "openai-dotnet". The `-Select`, `-Azure`, `-Unbranded`, and `-Mgmt` parameters are not applicable in OpenAI mode. +**Note**: OpenAI mode is automatically detected when the repository path contains "openai-dotnet". The `-Select`, `-Azure`, `-Unbranded`, `-Mgmt`, and `-Libraries` parameters are not applicable in OpenAI mode. ### Parameters @@ -164,11 +164,23 @@ Not applicable in OpenAI mode. .\RegenPreview.ps1 -SdkLibraryRepoPath "C:\repos\azure-sdk-for-net" -Mgmt ``` +#### `-Libraries` (Optional) + +**Azure SDK Mode only.** A comma-separated list of library names to regenerate. This parameter can be combined with `-Select` and generator filters (`-Azure`, `-Unbranded`, `-Mgmt`), but not with `-Spector`. + +Not applicable in OpenAI mode. + +**Example:** + +```powershell +.\RegenPreview.ps1 -SdkLibraryRepoPath "C:\repos\azure-sdk-for-net" -Libraries "Azure.ResourceManager.AppContainers, Azure.Data.AppConfig" +``` + #### `-Spector` (Optional) **Azure SDK Mode only.** When specified, regenerates the Azure spector test scenarios in azure-sdk-for-net instead of regenerating SDK libraries. This builds the local unbranded generator, wires it into the Azure generator, and runs the Azure generator's Generate.ps1 to regenerate spector test projects. -Mutually exclusive with `-Select`, `-Azure`, `-Unbranded`, and `-Mgmt`. +Mutually exclusive with `-Select`, `-Azure`, `-Unbranded`, `-Mgmt`, and `-Libraries`. Not applicable in OpenAI mode. @@ -282,7 +294,7 @@ When the repository path contains "openai-dotnet", the script switches to OpenAI - **On failure**, leaves all modified artifacts in place for debugging - Displays success message and exits -**Note:** Filter parameters (`-Azure`, `-Unbranded`, `-Mgmt`, `-Select`) are not applicable in OpenAI mode and will cause an error if specified. +**Note:** Filter parameters (`-Azure`, `-Unbranded`, `-Mgmt`, `-Select`, `-Libraries`) are not applicable in OpenAI mode and will cause an error if specified. --- @@ -335,6 +347,7 @@ In Azure SDK mode, the script continues with additional steps after Step 2.5: ### Step 7: Prepare Library List - Confirms the list of libraries to regenerate +- Applies the `-Libraries` filter when specified - When no `-Select` flag, loads all libraries from `Library_Inventory.md` including: - Data plane libraries using `@azure-typespec/http-client-csharp` - Data plane libraries using `@typespec/http-client-csharp` @@ -449,10 +462,7 @@ Detailed report saved to: C:\...\debug\regen-report.json ```powershell # You want to test Azure generator changes on specific libraries only -.\RegenPreview.ps1 -SdkLibraryRepoPath "C:\repos\azure-sdk-for-net" -Select - -# Select just one or two libraries when prompted -# Selection: 1,5 +.\RegenPreview.ps1 -SdkLibraryRepoPath "C:\repos\azure-sdk-for-net" -Libraries "Azure.ResourceManager.AppContainers, Azure.Data.AppConfig" ``` ### Scenario: Full Validation Before PR