Show progress during the initial apply

This commit is contained in:
Dandaedre 2026-11-21 11:33:37 +01:00
parent 7f734c6d2f
commit d0800ac154
4 changed files with 81 additions and 3 deletions

View File

@ -174,3 +174,7 @@ open until it is run on disposable machines with the required account setups.
## Requested Beffroi tools
- [x] Add verified PPTX Reporter 0.2.0 portable installation and update PDF Presenter to the stable 0.1.91 release.
## Setup progress feedback
- [x] Show elapsed spinner feedback during the initial apply, keep redirected output plain, and replay child results and diagnostics after completion.

View File

@ -83,6 +83,46 @@ function Assert-BootstrapPowerShell {
}
}
function Invoke-BootstrapApply {
param(
[Parameter(Mandatory = $true)][string]$PowerShell,
[Parameter(Mandatory = $true)][string[]]$Arguments,
[Parameter(Mandatory = $true)][string]$Machine
)
$outputPath = [System.IO.Path]::GetTempFileName()
$errorPath = [System.IO.Path]::GetTempFileName()
$process = $null
$stopwatch = [Diagnostics.Stopwatch]::StartNew()
$animate = -not [Console]::IsOutputRedirected
try {
$quotedArguments = @($Arguments | ForEach-Object {
if ($_ -match '"') { throw 'Bootstrap apply arguments cannot contain quotation marks.' }
'"' + $_ + '"'
})
Write-ConfigCentralMessage -Message "Applying software and configs for '$Machine'. This can take several minutes..."
$process = Start-Process -FilePath $PowerShell -ArgumentList $quotedArguments -PassThru -NoNewWindow -RedirectStandardOutput $outputPath -RedirectStandardError $errorPath
$frames = @('|', '/', '-', '\')
$frame = 0
while (-not $process.WaitForExit(125)) {
if ($animate) {
Write-Host -NoNewline ("`r{0} Working... {1}s" -f $frames[$frame % $frames.Count], [int]$stopwatch.Elapsed.TotalSeconds)
$frame++
}
}
if ($animate) { Write-Host -NoNewline ("`r{0}`r" -f (' ' * 48)) }
$output = Get-Content -LiteralPath $outputPath -Raw -ErrorAction SilentlyContinue
$errors = Get-Content -LiteralPath $errorPath -Raw -ErrorAction SilentlyContinue
if ($output) { [Console]::Out.Write($output) }
if ($errors) { [Console]::Error.Write($errors) }
return $process.ExitCode
}
finally {
$stopwatch.Stop()
if ($process -and -not $process.HasExited) { $process.WaitForExit() }
Remove-Item -LiteralPath $outputPath, $errorPath -Force -ErrorAction SilentlyContinue
}
}
function Find-GitPath {
$command = Get-Command git.exe -ErrorAction SilentlyContinue
if ($command) { return $command.Source }
@ -218,8 +258,8 @@ if (-not $SkipApply) {
(Join-Path $Checkout 'cc.ps1'), 'apply', '-Machine', $Machine,
'-DataRoot', $dataRoot, '-RepositoryRoot', $Checkout)
if (-not $PreserveLocalConfigs) { $applyArguments += '-ForceConfigs' }
& $powerShell7 @applyArguments
exit $LASTEXITCODE
$applyExitCode = Invoke-BootstrapApply -PowerShell $powerShell7 -Arguments $applyArguments -Machine $Machine
exit $applyExitCode
}
$global:LASTEXITCODE = 0

View File

@ -87,3 +87,37 @@ Describe 'Bootstrap PowerShell prerequisites' {
{ Assert-BootstrapPowerShell -Path Test-Runtime } | Should -Throw '*could not start*'
}
}
Describe 'Bootstrap first-apply feedback' {
BeforeAll {
$fn = $bootstrapAst.Find({
param($node)
$node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq 'Invoke-BootstrapApply'
}, $true)
. ([scriptblock]::Create($fn.Extent.Text))
}
It 'shows the active machine and preserves child output, diagnostics, and exit code' {
$powerShell = (Get-Process -Id $PID).Path
Mock Write-ConfigCentralMessage
$originalOutput = [Console]::Out
$originalError = [Console]::Error
$capturedOutput = [IO.StringWriter]::new()
$capturedError = [IO.StringWriter]::new()
try {
[Console]::SetOut($capturedOutput)
[Console]::SetError($capturedError)
$code = Invoke-BootstrapApply -PowerShell $powerShell -Arguments @('-NoProfile', '-Command', 'Write-Output child-output; [Console]::Error.WriteLine(123); exit 7') -Machine 'test-machine'
}
finally {
[Console]::SetOut($originalOutput)
[Console]::SetError($originalError)
}
$code | Should -Be 7
$capturedOutput.ToString() | Should -Match 'child-output'
$capturedError.ToString() | Should -Match '123'
Should -Invoke Write-ConfigCentralMessage -Times 1 -Exactly -ParameterFilter {
$Message -match "Applying software and configs for 'test-machine'"
}
}
}

View File

@ -75,7 +75,7 @@ Describe 'Setup config replacement policy' {
$installerText = Get-Content "$PSScriptRoot/../install.ps1" -Raw
$bootstrapText = Get-Content "$PSScriptRoot/../bootstrap.ps1" -Raw
$installerArguments = [regex]::Match($installerText, '(?s) \$arguments = @\(.*?(?= & \$windowsPowerShell)').Value
$bootstrapArguments = [regex]::Match($bootstrapText, '(?s) \$applyArguments = @\(.*?(?= & \$powerShell7)').Value
$bootstrapArguments = [regex]::Match($bootstrapText, '(?s) \$applyArguments = @\(.*?(?= \$applyExitCode = Invoke-BootstrapApply)').Value
$installerArguments | Should -Not -BeNullOrEmpty
$bootstrapArguments | Should -Not -BeNullOrEmpty
$bootstrapPath = 'bootstrap.ps1'; $repository = 'https://example.test/repo.git'