From 8edde27615578036b360f2abb0175258e7e248c1 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 27 May 2026 13:30:55 -0400 Subject: [PATCH 01/11] fix: stamp prerelease version in Python emitter build script The Build-Packages.ps1 script accepted a -Prerelease flag but never used it to stamp the package version. Every CI build on main produced a package with the same version from package.json, causing npm publish to fail with a 409 conflict when publishing to the DevOps feed. Added prerelease version stamping (matching the pattern used by the C# emitter) that appends -alpha.{BuildNumber} or -beta.{BuildNumber} to the version and updates package.json before npm pack. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../eng/scripts/Build-Packages.ps1 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/http-client-python/eng/scripts/Build-Packages.ps1 b/packages/http-client-python/eng/scripts/Build-Packages.ps1 index 16fd147f5db..f178988d698 100644 --- a/packages/http-client-python/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Build-Packages.ps1 @@ -75,6 +75,13 @@ New-Item -ItemType Directory -Force -Path "$outputPath/packages" | Out-Null $emitterVersion = node -p -e "require('$packageRoot/package.json').version" Write-Host "Package version: $emitterVersion" +# Stamp prerelease version if BuildNumber is provided +if ($BuildNumber) { + $versionTag = $Prerelease ? "-alpha" : "-beta" + $emitterVersion = "$emitterVersion$versionTag.$BuildNumber" + Write-Host "Stamped version: $emitterVersion" +} + Push-Location "$packageRoot" try { # Step 1: Build the emitter and generator @@ -87,7 +94,14 @@ try { Invoke-LoggedCommand "npm run lint" -GroupOutput } - # Step 3: Create npm package + # Step 3: Update package.json version and create npm package + if ($BuildNumber) { + Write-Host "`n=== Updating package.json to version: $emitterVersion ===" -ForegroundColor Cyan + $packageJson = Get-Content -Raw "package.json" | ConvertFrom-Json -AsHashtable + $packageJson.version = $emitterVersion + $packageJson | ConvertTo-Json -Depth 100 | Out-File -Path "package.json" -Encoding utf8 -NoNewline -Force + } + Write-Host "`n=== Creating npm package ===" -ForegroundColor Cyan Invoke-LoggedCommand "npm pack" Copy-Item "typespec-http-client-python-$emitterVersion.tgz" -Destination "$outputPath/packages" From 9e5527ff77fef0ee3d98a72cd47ba6293fbbcf7b Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 27 May 2026 13:31:22 -0400 Subject: [PATCH 02/11] Add changeset for Python prerelease version fix Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...ease-version-stamping-2026-5-27-13-30-0.md | 7 +++++++ .../eng/scripts/Build-Packages.ps1 | 19 ++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 .chronus/changes/fix-python-prerelease-version-stamping-2026-5-27-13-30-0.md diff --git a/.chronus/changes/fix-python-prerelease-version-stamping-2026-5-27-13-30-0.md b/.chronus/changes/fix-python-prerelease-version-stamping-2026-5-27-13-30-0.md new file mode 100644 index 00000000000..5cb580941de --- /dev/null +++ b/.chronus/changes/fix-python-prerelease-version-stamping-2026-5-27-13-30-0.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Fix CI publish failures by stamping prerelease version in Build-Packages.ps1. The `-Prerelease` flag was accepted but unused, causing every CI build to produce the same version and fail with a 409 conflict on the DevOps feed. diff --git a/packages/http-client-python/eng/scripts/Build-Packages.ps1 b/packages/http-client-python/eng/scripts/Build-Packages.ps1 index f178988d698..f3cb926ffa0 100644 --- a/packages/http-client-python/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Build-Packages.ps1 @@ -75,13 +75,6 @@ New-Item -ItemType Directory -Force -Path "$outputPath/packages" | Out-Null $emitterVersion = node -p -e "require('$packageRoot/package.json').version" Write-Host "Package version: $emitterVersion" -# Stamp prerelease version if BuildNumber is provided -if ($BuildNumber) { - $versionTag = $Prerelease ? "-alpha" : "-beta" - $emitterVersion = "$emitterVersion$versionTag.$BuildNumber" - Write-Host "Stamped version: $emitterVersion" -} - Push-Location "$packageRoot" try { # Step 1: Build the emitter and generator @@ -94,12 +87,12 @@ try { Invoke-LoggedCommand "npm run lint" -GroupOutput } - # Step 3: Update package.json version and create npm package - if ($BuildNumber) { - Write-Host "`n=== Updating package.json to version: $emitterVersion ===" -ForegroundColor Cyan - $packageJson = Get-Content -Raw "package.json" | ConvertFrom-Json -AsHashtable - $packageJson.version = $emitterVersion - $packageJson | ConvertTo-Json -Depth 100 | Out-File -Path "package.json" -Encoding utf8 -NoNewline -Force + # Step 3: Stamp prerelease version if this is a prerelease build + if ($Prerelease) { + Write-Host "`n=== Stamping prerelease version ===" -ForegroundColor Cyan + Invoke-LoggedCommand "pnpm chronus version --prerelease --only `"@typespec/http-client-python`"" + $emitterVersion = node -p -e "require('./package.json').version" + Write-Host "Stamped version: $emitterVersion" } Write-Host "`n=== Creating npm package ===" -ForegroundColor Cyan From a800b2798e600cf86b855e11d9a93d125882d9e5 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 27 May 2026 14:49:42 -0400 Subject: [PATCH 03/11] fix: use npx instead of pnpm for chronus in CI pnpm is not available in the CI build environment which only has npm/node. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- packages/http-client-python/eng/scripts/Build-Packages.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-python/eng/scripts/Build-Packages.ps1 b/packages/http-client-python/eng/scripts/Build-Packages.ps1 index f3cb926ffa0..eddc8c8c4b1 100644 --- a/packages/http-client-python/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Build-Packages.ps1 @@ -90,7 +90,7 @@ try { # Step 3: Stamp prerelease version if this is a prerelease build if ($Prerelease) { Write-Host "`n=== Stamping prerelease version ===" -ForegroundColor Cyan - Invoke-LoggedCommand "pnpm chronus version --prerelease --only `"@typespec/http-client-python`"" + Invoke-LoggedCommand "npx chronus version --prerelease --only `"@typespec/http-client-python`"" $emitterVersion = node -p -e "require('./package.json').version" Write-Host "Stamped version: $emitterVersion" } From 64788f843b6bc658ebbe33a227eaa53a873b9c5f Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 27 May 2026 14:50:31 -0400 Subject: [PATCH 04/11] fix: install pnpm in CI and revert to pnpm for chronus Add pnpm install step to the build-step template so chronus is available in the CI environment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/emitters/pipelines/templates/steps/build-step.yml | 3 +++ packages/http-client-python/eng/scripts/Build-Packages.ps1 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/eng/emitters/pipelines/templates/steps/build-step.yml b/eng/emitters/pipelines/templates/steps/build-step.yml index 2352b172f38..4dc72eb5cfa 100644 --- a/eng/emitters/pipelines/templates/steps/build-step.yml +++ b/eng/emitters/pipelines/templates/steps/build-step.yml @@ -85,6 +85,9 @@ steps: arguments: -UseTypeSpecNext:$${{ parameters.UseTypeSpecNext }} workingDirectory: $(selfRepositoryPath) + - script: npm install -g pnpm + displayName: Install pnpm + - task: PowerShell@2 displayName: "Run build script" name: ci_build diff --git a/packages/http-client-python/eng/scripts/Build-Packages.ps1 b/packages/http-client-python/eng/scripts/Build-Packages.ps1 index eddc8c8c4b1..f3cb926ffa0 100644 --- a/packages/http-client-python/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Build-Packages.ps1 @@ -90,7 +90,7 @@ try { # Step 3: Stamp prerelease version if this is a prerelease build if ($Prerelease) { Write-Host "`n=== Stamping prerelease version ===" -ForegroundColor Cyan - Invoke-LoggedCommand "npx chronus version --prerelease --only `"@typespec/http-client-python`"" + Invoke-LoggedCommand "pnpm chronus version --prerelease --only `"@typespec/http-client-python`"" $emitterVersion = node -p -e "require('./package.json').version" Write-Host "Stamped version: $emitterVersion" } From 9b8cc2d2dc9ed7e54633470343ffdb19d0df5e67 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 27 May 2026 15:20:03 -0400 Subject: [PATCH 05/11] fix: also install @chronus/chronus globally in CI chronus is not in http-client-python's node_modules, so pnpm can't find it. Install it globally alongside pnpm. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/emitters/pipelines/templates/steps/build-step.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/emitters/pipelines/templates/steps/build-step.yml b/eng/emitters/pipelines/templates/steps/build-step.yml index 4dc72eb5cfa..1bae41e60b1 100644 --- a/eng/emitters/pipelines/templates/steps/build-step.yml +++ b/eng/emitters/pipelines/templates/steps/build-step.yml @@ -85,8 +85,8 @@ steps: arguments: -UseTypeSpecNext:$${{ parameters.UseTypeSpecNext }} workingDirectory: $(selfRepositoryPath) - - script: npm install -g pnpm - displayName: Install pnpm + - script: npm install -g pnpm @chronus/chronus + displayName: Install pnpm and chronus - task: PowerShell@2 displayName: "Run build script" From 42e3b65a390180194b85890e36c1ad8c27236417 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2026 13:59:40 -0400 Subject: [PATCH 06/11] fix: use BuildNumber for unique prerelease versions, drop global chronus install Address PR review comments: - Remove global @chronus/chronus install from build-step.yml (pnpm chronus is already available) - Replace chronus-based version stamping with direct package.json update using -alpha.$BuildNumber suffix, matching the C# emitter pattern - This ensures each CI build produces a unique version, preventing 409 conflicts on the DevOps feed Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../pipelines/templates/steps/build-step.yml | 4 ++-- .../eng/scripts/Build-Packages.ps1 | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/eng/emitters/pipelines/templates/steps/build-step.yml b/eng/emitters/pipelines/templates/steps/build-step.yml index 1bae41e60b1..4dc72eb5cfa 100644 --- a/eng/emitters/pipelines/templates/steps/build-step.yml +++ b/eng/emitters/pipelines/templates/steps/build-step.yml @@ -85,8 +85,8 @@ steps: arguments: -UseTypeSpecNext:$${{ parameters.UseTypeSpecNext }} workingDirectory: $(selfRepositoryPath) - - script: npm install -g pnpm @chronus/chronus - displayName: Install pnpm and chronus + - script: npm install -g pnpm + displayName: Install pnpm - task: PowerShell@2 displayName: "Run build script" diff --git a/packages/http-client-python/eng/scripts/Build-Packages.ps1 b/packages/http-client-python/eng/scripts/Build-Packages.ps1 index f3cb926ffa0..5e1c39c80b2 100644 --- a/packages/http-client-python/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Build-Packages.ps1 @@ -88,11 +88,14 @@ try { } # Step 3: Stamp prerelease version if this is a prerelease build - if ($Prerelease) { - Write-Host "`n=== Stamping prerelease version ===" -ForegroundColor Cyan - Invoke-LoggedCommand "pnpm chronus version --prerelease --only `"@typespec/http-client-python`"" - $emitterVersion = node -p -e "require('./package.json').version" - Write-Host "Stamped version: $emitterVersion" + if ($BuildNumber) { + $versionTag = $Prerelease ? "-alpha" : "-beta" + $emitterVersion = "$emitterVersion$versionTag.$BuildNumber" + Write-Host "`n=== Stamping prerelease version: $emitterVersion ===" -ForegroundColor Cyan + + $packageJson = Get-Content -Raw "package.json" | ConvertFrom-Json -AsHashtable + $packageJson.version = $emitterVersion + $packageJson | ConvertTo-Json -Depth 100 | Out-File -Path "package.json" -Encoding utf8 -NoNewline -Force } Write-Host "`n=== Creating npm package ===" -ForegroundColor Cyan From eb10f4410426c2ac4fd6e7faff03bcd7fdc55130 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2026 14:13:51 -0400 Subject: [PATCH 07/11] fix: use chronus dev versioning, only stamp when changes exist Keep chronus-based prerelease (dev) versioning instead of alpha/BuildNumber. Only run 'chronus version --prerelease' when there are pending change files for @typespec/http-client-python, avoiding 409 conflicts when no changes are queued. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../eng/scripts/Build-Packages.ps1 | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/http-client-python/eng/scripts/Build-Packages.ps1 b/packages/http-client-python/eng/scripts/Build-Packages.ps1 index 5e1c39c80b2..6fa4bc2469a 100644 --- a/packages/http-client-python/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Build-Packages.ps1 @@ -88,14 +88,19 @@ try { } # Step 3: Stamp prerelease version if this is a prerelease build - if ($BuildNumber) { - $versionTag = $Prerelease ? "-alpha" : "-beta" - $emitterVersion = "$emitterVersion$versionTag.$BuildNumber" - Write-Host "`n=== Stamping prerelease version: $emitterVersion ===" -ForegroundColor Cyan - - $packageJson = Get-Content -Raw "package.json" | ConvertFrom-Json -AsHashtable - $packageJson.version = $emitterVersion - $packageJson | ConvertTo-Json -Depth 100 | Out-File -Path "package.json" -Encoding utf8 -NoNewline -Force + if ($Prerelease) { + # Only stamp if there are pending chronus change files for this package + $changeFiles = Get-ChildItem -Path "$packageRoot/../../.chronus/changes" -Filter "*.md" -ErrorAction SilentlyContinue | + Where-Object { (Get-Content $_.FullName -Raw) -match "http-client-python" } + + if ($changeFiles) { + Write-Host "`n=== Stamping prerelease version ===" -ForegroundColor Cyan + Invoke-LoggedCommand "pnpm chronus version --prerelease --only @typespec/http-client-python" + $emitterVersion = node -p -e "require('./package.json').version" + Write-Host "Stamped version: $emitterVersion" + } else { + Write-Host "`n=== No pending changes for @typespec/http-client-python, skipping prerelease version stamp ===" -ForegroundColor Yellow + } } Write-Host "`n=== Creating npm package ===" -ForegroundColor Cyan From 9c61a4d5e4127dfc755d931533884255362a9864 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2026 14:32:37 -0400 Subject: [PATCH 08/11] fix: align Python Build-Packages.ps1 with C# emitter pattern Rewrite Build-Packages.ps1 to match C#'s proven approach: - Use -alpha.$BuildNumber (prerelease) / -beta.$BuildNumber versioning - Directly update package.json instead of using chronus - Add Set-VersionVariable for ADO pipeline output variables - Remove chronus dependency from build pipeline entirely Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../eng/scripts/Build-Packages.ps1 | 123 +++++++----------- 1 file changed, 46 insertions(+), 77 deletions(-) diff --git a/packages/http-client-python/eng/scripts/Build-Packages.ps1 b/packages/http-client-python/eng/scripts/Build-Packages.ps1 index 6fa4bc2469a..fe8e120cea8 100644 --- a/packages/http-client-python/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Build-Packages.ps1 @@ -1,30 +1,4 @@ #Requires -Version 7.0 -<# -.SYNOPSIS - Builds and packages the TypeSpec Python emitter for publishing. - -.DESCRIPTION - This script is called by the CI pipeline to create publishable packages. - It runs: - 1. npm run build - Compile TypeScript emitter and build Python wheel - 2. npm run lint - Run linting (Linux only) - 3. npm pack - Create npm tarball for publishing - -.PARAMETER BuildNumber - The build number for versioning. - -.PARAMETER Output - Output directory for built packages. Defaults to ./ci-build. - -.PARAMETER Prerelease - Flag indicating if this is a prerelease build. - -.PARAMETER PublishType - Type of publish: "internal" for dev feed, otherwise public. - -.EXAMPLE - ./Build-Packages.ps1 -Output ./dist -#> param( [string] $BuildNumber, @@ -35,13 +9,14 @@ param( $ErrorActionPreference = 'Stop' Set-StrictMode -Version 3.0 - -# Setup paths and helpers $packageRoot = (Resolve-Path "$PSScriptRoot/../..").Path.Replace('\', '/') . "$packageRoot/../../eng/emitters/scripts/CommandInvocation-Helpers.ps1" Set-ConsoleEncoding -# Helper function to write package info for downstream publishing +Write-Host "Building packages for BuildNumber: '$BuildNumber', Output: '$Output', Prerelease: '$Prerelease', PublishType: '$PublishType'" + +$outputPath = $Output ? $Output : "$packageRoot/ci-build" + function Write-PackageInfo { param( [string] $packageName, @@ -55,81 +30,75 @@ function Write-PackageInfo { } @{ - Name = $packageName - Version = $version + Name = $packageName + Version = $version DirectoryPath = $directoryPath - SdkType = "client" - IsNewSdk = $true + SdkType = "client" + IsNewSdk = $true ReleaseStatus = "Unreleased" } | ConvertTo-Json | Set-Content -Path "$packageInfoPath/$packageName.json" } -Write-Host "Building packages for BuildNumber: '$BuildNumber', Output: '$Output', Prerelease: '$Prerelease', PublishType: '$PublishType'" +function Set-VersionVariable { + param( + [string] $variableName, + [string] $version + ) -# Setup output directory -$outputPath = $Output ? $Output : "$packageRoot/ci-build" + Write-Host "Setting output variable '$variableName' to $version" + Write-Host "##vso[task.setvariable variable=$variableName;isOutput=true]$version" +} + +# create the output folders $outputPath = New-Item -ItemType Directory -Force -Path $outputPath | Select-Object -ExpandProperty FullName New-Item -ItemType Directory -Force -Path "$outputPath/packages" | Out-Null -# Get package version +Write-Host "Getting existing versions" $emitterVersion = node -p -e "require('$packageRoot/package.json').version" -Write-Host "Package version: $emitterVersion" +if ($BuildNumber) { + # set package versions + $versionTag = $Prerelease ? "-alpha" : "-beta" + + $emitterVersion = "$emitterVersion$versionTag.$BuildNumber" + Set-VersionVariable -variableName "emitterVersion" -version $emitterVersion +} + +# build and pack the emitter Push-Location "$packageRoot" try { - # Step 1: Build the emitter and generator - Write-Host "`n=== Building emitter and generator ===" -ForegroundColor Cyan + Write-Host "Working in $PWD" + Invoke-LoggedCommand "npm run build" -GroupOutput - # Step 2: Run linting (Linux only, as CI runs on Linux) - if ($IsLinux) { - Write-Host "`n=== Running lint checks ===" -ForegroundColor Cyan - Invoke-LoggedCommand "npm run lint" -GroupOutput - } + if ($BuildNumber) { + Write-Host "Updating package.json to version: $emitterVersion`n" - # Step 3: Stamp prerelease version if this is a prerelease build - if ($Prerelease) { - # Only stamp if there are pending chronus change files for this package - $changeFiles = Get-ChildItem -Path "$packageRoot/../../.chronus/changes" -Filter "*.md" -ErrorAction SilentlyContinue | - Where-Object { (Get-Content $_.FullName -Raw) -match "http-client-python" } - - if ($changeFiles) { - Write-Host "`n=== Stamping prerelease version ===" -ForegroundColor Cyan - Invoke-LoggedCommand "pnpm chronus version --prerelease --only @typespec/http-client-python" - $emitterVersion = node -p -e "require('./package.json').version" - Write-Host "Stamped version: $emitterVersion" - } else { - Write-Host "`n=== No pending changes for @typespec/http-client-python, skipping prerelease version stamp ===" -ForegroundColor Yellow - } + $packageJson = Get-Content -Raw "package.json" | ConvertFrom-Json -AsHashtable + $packageJson.version = $emitterVersion + $packageJson | ConvertTo-Json -Depth 100 | Out-File -Path "package.json" -Encoding utf8 -NoNewline -Force } - Write-Host "`n=== Creating npm package ===" -ForegroundColor Cyan - Invoke-LoggedCommand "npm pack" - Copy-Item "typespec-http-client-python-$emitterVersion.tgz" -Destination "$outputPath/packages" + # pack the emitter + $file = Invoke-LoggedCommand "npm pack -q" + Copy-Item $file -Destination "$outputPath/packages" - # Step 4: Verify package can be installed - Write-Host "`n=== Verifying package installation ===" -ForegroundColor Cyan - Invoke-LoggedCommand "npm install typespec-http-client-python-$emitterVersion.tgz" -GroupOutput - - # Write package info for publishing pipeline - Write-PackageInfo -packageName "typespec-http-client-python" ` - -directoryPath "packages/http-client-python/emitter/src" ` - -version $emitterVersion + Write-PackageInfo -packageName "typespec-http-client-python" -directoryPath "packages/http-client-python/emitter/src" -version $emitterVersion } finally { Pop-Location } -# Generate override URLs for internal publishing -$overrides = @{} if ($PublishType -eq "internal") { $feedUrl = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry" - $overrides["@typespec/http-client-python"] = "$feedUrl/@typespec/http-client-python/-/http-client-python-$emitterVersion.tgz" + + $overrides = @{ + "@typespec/http-client-python" = "$feedUrl/@typespec/http-client-python/-/http-client-python-$emitterVersion.tgz" + } +} else { + $overrides = @{} } + $overrides | ConvertTo-Json | Set-Content "$outputPath/overrides.json" -# Write package version matrix @{ "emitter" = $emitterVersion } | ConvertTo-Json | Set-Content "$outputPath/package-versions.json" - -Write-Host "`n=== Build complete ===" -ForegroundColor Green -Write-Host "Output: $outputPath" From 2c3eca68f597096429f548d32b7dfcf6a74d83be Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2026 16:38:53 -0400 Subject: [PATCH 09/11] fix: restore lint and install verification steps Add back the Linux-only lint step and package install verification that were accidentally removed when aligning with C# pattern. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../http-client-python/eng/scripts/Build-Packages.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/http-client-python/eng/scripts/Build-Packages.ps1 b/packages/http-client-python/eng/scripts/Build-Packages.ps1 index fe8e120cea8..4161a51d4a3 100644 --- a/packages/http-client-python/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Build-Packages.ps1 @@ -71,6 +71,11 @@ try { Invoke-LoggedCommand "npm run build" -GroupOutput + # Run linting (Linux only, as CI runs on Linux) + if ($IsLinux) { + Invoke-LoggedCommand "npm run lint" -GroupOutput + } + if ($BuildNumber) { Write-Host "Updating package.json to version: $emitterVersion`n" @@ -83,6 +88,9 @@ try { $file = Invoke-LoggedCommand "npm pack -q" Copy-Item $file -Destination "$outputPath/packages" + # verify package can be installed + Invoke-LoggedCommand "npm install $file" -GroupOutput + Write-PackageInfo -packageName "typespec-http-client-python" -directoryPath "packages/http-client-python/emitter/src" -version $emitterVersion } finally { From c82c8d4d62de5ce4f1e3f11d62cd75be31033888 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2026 16:41:43 -0400 Subject: [PATCH 10/11] fix: add prerelease version stamping to Build-Packages.ps1 Add -alpha.$BuildNumber (prerelease) or -beta.$BuildNumber version stamping, matching the C# emitter pattern. The rest of the script remains unchanged from main. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../eng/scripts/Build-Packages.ps1 | 105 +++++++++++------- 1 file changed, 64 insertions(+), 41 deletions(-) diff --git a/packages/http-client-python/eng/scripts/Build-Packages.ps1 b/packages/http-client-python/eng/scripts/Build-Packages.ps1 index 4161a51d4a3..21b79415450 100644 --- a/packages/http-client-python/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Build-Packages.ps1 @@ -1,4 +1,30 @@ #Requires -Version 7.0 +<# +.SYNOPSIS + Builds and packages the TypeSpec Python emitter for publishing. + +.DESCRIPTION + This script is called by the CI pipeline to create publishable packages. + It runs: + 1. npm run build - Compile TypeScript emitter and build Python wheel + 2. npm run lint - Run linting (Linux only) + 3. npm pack - Create npm tarball for publishing + +.PARAMETER BuildNumber + The build number for versioning. + +.PARAMETER Output + Output directory for built packages. Defaults to ./ci-build. + +.PARAMETER Prerelease + Flag indicating if this is a prerelease build. + +.PARAMETER PublishType + Type of publish: "internal" for dev feed, otherwise public. + +.EXAMPLE + ./Build-Packages.ps1 -Output ./dist +#> param( [string] $BuildNumber, @@ -9,14 +35,13 @@ param( $ErrorActionPreference = 'Stop' Set-StrictMode -Version 3.0 + +# Setup paths and helpers $packageRoot = (Resolve-Path "$PSScriptRoot/../..").Path.Replace('\', '/') . "$packageRoot/../../eng/emitters/scripts/CommandInvocation-Helpers.ps1" Set-ConsoleEncoding -Write-Host "Building packages for BuildNumber: '$BuildNumber', Output: '$Output', Prerelease: '$Prerelease', PublishType: '$PublishType'" - -$outputPath = $Output ? $Output : "$packageRoot/ci-build" - +# Helper function to write package info for downstream publishing function Write-PackageInfo { param( [string] $packageName, @@ -30,83 +55,81 @@ function Write-PackageInfo { } @{ - Name = $packageName - Version = $version + Name = $packageName + Version = $version DirectoryPath = $directoryPath - SdkType = "client" - IsNewSdk = $true + SdkType = "client" + IsNewSdk = $true ReleaseStatus = "Unreleased" } | ConvertTo-Json | Set-Content -Path "$packageInfoPath/$packageName.json" } -function Set-VersionVariable { - param( - [string] $variableName, - [string] $version - ) - - Write-Host "Setting output variable '$variableName' to $version" - Write-Host "##vso[task.setvariable variable=$variableName;isOutput=true]$version" -} +Write-Host "Building packages for BuildNumber: '$BuildNumber', Output: '$Output', Prerelease: '$Prerelease', PublishType: '$PublishType'" -# create the output folders +# Setup output directory +$outputPath = $Output ? $Output : "$packageRoot/ci-build" $outputPath = New-Item -ItemType Directory -Force -Path $outputPath | Select-Object -ExpandProperty FullName New-Item -ItemType Directory -Force -Path "$outputPath/packages" | Out-Null -Write-Host "Getting existing versions" +# Get package version $emitterVersion = node -p -e "require('$packageRoot/package.json').version" +Write-Host "Package version: $emitterVersion" +# Stamp prerelease version if BuildNumber is provided if ($BuildNumber) { - # set package versions $versionTag = $Prerelease ? "-alpha" : "-beta" - $emitterVersion = "$emitterVersion$versionTag.$BuildNumber" - Set-VersionVariable -variableName "emitterVersion" -version $emitterVersion + Write-Host "Stamped prerelease version: $emitterVersion" } -# build and pack the emitter Push-Location "$packageRoot" try { - Write-Host "Working in $PWD" - + # Step 1: Build the emitter and generator + Write-Host "`n=== Building emitter and generator ===" -ForegroundColor Cyan Invoke-LoggedCommand "npm run build" -GroupOutput - # Run linting (Linux only, as CI runs on Linux) + # Step 2: Run linting (Linux only, as CI runs on Linux) if ($IsLinux) { + Write-Host "`n=== Running lint checks ===" -ForegroundColor Cyan Invoke-LoggedCommand "npm run lint" -GroupOutput } + # Step 3: Stamp version in package.json if prerelease if ($BuildNumber) { - Write-Host "Updating package.json to version: $emitterVersion`n" - + Write-Host "`n=== Updating package.json version to $emitterVersion ===" -ForegroundColor Cyan $packageJson = Get-Content -Raw "package.json" | ConvertFrom-Json -AsHashtable $packageJson.version = $emitterVersion $packageJson | ConvertTo-Json -Depth 100 | Out-File -Path "package.json" -Encoding utf8 -NoNewline -Force } - # pack the emitter - $file = Invoke-LoggedCommand "npm pack -q" - Copy-Item $file -Destination "$outputPath/packages" + # Step 4: Create npm package + Write-Host "`n=== Creating npm package ===" -ForegroundColor Cyan + Invoke-LoggedCommand "npm pack" + Copy-Item "typespec-http-client-python-$emitterVersion.tgz" -Destination "$outputPath/packages" - # verify package can be installed - Invoke-LoggedCommand "npm install $file" -GroupOutput + # Step 5: Verify package can be installed + Write-Host "`n=== Verifying package installation ===" -ForegroundColor Cyan + Invoke-LoggedCommand "npm install typespec-http-client-python-$emitterVersion.tgz" -GroupOutput - Write-PackageInfo -packageName "typespec-http-client-python" -directoryPath "packages/http-client-python/emitter/src" -version $emitterVersion + # Write package info for publishing pipeline + Write-PackageInfo -packageName "typespec-http-client-python" ` + -directoryPath "packages/http-client-python/emitter/src" ` + -version $emitterVersion } finally { Pop-Location } +# Generate override URLs for internal publishing +$overrides = @{} if ($PublishType -eq "internal") { $feedUrl = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry" - - $overrides = @{ - "@typespec/http-client-python" = "$feedUrl/@typespec/http-client-python/-/http-client-python-$emitterVersion.tgz" - } -} else { - $overrides = @{} + $overrides["@typespec/http-client-python"] = "$feedUrl/@typespec/http-client-python/-/http-client-python-$emitterVersion.tgz" } - $overrides | ConvertTo-Json | Set-Content "$outputPath/overrides.json" +# Write package version matrix @{ "emitter" = $emitterVersion } | ConvertTo-Json | Set-Content "$outputPath/package-versions.json" + +Write-Host "`n=== Build complete ===" -ForegroundColor Green +Write-Host "Output: $outputPath" From 08c6fdc2c35e4d56482d23afb0c6e1f0c428ac71 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2026 16:48:23 -0400 Subject: [PATCH 11/11] chore: remove unused pnpm install from build-step.yml Neither Python nor C# build scripts use pnpm, so the global install is unnecessary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/emitters/pipelines/templates/steps/build-step.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/eng/emitters/pipelines/templates/steps/build-step.yml b/eng/emitters/pipelines/templates/steps/build-step.yml index 4dc72eb5cfa..2352b172f38 100644 --- a/eng/emitters/pipelines/templates/steps/build-step.yml +++ b/eng/emitters/pipelines/templates/steps/build-step.yml @@ -85,9 +85,6 @@ steps: arguments: -UseTypeSpecNext:$${{ parameters.UseTypeSpecNext }} workingDirectory: $(selfRepositoryPath) - - script: npm install -g pnpm - displayName: Install pnpm - - task: PowerShell@2 displayName: "Run build script" name: ci_build