Files
install-jq-action/scripts/windowsish.ps1
2023-09-14 17:14:55 -05:00

59 lines
1.4 KiB
PowerShell
Executable File

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
Write-Host "::group::Prep"
# validate input and prepare some vars
switch ($Env:RUNNER_ARCH)
{
"X86" {
$_bin_name = "jq-win32.exe"
}
"X64" {
$_bin_name = "jq-win64.exe"
}
default {
Write-Host "Cannot handle arch of type $Env:RUNNER_ARCH"
Write-Host "Expected one of: [ X86 X64 ]"
exit 1
}
}
$_base_url = "https://github.com/stedolan/jq/releases/download"
$_dl_name = "${_bin_name}"
$_dl_path = "$Env:RUNNER_TEMP\${_dl_name}"
$_dl_url = "${_base_url}/jq-$Env:JQ_VERSION/${_dl_name}"
Write-Host "::endgroup::"
# download artifact
Write-Host "::group::Downloading jq"
Write-Host "Src: ${_dl_url}"
Write-Host "Dst: ${_dl_path}"
Invoke-WebRequest -Uri "${_dl_url}" -OutFile "${_dl_path}"
Write-Host "::endgroup::"
# install into tool cache
Write-Host "::group::Copying to tool cache"
Write-Host "Creating tool cache directory $Env:RUNNER_TOOL_CACHE\jq\"
New-Item "$Env:RUNNER_TOOL_CACHE\jq\" -ItemType Directory -Force
Write-Host "Installing into tool cache:"
Write-Host "Src: $Env:RUNNER_TEMP\${_bin_name}"
Write-Host "Dst: $Env:RUNNER_TOOL_CACHE\jq\jq.exe"
Move-Item -Force -LiteralPath "$Env:RUNNER_TEMP\${_bin_name}" -Destination "$Env:RUNNER_TOOL_CACHE\jq\jq.exe"
Write-Host "Adding $Env:RUNNER_TOOL_CACHE\jq\ to path..."
Add-Content "$Env:GITHUB_PATH" "$Env:RUNNER_TOOL_CACHE\jq\"
Write-Host "::endgroup::"