mirror of
https://github.com/hanzoai/azure-sdk-for-js.git
synced 2026-10-30 19:51:51 +00:00
Sync eng/common directory with azure-sdk-tools for PR https://github.com/Azure/azure-sdk-tools/pull/12532 See [eng/common workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow) --------- Co-authored-by: Wes Haggard <[email protected]> Co-authored-by: Wes Haggard <[email protected]>
85 lines
1.8 KiB
PowerShell
85 lines
1.8 KiB
PowerShell
. $PSScriptRoot/../logging.ps1
|
|
|
|
function Invoke-LoggedMsbuildCommand
|
|
{
|
|
[CmdletBinding()]
|
|
param
|
|
(
|
|
[string] $Command,
|
|
[string] $ExecutePath,
|
|
[switch] $GroupOutput,
|
|
[int[]] $AllowedExitCodes = @(0)
|
|
)
|
|
return Invoke-LoggedCommand $Command -ExecutePath $ExecutePath -GroupOutput:$GroupOutput -AllowedExitCodes $AllowedExitCodes -OutputProcessor { param($line) ProcessMsBuildLogLine $line }
|
|
|
|
}
|
|
|
|
function Invoke-LoggedCommand
|
|
{
|
|
[CmdletBinding()]
|
|
param
|
|
(
|
|
[string] $Command,
|
|
[string] $ExecutePath,
|
|
[switch] $GroupOutput,
|
|
[int[]] $AllowedExitCodes = @(0),
|
|
[switch] $DoNotExitOnFailedExitCode,
|
|
[scriptblock] $OutputProcessor
|
|
)
|
|
|
|
$startTime = Get-Date
|
|
|
|
if($GroupOutput) {
|
|
LogGroupStart $Command
|
|
} else {
|
|
Write-Host "> $Command"
|
|
}
|
|
|
|
if($ExecutePath) {
|
|
Push-Location $ExecutePath
|
|
}
|
|
|
|
if (!$OutputProcessor) {
|
|
$OutputProcessor = { param($line) $line }
|
|
}
|
|
|
|
try {
|
|
Invoke-Expression $Command | Foreach-Object { & $OutputProcessor $_ }
|
|
|
|
$duration = (Get-Date) - $startTime
|
|
|
|
if($GroupOutput) {
|
|
LogGroupEnd
|
|
}
|
|
|
|
if($LASTEXITCODE -notin $AllowedExitCodes)
|
|
{
|
|
LogError "Command failed to execute ($duration): $Command`n"
|
|
if (!$DoNotExitOnFailedExitCode) {
|
|
exit $LASTEXITCODE
|
|
}
|
|
}
|
|
else {
|
|
Write-Host "Command succeeded ($duration)`n"
|
|
}
|
|
}
|
|
finally {
|
|
if($ExecutePath) {
|
|
Pop-Location
|
|
}
|
|
}
|
|
}
|
|
|
|
function Set-ConsoleEncoding
|
|
{
|
|
[CmdletBinding()]
|
|
param
|
|
(
|
|
[string] $Encoding = 'utf-8'
|
|
)
|
|
|
|
$outputEncoding = [System.Text.Encoding]::GetEncoding($Encoding)
|
|
[Console]::OutputEncoding = $outputEncoding
|
|
[Console]::InputEncoding = $outputEncoding
|
|
}
|