mirror of
https://github.com/actions/versions-package-tools.git
synced 2025-12-24 18:47:15 +08:00
Merge pull request #16 from actions/v-nibyko/boost
Add GetToolDirectory function and fix Get-CommandResult to work properly on Windows
This commit is contained in:
@@ -83,3 +83,26 @@ function IsNixPlatform {
|
||||
|
||||
return ($Platform -match "macos") -or ($Platform -match "darwin") -or ($Platform -match "ubuntu") -or ($Platform -match "linux")
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Get root directory of selected tool
|
||||
#>
|
||||
function GetToolDirectory {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String]$ToolName,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String]$Version,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String]$Architecture
|
||||
)
|
||||
$targetPath = $env:AGENT_TOOLSDIRECTORY
|
||||
if ([string]::IsNullOrEmpty($targetPath)) {
|
||||
# GitHub Windows images don't have `AGENT_TOOLSDIRECTORY` variable
|
||||
$targetPath = $env:RUNNER_TOOL_CACHE
|
||||
}
|
||||
$ToolcachePath = Join-Path -Path $targetPath -ChildPath $ToolName
|
||||
$ToolcacheVersionPath = Join-Path -Path $ToolcachePath -ChildPath $Version
|
||||
return Join-Path $ToolcacheVersionPath $Architecture
|
||||
}
|
||||
|
||||
@@ -6,14 +6,19 @@ Pester extension that allows to run command and validate exit code
|
||||
#>
|
||||
|
||||
function Get-CommandResult {
|
||||
param (
|
||||
Param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $Command,
|
||||
[switch] $Multiline
|
||||
)
|
||||
# Bash trick to suppress and show error output because some commands write to stderr (for example, "python --version")
|
||||
$stdout = & bash -c "$Command 2>&1"
|
||||
# CMD and bash trick to suppress and show error output because some commands write to stderr (for example, "python --version")
|
||||
If ($IsWindows) {
|
||||
$stdout = & $env:comspec /c "$Command 2>&1"
|
||||
} else {
|
||||
$stdout = & bash -c "$Command 2>&1"
|
||||
}
|
||||
$exitCode = $LASTEXITCODE
|
||||
|
||||
return @{
|
||||
Output = If ($Multiline -eq $true) { $stdout } else { [string]$stdout }
|
||||
ExitCode = $exitCode
|
||||
|
||||
Reference in New Issue
Block a user