From 6e74a6659f514c90b5e9f00574056f8783f4d3b1 Mon Sep 17 00:00:00 2001 From: Erik Bershel Date: Tue, 26 Mar 2024 15:24:45 +0100 Subject: [PATCH 1/4] [Windows] Add WIX binaries folder to the PATH --- images/windows/scripts/build/Install-Wix.ps1 | 12 ++++++++++++ images/windows/scripts/tests/Wix.Tests.ps1 | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/images/windows/scripts/build/Install-Wix.ps1 b/images/windows/scripts/build/Install-Wix.ps1 index 0fd90bf329df..fb9a1dae5ff6 100644 --- a/images/windows/scripts/build/Install-Wix.ps1 +++ b/images/windows/scripts/build/Install-Wix.ps1 @@ -5,4 +5,16 @@ Install-ChocoPackage wixtoolset -ArgumentList "--force" +# Add WIX binaries to PATH +$wixBinPath = Join-Path -Path $env:WIX -ChildPath 'bin' +if (Test-Path $wixBinPath) { + $currentPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + $newPath = $currentPath + ";$wixBinPath" + Write-Host "Add $wixBinPath to PATH" + [Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") + $env:Path += ";$wixBinPath" +}else{ + Write-Error "WIX binaries folder ($wixBinPath) not found." +} + Invoke-PesterTests -TestFile "Wix" diff --git a/images/windows/scripts/tests/Wix.Tests.ps1 b/images/windows/scripts/tests/Wix.Tests.ps1 index 66937f696969..709ac2f02a8c 100644 --- a/images/windows/scripts/tests/Wix.Tests.ps1 +++ b/images/windows/scripts/tests/Wix.Tests.ps1 @@ -8,4 +8,8 @@ Describe "Wix" { It "Wix Toolset version from registry" { $version | Should -Not -BeNullOrEmpty } + + It "Wix binaries are available via env:Path" { + candle.exe -? | Should -Not -BeNullOrEmpty + } } From f49fc5a6fc589562f8de5dd249c7c85fd29d71ed Mon Sep 17 00:00:00 2001 From: Erik Bershel Date: Thu, 28 Mar 2024 14:19:32 +0100 Subject: [PATCH 2/4] Add Update-Environment, small prettifying --- images/windows/scripts/build/Install-Wix.ps1 | 7 +++---- images/windows/scripts/tests/Wix.Tests.ps1 | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/images/windows/scripts/build/Install-Wix.ps1 b/images/windows/scripts/build/Install-Wix.ps1 index fb9a1dae5ff6..3ff56f63107e 100644 --- a/images/windows/scripts/build/Install-Wix.ps1 +++ b/images/windows/scripts/build/Install-Wix.ps1 @@ -5,15 +5,14 @@ Install-ChocoPackage wixtoolset -ArgumentList "--force" -# Add WIX binaries to PATH +Update-Environment + $wixBinPath = Join-Path -Path $env:WIX -ChildPath 'bin' if (Test-Path $wixBinPath) { $currentPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") $newPath = $currentPath + ";$wixBinPath" - Write-Host "Add $wixBinPath to PATH" [Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") - $env:Path += ";$wixBinPath" -}else{ +} else { Write-Error "WIX binaries folder ($wixBinPath) not found." } diff --git a/images/windows/scripts/tests/Wix.Tests.ps1 b/images/windows/scripts/tests/Wix.Tests.ps1 index 709ac2f02a8c..2745c42ba6ed 100644 --- a/images/windows/scripts/tests/Wix.Tests.ps1 +++ b/images/windows/scripts/tests/Wix.Tests.ps1 @@ -9,7 +9,7 @@ Describe "Wix" { $version | Should -Not -BeNullOrEmpty } - It "Wix binaries are available via env:Path" { + It "Wix binaries are available" { candle.exe -? | Should -Not -BeNullOrEmpty } } From 8c2ee1d2e61aa6ee47ecc93f1e99a1146907f650 Mon Sep 17 00:00:00 2001 From: Erik Bershel Date: Thu, 28 Mar 2024 14:37:52 +0100 Subject: [PATCH 3/4] Move tests from script to Pester --- images/windows/scripts/build/Install-Wix.ps1 | 13 ++++--------- images/windows/scripts/tests/Wix.Tests.ps1 | 12 ++++++++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/images/windows/scripts/build/Install-Wix.ps1 b/images/windows/scripts/build/Install-Wix.ps1 index 3ff56f63107e..d94d03da1b09 100644 --- a/images/windows/scripts/build/Install-Wix.ps1 +++ b/images/windows/scripts/build/Install-Wix.ps1 @@ -6,14 +6,9 @@ Install-ChocoPackage wixtoolset -ArgumentList "--force" Update-Environment - -$wixBinPath = Join-Path -Path $env:WIX -ChildPath 'bin' -if (Test-Path $wixBinPath) { - $currentPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") - $newPath = $currentPath + ";$wixBinPath" - [Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") -} else { - Write-Error "WIX binaries folder ($wixBinPath) not found." -} +$currentPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") +$newPath = $currentPath + ";$(Join-Path -Path $env:WIX -ChildPath "bin")" +[Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine") +Update-Environment Invoke-PesterTests -TestFile "Wix" diff --git a/images/windows/scripts/tests/Wix.Tests.ps1 b/images/windows/scripts/tests/Wix.Tests.ps1 index 2745c42ba6ed..6ac9af7cc2da 100644 --- a/images/windows/scripts/tests/Wix.Tests.ps1 +++ b/images/windows/scripts/tests/Wix.Tests.ps1 @@ -9,7 +9,15 @@ Describe "Wix" { $version | Should -Not -BeNullOrEmpty } - It "Wix binaries are available" { - candle.exe -? | Should -Not -BeNullOrEmpty + It "Wix variable exists" { + $env:WIX | Should -Not -BeNullOrEmpty + } + + It "Wix binaries folder exists" { + Test-Path -Path "$env:WIX\bin" | Should -Be $true + } + + It "Wix binaries folder is in PATH" { + $env:PATH -split ";" | Should -Contain "$env:WIX\bin" } } From 325b8e844fea4ceaebe3f49b4a521a82c7850172 Mon Sep 17 00:00:00 2001 From: Erik Bershel Date: Thu, 28 Mar 2024 17:53:31 +0100 Subject: [PATCH 4/4] Fix Wix tests to use Join-Path --------- Co-authored-by: Leon Zandman --- images/windows/scripts/tests/Wix.Tests.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/images/windows/scripts/tests/Wix.Tests.ps1 b/images/windows/scripts/tests/Wix.Tests.ps1 index 6ac9af7cc2da..cf6fc2fdf1ba 100644 --- a/images/windows/scripts/tests/Wix.Tests.ps1 +++ b/images/windows/scripts/tests/Wix.Tests.ps1 @@ -14,10 +14,11 @@ Describe "Wix" { } It "Wix binaries folder exists" { - Test-Path -Path "$env:WIX\bin" | Should -Be $true + Test-Path -Path $(Join-Path -Path $env:WIX -ChildPath "bin") | Should -Be $true } It "Wix binaries folder is in PATH" { - $env:PATH -split ";" | Should -Contain "$env:WIX\bin" + $testPath = Join-Path -Path $env:WIX -ChildPath "bin" + $env:PATH -split ";" | Should -Contain "$testPath" } }