Merge pull request #16 from actions/v-nibyko/boost

Add GetToolDirectory function and fix Get-CommandResult to work properly on Windows
pull/19/head
MaksimZhukov 4 years ago committed by GitHub
commit 4b0fa42d99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

Loading…
Cancel
Save