Skip to content

Commit 2d7e7f6

Browse files
committed
Fix invoke
1 parent a8c0c90 commit 2d7e7f6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Main.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
99
. "$scriptPath/scripts/utils/Minimize.ps1" # To get better screenshots we need to minimize the "Administrator" CMD window
1010
. "$scriptPath/scripts/utils/TimedMessage.ps1"
1111
. "$scriptPath/scripts/utils/Invoke.ps1" # Function to invoke a script with a timeout
12+
. "$scriptPath/utils/Screenshot.ps1"
1213

1314
# Start the main timer
1415
$mainTimer = [System.Diagnostics.Stopwatch]::StartNew()
@@ -111,8 +112,15 @@ foreach ($folder in $folders) {
111112
$success = Invoke-ScriptWithTimeout -ScriptPath $buildVbaScriptPath -Arguments @("${SourceDir}/${folder}", "$app") -TimeoutSeconds 300
112113

113114
if (-not $success) {
114-
Write-TimedMessage "🔴 Build-VBA.ps1 execution timed out or failed for ${folder}. Continuing with next file..." -ForegroundColor Yellow
115-
# Optionally add cleanup code here
115+
Write-TimedMessage "🔴 Build-VBA.ps1 execution timed out or failed for ${folder}. Continuing with next file..."
116+
117+
$screenshotDir = ${SourceDir} + "screenshots/"
118+
if (-not (Test-Path $screenshotDir)) {
119+
New-Item -ItemType Directory -Path $screenshotDir -Force | Out-Null
120+
Write-Host "Created screenshot directory: $screenshotDir"
121+
}
122+
123+
Take-Screenshot -FileName "${screenshotDir}${app}_{{timestamp}}.png"
116124
}
117125

118126
Write-TimedMessage "Completed processing folder: $folder"

scripts/utils/Invoke.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
function Invoke-ScriptWithTimeout {
32
param (
43
[string]$ScriptPath,
@@ -7,14 +6,15 @@ function Invoke-ScriptWithTimeout {
76
)
87

98
$job = Start-Job -ScriptBlock {
10-
param($scriptPath, $args)
11-
& $scriptPath $args
9+
param($scriptPath, $arguments)
10+
# Properly expand the arguments when calling the script
11+
& $scriptPath @arguments
1212
} -ArgumentList $ScriptPath, $Arguments
1313

1414
$completed = Wait-Job -Job $job -Timeout $TimeoutSeconds
1515

1616
if ($completed -eq $null) {
17-
Write-Host "Script execution timed out after $TimeoutSeconds seconds" -ForegroundColor Red
17+
Write-Host "🔴 Script execution timed out after $TimeoutSeconds seconds" -ForegroundColor Red
1818
Stop-Job -Job $job
1919
Remove-Job -Job $job -Force
2020
return $false

0 commit comments

Comments
 (0)