Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a256e2a

Browse files
fs-eireashrit-ms
authored andcommittedApr 24, 2025
include corresponding Nuget version info to Node.js binding (#24450)
### Description Update the packaging pipeline to include the corresponding Nuget version info for Node.js binding. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. -->
1 parent 9dbc6a1 commit a256e2a

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed
 

‎tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ stages:
506506

507507
- stage: Nodejs_Packaging
508508
dependsOn:
509+
- Setup
509510
- Windows_Nodejs_Packaging_x64
510511
- Windows_Nodejs_Packaging_arm64
511512
- Linux_Nodejs_Packaging_x64
@@ -523,6 +524,8 @@ stages:
523524
${{ if not(eq(parameters.IsReleaseBuild, true)) }}:
524525
NpmPackagingMode: 'dev'
525526
breakCodesignValidationInjection: ${{ parameters.DoEsrp }}
527+
BuildDate: $[stageDependencies.Setup.Set_Variables.outputs['Set_Build_Date.BuildDate']]
528+
BuildTime: $[stageDependencies.Setup.Set_Variables.outputs['Set_Build_Time.BuildTime']]
526529

527530
steps:
528531
- checkout: self
@@ -717,10 +720,60 @@ stages:
717720
*.node
718721
TargetFolder: '$(Build.SourcesDirectory)\js\node\bin\napi-v6\darwin\arm64'
719722

723+
- ${{ if not(eq(parameters.IsReleaseBuild, true)) }}:
724+
- task: PowerShell@2
725+
displayName: 'Set environment variable NODEJS_DEP_PACKAGE_VERSIONS'
726+
inputs:
727+
targetType: 'inline'
728+
script: |
729+
# The following PowerShell script is used to set environment variable "NODEJS_DEP_PACKAGE_VERSIONS" to the
730+
# following format:
731+
# <current_version>;<latest_existing_version>
732+
#
733+
# - The "current_version" is the same to the version of the Nuget package being built.
734+
# - The "latest_existing_version" is the latest existing version of the package
735+
# "Microsoft.ML.OnnxRuntime.Gpu.Linux" from the NuGet nightly feed.
736+
#
737+
738+
$index = 'https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/nuget/v3/index.json'
739+
$packageName = 'Microsoft.ML.OnnxRuntime.Gpu.Linux'
740+
741+
# Download NuGet index
742+
$nugetIndex = Invoke-RestMethod -Uri $index -UseBasicParsing
743+
if (-not $nugetIndex) {
744+
throw "Failed to download NuGet index from $index"
745+
}
746+
747+
# Find the base URL for "PackageBaseAddress/3.0.0"
748+
$packageBaseUrl = ($nugetIndex.resources | Where-Object { $_.'@type' -eq 'PackageBaseAddress/3.0.0' }).'@id'
749+
if (-not $packageBaseUrl) {
750+
throw "Failed to find PackageBaseAddress in NuGet index"
751+
}
752+
753+
# Fetch package version info
754+
$packageInfo = Invoke-RestMethod -Uri "$packageBaseUrl$($packageName.ToLower())/index.json" -UseBasicParsing
755+
if (-not $packageInfo.versions -or $packageInfo.versions.Count -eq 0) {
756+
throw "No versions found for package $packageName"
757+
}
758+
759+
# Extract the latest version
760+
$devVersions = $packageInfo.versions | Where-Object { $_ -match '-dev-' }
761+
$latestVersion = $devVersions[0]
762+
Write-Host "Latest version of ${packageName}: $latestVersion"
763+
764+
# Generate current version
765+
$currentVersion = "$(cat .\VERSION_NUMBER)-dev-$($env:BuildDate)-$($env:BuildTime)-$(git rev-parse --short HEAD)"
766+
Write-Host "Current version: $currentVersion"
767+
768+
# Set the version as an environment variable
769+
Write-Host "##vso[task.setvariable variable=NODEJS_DEP_PACKAGE_VERSIONS]$currentVersion;$latestVersion"
770+
Write-Host "Environment variable NODEJS_DEP_PACKAGE_VERSIONS set to $currentVersion;$latestVersion"
771+
workingDirectory: '$(Build.SourcesDirectory)'
772+
720773
- task: PowerShell@2
721774
inputs:
722775
filePath: '$(Build.SourcesDirectory)\tools\ci_build\github\js\pack-npm-packages.ps1'
723-
arguments: '$(NpmPackagingMode) $(Build.SourcesDirectory) node'
776+
arguments: '$(NpmPackagingMode) "$(Build.SourcesDirectory)" node "$env:NODEJS_DEP_PACKAGE_VERSIONS"'
724777
workingDirectory: $(Build.BinariesDirectory)
725778
errorActionPreference: stop
726779
displayName: 'Pack NPM packages'

0 commit comments

Comments
 (0)
Please sign in to comment.