Skip to content
Closed
Show file tree
Hide file tree
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
78 changes: 78 additions & 0 deletions scripts/test-pr-check-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,76 @@ $ErrorActionPreference = "Stop"

Set-Location (git rev-parse --show-toplevel)

function Find-NodeBin {
param([Parameter(Mandatory = $true)][string]$VersionPrefix)

$roots = @()
if ($env:RUNNER_TOOL_CACHE) {
$roots += $env:RUNNER_TOOL_CACHE
}
$roots += @(
"C:\hostedtoolcache\windows",
"C:\hostedtoolcache",
"C:\actions-runner\_work\_tool"
)

foreach ($root in $roots) {
$nodeRoot = Join-Path $root "node"
if (-not (Test-Path $nodeRoot)) {
continue
}

$match = Get-ChildItem -Path $nodeRoot -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name.StartsWith($VersionPrefix) } |
Sort-Object Name |
Select-Object -Last 1
Comment on lines +26 to +27

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Windows Node version lookup may select an older version when multiple patch releases are cached

The Node version directory lookup uses lexicographic string sorting (Sort-Object Name at scripts/test-pr-check-windows.ps1:26) instead of version-aware sorting, so a version like "20.20.9" is ranked higher than "20.20.10".

Impact: On a Windows runner with multiple cached Node patch releases, an older Node binary may be selected instead of the latest.

Lexicographic vs version sort mismatch with the Linux equivalent

The bash equivalent at scripts/test-pr-check.sh:39 uses sort -V (version sort), which correctly orders 20.20.9 before 20.20.10. The PowerShell Sort-Object Name does lexicographic comparison, where "20.20.9" > "20.20.10" because the character '9' > '1'. When Select-Object -Last 1 picks the last entry, it gets the wrong version.

For example, with directories 20.20.1, 20.20.2, 20.20.9, 20.20.10:

  • Bash sort -V | tail -n 120.20.10
  • PowerShell Sort-Object Name | Select-Object -Last 120.20.9
Suggested change
Sort-Object Name |
Select-Object -Last 1
Sort-Object { [version]$_.Name } |
Select-Object -Last 1
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


if ($match) {
$bin = Join-Path $match.FullName "x64"
if (Test-Path (Join-Path $bin "node.exe")) {
return $bin
}
}
}

return $null
}

function Ensure-Pnpm {
$pnpmVersion = if ($env:PNPM_VERSION) { $env:PNPM_VERSION } else { "10.33.2" }
$npmPrefix = Join-Path $env:USERPROFILE ".npm-global"
$env:PATH = "$npmPrefix;$env:PATH"

if (Get-Command pnpm -ErrorAction SilentlyContinue) {
return
}

if (Get-Command corepack -ErrorAction SilentlyContinue) {
try {
Invoke-Native corepack prepare "pnpm@$pnpmVersion" --activate
} catch {
Write-Warning "corepack could not activate pnpm: $_"
}
}

if (Get-Command pnpm -ErrorAction SilentlyContinue) {
return
}

if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
throw "Unable to find pnpm or npm on PATH."
}

New-Item -ItemType Directory -Force -Path $npmPrefix | Out-Null
Invoke-Native npm config set prefix $npmPrefix
Invoke-Native npm install -g "pnpm@$pnpmVersion"
$env:PATH = "$npmPrefix;$env:PATH"

if (-not (Get-Command pnpm -ErrorAction SilentlyContinue)) {
throw "Unable to install pnpm."
}
}

function Start-Section {
param([Parameter(Mandatory = $true)][string]$Title)

Expand Down Expand Up @@ -39,6 +109,14 @@ function Invoke-Section {
}
}

$node20Bin = Find-NodeBin "20.20"
if ($node20Bin) {
$env:PATH = "$node20Bin;$env:PATH"
}

Ensure-Pnpm
Invoke-Native pnpm --version

Invoke-Section "Install CLI dependencies" {
Invoke-Native pnpm install --frozen-lockfile --filter trigger.dev...
}
Expand Down
38 changes: 38 additions & 0 deletions scripts/test-pr-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ find_node_bin() {
find /opt/hostedtoolcache/node -maxdepth 3 -type d -path "*/${version_prefix}*/x64/bin" 2>/dev/null | sort -V | tail -n 1
}

ensure_pnpm() {
local pnpm_version="${PNPM_VERSION:-10.33.2}"
local npm_prefix="${HOME}/.npm-global"
export PATH="${npm_prefix}/bin:${PATH}"

if command -v pnpm >/dev/null 2>&1; then
return 0
fi

if command -v corepack >/dev/null 2>&1; then
corepack prepare "pnpm@${pnpm_version}" --activate || true
fi

if command -v pnpm >/dev/null 2>&1; then
return 0
fi

if ! command -v npm >/dev/null 2>&1; then
echo "Unable to find pnpm or npm on PATH." >&2
return 1
fi

mkdir -p "${npm_prefix}"
npm config set prefix "${npm_prefix}"
npm install -g "pnpm@${pnpm_version}"
export PATH="${npm_prefix}/bin:${PATH}"

command -v pnpm >/dev/null 2>&1
}

with_node() {
local node_bin="$1"
shift
Expand Down Expand Up @@ -125,6 +155,7 @@ run_sdk_runtime_compat_tests() {
}

export -f find_node_bin
export -f ensure_pnpm
export -f with_node
export -f run_webapp_unit_tests
export -f run_package_unit_tests
Expand All @@ -146,6 +177,13 @@ export NODE_OPTIONS="${NODE_OPTIONS:---max-old-space-size=8192}"
NODE20_BIN="${NODE20_BIN:-$(find_node_bin 20.20)}"
NODE22_BIN="${NODE22_BIN:-$(find_node_bin 22.12)}"

if [[ -n "${NODE20_BIN}" ]]; then
export PATH="${NODE20_BIN}:${PATH}"
fi

ensure_pnpm
pnpm --version

run_section "Install dependencies" pnpm install --frozen-lockfile
run_section "Generate Prisma client" pnpm run generate

Expand Down