From 08f4f50bcce62a7c62cbd10ae68b810def38b621 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Oct 2025 17:11:44 +0700 Subject: [PATCH] Fix critical script exit issues - Bypass admin check to prevent early exit (runner is already admin) - Bypass execution policy check (already set in workflow) - Improve Read-Host to handle empty prompts (return 'yes' instead of empty) - Override $myInvocation to prevent admin restart attempts - Change ErrorActionPreference to Continue for better error visibility - Add better handling for all prompt types --- .github/scripts/run-coremaker-automated.ps1 | 26 +++++++++++++++++---- .github/scripts/run-maker-automated.ps1 | 26 +++++++++++++++++---- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/.github/scripts/run-coremaker-automated.ps1 b/.github/scripts/run-coremaker-automated.ps1 index 8e217b0..dd66d61 100644 --- a/.github/scripts/run-coremaker-automated.ps1 +++ b/.github/scripts/run-coremaker-automated.ps1 @@ -41,21 +41,27 @@ $scriptContent = Get-Content $scriptPath -Raw -ErrorAction Stop # Fix missing $ScratchDisk variable (should be $mainOSDrive) $scriptContent = $scriptContent -replace '\$ScratchDisk', '$mainOSDrive' +# Disable admin restart check by commenting out the exit +$scriptContent = $scriptContent -replace 'if \(!\s*\$myWindowsPrincipal\.IsInRole\(\$adminRole\)\)', 'if ($false -and !$myWindowsPrincipal.IsInRole($adminRole)) # Disabled for GitHub Actions' + +# Disable execution policy check by commenting out the exit +$scriptContent = $scriptContent -replace 'if \(\(Get-ExecutionPolicy\) -eq ''Restricted''\)', 'if ($false -and (Get-ExecutionPolicy) -eq ''Restricted'') # Disabled for GitHub Actions' + # Create a temporary script with auto-answers $ISODriveLetter = $ISODrive -replace ':', '' $dotNetAnswer = if ($EnableDotNet35) { "y" } else { "n" } $tempScriptHeader = @" -`$ErrorActionPreference = 'Stop' +`$ErrorActionPreference = 'Continue' # Continue on errors to see full output -# Override Read-Host to auto-answer prompts +# Override Read-Host BEFORE any script execution to ensure all prompts are handled function Read-Host { param([string]`$Prompt) Write-Host "`$Prompt" - # Auto-answer execution policy prompt (yes/no) - if (`$Prompt -eq "" -or `$Prompt -match "change it to RemoteSigned") { + # Auto-answer execution policy prompt (yes/no) - handle empty prompt too + if (`$Prompt -eq "" -or `$Prompt -match "change it to RemoteSigned" -or `$Prompt -match "Execution Policy" -or `$Prompt -match "Restricted") { Write-Host "Auto-answering: yes" return "yes" } @@ -89,10 +95,20 @@ function Read-Host { return "" } - # Default: return empty + # Default: return empty or "yes" for empty prompts + if (`$Prompt -eq "") { + return "yes" + } return "" } +# Override $myInvocation to prevent admin restart +`$script:myInvocation = @{ + MyCommand = @{ + Definition = `$PSCommandPath + } +} + "@ $tempScriptPath = Join-Path $env:TEMP "tiny11coremaker-automated-$(Get-Date -Format 'yyyyMMddHHmmss').ps1" diff --git a/.github/scripts/run-maker-automated.ps1 b/.github/scripts/run-maker-automated.ps1 index cae447b..88c955e 100644 --- a/.github/scripts/run-maker-automated.ps1 +++ b/.github/scripts/run-maker-automated.ps1 @@ -42,9 +42,15 @@ $ISODriveLetter = $ISODrive -replace ':', '' # Read the script content to modify it for automation $scriptContent = Get-Content $scriptPath -Raw -ErrorAction Stop +# Disable admin restart check by commenting out the exit +$scriptContent = $scriptContent -replace 'if \(!\s*\$myWindowsPrincipal\.IsInRole\(\$adminRole\)\)', 'if ($false -and !$myWindowsPrincipal.IsInRole($adminRole)) # Disabled for GitHub Actions' + +# Disable execution policy check by commenting out the exit +$scriptContent = $scriptContent -replace 'if \(\(Get-ExecutionPolicy\) -eq ''Restricted''\)', 'if ($false -and (Get-ExecutionPolicy) -eq ''Restricted'') # Disabled for GitHub Actions' + # Create a temporary script with auto-answers for image index $tempScriptHeader = @" -`$ErrorActionPreference = 'Stop' +`$ErrorActionPreference = 'Continue' # Continue on errors to see full output # Set ISO parameter if not already set if (-not `$ISO) { @@ -54,14 +60,14 @@ if (-not `$SCRATCH -and '$ScratchDrive' -ne '') { `$SCRATCH = '$ScratchDrive' } -# Override Read-Host to auto-answer prompts +# Override Read-Host BEFORE any script execution to ensure all prompts are handled function Read-Host { param([string]`$Prompt) Write-Host "`$Prompt" - # Auto-answer execution policy prompt (yes/no) - if (`$Prompt -eq "" -or `$Prompt -match "change it to RemoteSigned") { + # Auto-answer execution policy prompt (yes/no) - handle empty prompt too + if (`$Prompt -eq "" -or `$Prompt -match "change it to RemoteSigned" -or `$Prompt -match "Execution Policy" -or `$Prompt -match "Restricted") { Write-Host "Auto-answering: yes" return "yes" } @@ -86,10 +92,20 @@ function Read-Host { return "" } - # Default: return empty + # Default: return empty or "yes" for empty prompts + if (`$Prompt -eq "") { + return "yes" + } return "" } +# Override $myInvocation to prevent admin restart +`$script:myInvocation = @{ + MyCommand = @{ + Definition = `$PSCommandPath + } +} + "@ $tempScriptPath = Join-Path $env:TEMP "tiny11maker-automated-$(Get-Date -Format 'yyyyMMddHHmmss').ps1"