Back to Azure Sdk For

RegenPreview.ps1

eng/packages/http-client-csharp/eng/scripts/docs/RegenPreview.md

2019-05-16T16-525.4 KB
Original Source

RegenPreview.ps1

Overview

RegenPreview.ps1 is a PowerShell script that automates the process of building local generator packages and regenerating libraries for validation purposes.

This script is designed to streamline the workflow for testing changes to the TypeSpec HTTP Client C# generator before submitting a pull request.

Purpose

When making changes to the TypeSpec HTTP Client C# generator, it may be helpful to validate what the effects will be to generated libraries. This script automates the entire validation workflow by:

High level process

  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)
  4. Cleaning up all modifications after validation

Prerequisites

  • PowerShell 7.0 or later (cross-platform: Windows, Linux, macOS)
  • Node.js and npm installed
  • .NET SDK installed
  • Local clone of the azure-sdk-for-net repository

Usage

Basic Usage (Regenerate All)

Windows:

powershell
.\RegenPreview.ps1

Linux/macOS:

powershell
./RegenPreview.ps1

This will:

  • Clean and build the Azure & Mgmt generator with local changes
  • Regenerate all libraries automatically
  • Restore all modified metadata files on success (ie. package.json, package-lock.json)

Parameters

-Select (Optional)

When specified, displays an interactive menu to select specific libraries to regenerate. If omitted, all libraries are regenerated automatically.

Can be combined with generator filter parameters (-Azure, -Unbranded, -Mgmt) to interactively select from a filtered subset.

Example:

powershell
.\RegenPreview.ps1 -Select

-Azure (Optional)

When specified, only regenerates libraries using the Azure-branded generator (@azure-typespec/http-client-csharp).

Example:

powershell
.\RegenPreview.ps1 -Azure

-Unbranded (Optional)

When specified, only regenerates libraries using the unbranded generator (@typespec/http-client-csharp).

Example:

powershell
.\RegenPreview.ps1 -Unbranded

-Mgmt (Optional)

When specified, only regenerates libraries using the management plane generator (@azure-typespec/http-client-csharp-mgmt).

If no generator filter parameter is specified, all libraries are regenerated by default.

Example:

powershell
.\RegenPreview.ps1 -Mgmt

Interactive Selection

When running with the -Select flag, the script presents an interactive menu listing all available libraries:

==================== LIBRARY SELECTION ====================
Found 28 libraries available for regeneration

Azure-branded libraries (@azure-typespec/http-client-csharp):
  [ 1] Azure.AI.VoiceLive                                  (ai)
  [ 2] Azure.Data.AppConfiguration                         (appconfiguration)
  ...

Unbranded libraries (@typespec/http-client-csharp):
  [12] Azure.AI.Projects                                   (ai)
  [13] Azure.AI.OpenAI                                     (openai)

Management plane libraries (@azure-typespec/http-client-csharp-mgmt):
  [14] Azure.ResourceManager.AgriculturePlatform           (agricultureplatform)
  [15] Azure.ResourceManager.ArizeAIObservabilityEval      (arizeaiobservabilityeval)
  ...

Enter library numbers to regenerate (comma-separated), 'all' for all libraries, or 'q' to quit:
Example: 1,3,5  or  1-4,7  or  all

Selection Options:

  • Single library: 1
  • Multiple libraries: 1,3,5
  • Range of libraries: 1-4
  • Combination: 1-4,7,10
  • All libraries: all
  • Quit: q

Error Handling

If the script encounters an error during pre-requisite steps (Steps 1-6), it will:

  • Display the error message and stack trace
  • Attempt to restore NuGet.Config to prevent leaving the repository in an inconsistent state
  • Exit with code 1

Output

Debug Folder

All packaged artifacts are stored in the debug folder at the root of the azure generator:

  • azure-typespec-http-client-csharp-{version}.tgz - Azure generator npm package
  • Azure.Generator.{version}.nupkg - Core generator NuGet package
  • regen-report.json - Detailed JSON report of regeneration results

Console Output

The script provides colored console output with:

  • Cyan: Step headers and section dividers
  • Yellow: Important information (versions, library counts, warnings)
  • Gray: Detailed command execution and file operations
  • Green: Success messages
  • Red: Error messages and failed libraries
  • White: Library names during regeneration

Regeneration Report

After regeneration completes, a summary report is displayed:

==================== REGENERATION REPORT ====================
Total Libraries: 3
Passed: 2
Failed: 1
Execution Time: 00:02:45

PASSED LIBRARIES:
  ✓ Azure.AI.VoiceLive (ai)
  ✓ Azure.AI.Projects (cognitiveservices)

FAILED LIBRARIES:
  ✗ Azure.Messaging.EventGrid.Namespaces (eventgrid)
    Error: Generation failed with exit code 1
    Details: ...

=============================================================
Detailed report saved to: C:\...\debug\regen-report.json

Common Scenarios

Scenario: Test a Small Change Quickly

powershell
# You want to test Azure generator changes on specific libraries only
.\RegenPreview.ps1  -Select

# Select just one or two libraries when prompted
# Selection: 1,5

Scenario: Full Validation Before PR

powershell
.\RegenPreview.ps1