Skip to content

Commit 2c0fdc3

Browse files
committed
fix(): choco install and package arguments
Update how `choco` is called with install when install or package arguments are provided. Add a timer to know how long an install was. Do not display progress when in CI.
1 parent 63536ba commit 2c0fdc3

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

WebKitDev/Functions/Install-FromChoco.ps1

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<#
66
.Synopsis
7-
Installs a Windows package through choco.
7+
Installs a Windows package through chocolatey.
88
99
.Description
1010
Installs a package from chocolatey onto the system.
@@ -56,25 +56,35 @@ function Install-FromChoco {
5656
)
5757

5858
$chocoArgs = @('install',$name,'--confirm');
59-
$chocoArgs += $options;
6059

6160
if ($version) {
6261
$chocoArgs += @('--version',$version);
6362
}
6463

64+
# The progress status is very noisy in CI environments so turn it off
65+
if (Test-Path env:CI) {
66+
$chocoArgs += '--no-progress';
67+
}
68+
6569
if ($installerOptions) {
66-
$chocoArgs += @('--install-arguments',("'{0}'" -f ($installerOptions -join ' ')));
70+
$joined = ($installerOptions -join ' ');
71+
$chocoArgs += ('--install-arguments="{0}"' -f ($joined -replace '"','""'));
6772
}
6873

6974
if ($packageParameters) {
70-
$chocoArgs += @('--package-parameters',("'{0}'" -f ($packageParameters -join ' ')));
75+
$joined = ($packageParameters -join ' ');
76+
$chocoArgs += ('--package-parameters="{0}"' -f ($joined -replace '"','""'));
7177
}
7278

73-
Write-Information ('choco {0}' -f ($chocoArgs -join ' '));
79+
$chocoArgs += $options;
80+
81+
Write-Information -MessageData ('choco {0}' -f ($chocoArgs -join ' ')) -InformationAction Continue;
82+
$startTime = Get-Date;
7483
$process = Start-Process choco -Passthru -NoNewWindow -ArgumentList $chocoArgs;
7584
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments','',Scope = 'Function')]
7685
$handle = $process.Handle;
7786
$process.WaitForExit();
87+
$endTime = Get-Date;
7888

7989
if ($process.ExitCode -ne 0) {
8090
Write-Error ('{0} installer failed with exit code {1}' -f $name,$process.ExitCode) -ErrorAction Stop;
@@ -95,4 +105,6 @@ function Install-FromChoco {
95105
Write-Information -MessageData $verifyCommand -InformationAction Continue;
96106
Invoke-Expression $verifyCommand;
97107
}
108+
109+
Write-Information -MessageData ('Installation of {0} completed in {1:mm} min {1:ss} sec' -f $name,($endTime - $startTime)) -InformationAction Continue;
98110
}

0 commit comments

Comments
 (0)