Skip to content

include corresponding Nuget version info to Node.js binding #24450

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 2 commits into from
Apr 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml
Original file line number Diff line number Diff line change
@@ -506,6 +506,7 @@ stages:

- stage: Nodejs_Packaging
dependsOn:
- Setup
- Windows_Nodejs_Packaging_x64
- Windows_Nodejs_Packaging_arm64
- Linux_Nodejs_Packaging_x64
@@ -523,6 +524,8 @@ stages:
${{ if not(eq(parameters.IsReleaseBuild, true)) }}:
NpmPackagingMode: 'dev'
breakCodesignValidationInjection: ${{ parameters.DoEsrp }}
BuildDate: $[stageDependencies.Setup.Set_Variables.outputs['Set_Build_Date.BuildDate']]
BuildTime: $[stageDependencies.Setup.Set_Variables.outputs['Set_Build_Time.BuildTime']]

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

- ${{ if not(eq(parameters.IsReleaseBuild, true)) }}:
- task: PowerShell@2
displayName: 'Set environment variable NODEJS_DEP_PACKAGE_VERSIONS'
inputs:
targetType: 'inline'
script: |
# The following PowerShell script is used to set environment variable "NODEJS_DEP_PACKAGE_VERSIONS" to the
# following format:
# <current_version>;<latest_existing_version>
#
# - The "current_version" is the same to the version of the Nuget package being built.
# - The "latest_existing_version" is the latest existing version of the package
# "Microsoft.ML.OnnxRuntime.Gpu.Linux" from the NuGet nightly feed.
#

$index = 'https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/nuget/v3/index.json'
$packageName = 'Microsoft.ML.OnnxRuntime.Gpu.Linux'

# Download NuGet index
$nugetIndex = Invoke-RestMethod -Uri $index -UseBasicParsing
if (-not $nugetIndex) {
throw "Failed to download NuGet index from $index"
}

# Find the base URL for "PackageBaseAddress/3.0.0"
$packageBaseUrl = ($nugetIndex.resources | Where-Object { $_.'@type' -eq 'PackageBaseAddress/3.0.0' }).'@id'
if (-not $packageBaseUrl) {
throw "Failed to find PackageBaseAddress in NuGet index"
}

# Fetch package version info
$packageInfo = Invoke-RestMethod -Uri "$packageBaseUrl$($packageName.ToLower())/index.json" -UseBasicParsing
if (-not $packageInfo.versions -or $packageInfo.versions.Count -eq 0) {
throw "No versions found for package $packageName"
}

# Extract the latest version
$devVersions = $packageInfo.versions | Where-Object { $_ -match '-dev-' }
$latestVersion = $devVersions[0]
Write-Host "Latest version of ${packageName}: $latestVersion"

# Generate current version
$currentVersion = "$(cat .\VERSION_NUMBER)-dev-$($env:BuildDate)-$($env:BuildTime)-$(git rev-parse --short HEAD)"
Write-Host "Current version: $currentVersion"

# Set the version as an environment variable
Write-Host "##vso[task.setvariable variable=NODEJS_DEP_PACKAGE_VERSIONS]$currentVersion;$latestVersion"
Write-Host "Environment variable NODEJS_DEP_PACKAGE_VERSIONS set to $currentVersion;$latestVersion"
workingDirectory: '$(Build.SourcesDirectory)'

- task: PowerShell@2
inputs:
filePath: '$(Build.SourcesDirectory)\tools\ci_build\github\js\pack-npm-packages.ps1'
arguments: '$(NpmPackagingMode) $(Build.SourcesDirectory) node'
arguments: '$(NpmPackagingMode) "$(Build.SourcesDirectory)" node "$env:NODEJS_DEP_PACKAGE_VERSIONS"'
workingDirectory: $(Build.BinariesDirectory)
errorActionPreference: stop
displayName: 'Pack NPM packages'