mirror of
https://github.com/actions/node-versions.git
synced 2025-07-01 21:07:24 +08:00
39 lines
1.6 KiB
PowerShell
39 lines
1.6 KiB
PowerShell
$ErrorActionPreference = "Stop"
|
|
[Version]$Version = "{{__VERSION__}}"
|
|
[string]$Architecture = "{{__ARCHITECTURE__}}"
|
|
$ArchiveFileName = "tool.7z"
|
|
$TempDirectory = Join-Path $env:TEMP "Node"
|
|
|
|
$NodeToolcachePath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "node"
|
|
$NodeToolcacheVersionPath = Join-Path -Path $NodeToolcachePath -ChildPath $Version.ToString()
|
|
$NodeToolcacheArchitecturePath = Join-Path $NodeToolcacheVersionPath $Architecture
|
|
|
|
Write-Host "Check if Node.js hostedtoolcache folder exist..."
|
|
if (-not (Test-Path $NodeToolcachePath)) {
|
|
New-Item -ItemType Directory -Path $NodeToolcachePath | Out-Null
|
|
}
|
|
|
|
Write-Host "Delete Node.js $Version if installed"
|
|
if (Test-Path $NodeToolcacheVersionPath) {
|
|
Remove-Item $NodeToolcachePath -Recurse -Force | Out-Null
|
|
}
|
|
|
|
Write-Host "Create Node.js $Version folder"
|
|
if (-not (Test-Path $NodeToolcacheArchitecturePath)) {
|
|
New-Item -ItemType Directory -Path $NodeToolcacheArchitecturePath | Out-Null
|
|
}
|
|
|
|
Write-Host "Copy Node.js binaries to hostedtoolcache folder"
|
|
Copy-Item -Path $ArchiveFileName -Destination $NodeToolcacheArchitecturePath
|
|
|
|
Set-Location $NodeToolcacheArchitecturePath
|
|
Write-Host "Unzip Node.js to $NodeToolcacheArchitecturePath"
|
|
7z.exe x $ArchiveFileName -o"$TempDirectory" -y | Out-Null
|
|
$NodeInnerFolder = Get-Item -Path "$TempDirectory\node-*" | Select-Object -First 1
|
|
Get-ChildItem $NodeInnerFolder | Move-Item -Destination $NodeToolcacheArchitecturePath
|
|
Write-Host "Node.js unzipped successfully"
|
|
|
|
Remove-Item $ArchiveFileName -Force | Out-Null
|
|
|
|
Write-Host "Create complete file"
|
|
New-Item -ItemType File -Path $NodeToolcacheVersionPath -Name "$Architecture.complete" | Out-Null |