From 20ae425d90da477fe5eaf2eeffd5a784eeea30c5 Mon Sep 17 00:00:00 2001 From: Zaldaryon <273555259+Zaldaryon@users.noreply.github.com> Date: Thu, 17 Sep 2026 08:11:13 -0300 Subject: [PATCH] Bypass execution policy and skip profile when launching PowerShell in ScriptBuildDriver Windows client machines default to the Restricted PowerShell execution policy, which prevents ScriptBuildDriver from executing bootstrap.ps1 and package.ps1 during source builds. Pass -NoProfile -ExecutionPolicy Bypass to PowerShell invocations on Windows, matching SdkInstaller and install-windows.cmd. Update the build layer command tests to assert the execution policy flags. --- .../BuildLayerTests.cs | 20 ++++++++++++------- .../Build/ScriptBuildDriver.cs | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Optimum.Bootstrap.Core.Tests/BuildLayerTests.cs b/Optimum.Bootstrap.Core.Tests/BuildLayerTests.cs index 8333c227..31c54ec0 100644 --- a/Optimum.Bootstrap.Core.Tests/BuildLayerTests.cs +++ b/Optimum.Bootstrap.Core.Tests/BuildLayerTests.cs @@ -213,9 +213,12 @@ public void BootstrapCommandUsesAnAbsoluteScriptPathFromTheSourceRoot() var command = new ScriptBuildDriver(probe).BootstrapCommand(request); - Assert.Equal("-File", command.Args[0]); - Assert.Equal(Path.GetFullPath(Path.Combine(repo, "scripts", "bootstrap.ps1")), command.Args[1]); - Assert.True(Path.IsPathFullyQualified(command.Args[1])); + Assert.Equal("-NoProfile", command.Args[0]); + Assert.Equal("-ExecutionPolicy", command.Args[1]); + Assert.Equal("Bypass", command.Args[2]); + Assert.Equal("-File", command.Args[3]); + Assert.Equal(Path.GetFullPath(Path.Combine(repo, "scripts", "bootstrap.ps1")), command.Args[4]); + Assert.True(Path.IsPathFullyQualified(command.Args[4])); } [Fact] @@ -228,9 +231,12 @@ public void PackageCommandUsesAnAbsoluteScriptPathFromTheSourceRoot() var command = new ScriptBuildDriver(probe).PackageCommand(request); - Assert.Equal("-File", command.Args[0]); - Assert.Equal(Path.GetFullPath(Path.Combine(repo, "scripts", "package.ps1")), command.Args[1]); - Assert.True(Path.IsPathFullyQualified(command.Args[1])); - Assert.Equal(output, command.Args[3]); + Assert.Equal("-NoProfile", command.Args[0]); + Assert.Equal("-ExecutionPolicy", command.Args[1]); + Assert.Equal("Bypass", command.Args[2]); + Assert.Equal("-File", command.Args[3]); + Assert.Equal(Path.GetFullPath(Path.Combine(repo, "scripts", "package.ps1")), command.Args[4]); + Assert.True(Path.IsPathFullyQualified(command.Args[4])); + Assert.Equal(output, command.Args[6]); } } diff --git a/Optimum.Bootstrap.Core/Build/ScriptBuildDriver.cs b/Optimum.Bootstrap.Core/Build/ScriptBuildDriver.cs index 56be4571..de757dd0 100644 --- a/Optimum.Bootstrap.Core/Build/ScriptBuildDriver.cs +++ b/Optimum.Bootstrap.Core/Build/ScriptBuildDriver.cs @@ -115,7 +115,7 @@ public async Task RunAsync( { if (probe.Os == OsKind.Windows) { - List win = ["-File", ScriptPath(request.RepoRoot, "bootstrap.ps1")]; + List win = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ScriptPath(request.RepoRoot, "bootstrap.ps1")]; if (request.ClientArchive is not null) win.AddRange(["-ClientArchive", request.ClientArchive]); if (request.Version is not null) @@ -137,7 +137,7 @@ public async Task RunAsync( switch (probe.Os) { case OsKind.Windows: - List win = ["-File", ScriptPath(request.RepoRoot, "package.ps1"), "-OutputDir", output]; + List win = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ScriptPath(request.RepoRoot, "package.ps1"), "-OutputDir", output]; if (request.ClientArchive is not null) win.AddRange(["-ClientArchive", request.ClientArchive]); return (PwshExecutable(), win); case OsKind.MacOs: