Files
OpenShell/tasks/scripts/typescript-proto.ps1
Prekshi VyasandShailendra Singh d95bab5436 fix(ci): upstream Windows SDK validation support (#3327)
* fix(ci): upstream Windows SDK validation support

Port remaining Windows validation tooling from GitLab independently of the combined MXC runtime port. Preserve locked SDK dependencies and guard temporary launcher cleanup.

Co-authored-by: Shailendra Singh <shailendras@nvidia.com>
Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com>

* fix(ci): install native TypeScript dependencies before validation

Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com>

---------

Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com>
Co-authored-by: Shailendra Singh <shailendras@nvidia.com>
2026-09-15 22:34:36 +00:00

59 lines
2.2 KiB
PowerShell

# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$repository = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
$sdkRoot = Join-Path $repository 'sdk\typescript'
$sourceTemplate = Join-Path $sdkRoot 'buf.gen.yaml'
$buf = (Resolve-Path (Join-Path $sdkRoot 'node_modules\.bin\buf.cmd')).Path
$plugin = (Resolve-Path (Join-Path $sdkRoot 'node_modules\.bin\protoc-gen-es.cmd')).Path
$temporaryRoot = Join-Path ([IO.Path]::GetTempPath()) "openshell-ts-proto-$([guid]::NewGuid().ToString('N'))"
$windowsTemplate = Join-Path $temporaryRoot 'buf.gen.windows.yaml'
$tempPrefix = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd('\', '/') + [IO.Path]::DirectorySeparatorChar
if (-not [IO.Path]::GetFullPath($temporaryRoot).StartsWith($tempPrefix, [StringComparison]::OrdinalIgnoreCase)) {
throw 'Protobuf temporary directory escaped the temporary root'
}
New-Item -ItemType Directory -Path $temporaryRoot | Out-Null
try {
$pluginPath = $plugin.Replace('\', '/')
$template = [IO.File]::ReadAllText($sourceTemplate).Replace(
'./node_modules/.bin/protoc-gen-es',
$pluginPath
)
[IO.File]::WriteAllText(
$windowsTemplate,
$template,
[Text.UTF8Encoding]::new($false)
)
Push-Location $sdkRoot
try {
& $buf generate --template $windowsTemplate
if ($LASTEXITCODE -ne 0) {
throw "TypeScript protobuf generation failed with exit code $LASTEXITCODE."
}
}
finally {
Pop-Location
}
}
finally {
if (
(Test-Path -LiteralPath $temporaryRoot) -and
(Split-Path -Leaf $temporaryRoot) -like 'openshell-ts-proto-*'
) {
$resolvedTemp = (Resolve-Path -LiteralPath $temporaryRoot).ProviderPath
if (-not $resolvedTemp.StartsWith($tempPrefix, [StringComparison]::OrdinalIgnoreCase) -or
((Get-Item -LiteralPath $temporaryRoot).Attributes -band [IO.FileAttributes]::ReparsePoint)) {
throw 'Refusing to remove an unexpected protobuf temporary directory'
}
Remove-Item -LiteralPath $temporaryRoot -Recurse -Force
}
}