Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions assets/wix/ExeLicense.rtf

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions assets/wix/bundle.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<!-- UpgradeCode GUID MUST REMAIN SAME THROUGHOUT ALL VERSIONS, otherwise, updates won't occur. -->
<?if $(sys.BUILDARCH)=x64?>
<?define UpgradeCodePreview = "3C90221B-D500-43C6-A4A6-0BE6C2C1B317"?>
<?define UpgradeCodeRelease = "7A804CBB-648E-4276-9A58-081862DB1B99"?>
<?if $(var.IsPreview)=True?>
<?define UpgradeCode = $(var.UpgradeCodePreview)?>
<?else?>
<?define UpgradeCode = $(var.UpgradeCodeRelease)?>
<?endif?>
<?else?>
<?define UpgradeCodePreview = "4A699A9C-E904-4024-BCD2-44E098A8C6BD"?>
<?define UpgradeCodeRelease = "ED46CB02-64B3-43FD-A63E-6CF269D8C21C"?>
<?if $(var.IsPreview)=True?>
<?define UpgradeCode = $(var.UpgradeCodePreview)?>
<?else?>
<?define UpgradeCode = $(var.UpgradeCodeRelease)?>
<?endif?>
<?endif?>

<Bundle Name="PowerShell $(var.WindowsVersion)-$(sys.BUILDARCH)" Version="$(var.WindowsVersion)" Manufacturer="Microsoft Corporation" UpgradeCode="$(var.UpgradeCode)">
<!-- See https://wixtoolset.org/documentation/manual/v3/bundle/wixstdba/ for a list of WiX standard bootstrapper types. -->
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense">
<bal:WixStandardBootstrapperApplication LicenseFile="assets\wix\ExeLicense.rtf" LogoFile="assets\ps_black_32x32.ico" />
</BootstrapperApplicationRef>
<Chain>
<MsiPackage SourceFile="$(var.TargetPath)" Compressed="yes" />
</Chain>
</Bundle>
</Wix>
126 changes: 126 additions & 0 deletions test/packaging/windows/exe.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe -Name "Windows EXE" -Fixture {
BeforeAll {
function Test-Elevated {
[CmdletBinding()]
[OutputType([bool])]
Param()

# if the current Powershell session was called with administrator privileges,
# the Administrator Group's well-known SID will show up in the Groups for the current identity.
# Note that the SID won't show up unless the process is elevated.
return (([Security.Principal.WindowsIdentity]::GetCurrent()).Groups -contains "S-1-5-32-544")
}

function Invoke-ExeInstaller {
param(
[Parameter(ParameterSetName = 'Install', Mandatory)]
[Switch]$Install,

[Parameter(ParameterSetName = 'Uninstall', Mandatory)]
[Switch]$Uninstall,

[Parameter(Mandatory)]
[ValidateScript({Test-Path -Path $_})]
[String]$ExePath
)
$action = "$($PSCmdlet.ParameterSetName)ing"
if ($Install) {
$switch = '/install'
} else {
$switch = '/uninstall'
}

$installProcess = Start-Process -wait $ExePath -ArgumentList $switch, '/quiet', '/norestart' -PassThru
if ($installProcess.ExitCode -ne 0) {
$exitCode = $installProcess.ExitCode
throw "$action EXE failed and returned error code $exitCode."
}
}

$exePath = $env:PsExePath
$channel = $env:PSMsiChannel
$runtime = $env:PSMsiRuntime

# Get any existing powershell in the path
$beforePath = @(([System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE')) -split ';' |
Where-Object {$_ -like '*files\powershell*'})

foreach ($pathPart in $beforePath) {
Write-Warning "Found existing PowerShell path: $pathPart"
}

if (!(Test-Elevated)) {
Write-Warning "Tests must be elevated"
}
}
BeforeEach {
$error.Clear()
}

Context "$Channel-$Runtime" {
BeforeAll {
Write-Verbose "cr-$channel-$runtime" -Verbose
switch ("$channel-$runtime") {
"preview-win7-x64" {
$msiUpgradeCode = '39243d76-adaf-42b1-94fb-16ecf83237c8'
}
"stable-win7-x64" {
$msiUpgradeCode = '31ab5147-9a97-4452-8443-d9709f0516e1'
}
"preview-win7-x86" {
$msiUpgradeCode = '86abcfbd-1ccc-4a88-b8b2-0facfde29094'
}
"stable-win7-x86" {
$msiUpgradeCode = '1d00683b-0f84-4db8-a64f-2f98ad42fe06'
}
default {
throw "'$_' not a valid channel runtime combination"
}
}
}

It "$Channel MSI should not be installed before test" -Skip:(!(Test-Elevated)) {
$result = @(Get-CimInstance -Query "SELECT Value FROM Win32_Property WHERE Property='UpgradeCode' and Value = '{$msiUpgradeCode}'")
$result.Count | Should -Be 0 -Because "Query should return nothing if $channel $runtime is not installed"
}

It "EXE should install without error" -Skip:(!(Test-Elevated)) {
{
Invoke-ExeInstaller -Install -ExePath $exePath
} | Should -Not -Throw
}

It "Upgrade code should be correct" -Skip:(!(Test-Elevated)) {
$result = @(Get-CimInstance -Query "SELECT Value FROM Win32_Property WHERE Property='UpgradeCode' and Value = '{$msiUpgradeCode}'")
$result.Count | Should -Be 1 -Because "Query should return 1 result if Upgrade code is for $runtime $channel"
}

It "MSI should have updated path" -Skip:(!(Test-Elevated)) {
if ($channel -eq 'preview') {
$pattern = '*files*\powershell*\preview*'
} else {
$pattern = '*files*\powershell*'
}

$psPath = ([System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE')) -split ';' |
Where-Object { $_ -like $pattern -and $_ -notin $beforePath }

if (!$psPath) {
([System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE')) -split ';' |
Where-Object { $_ -notin $beforePath } |
ForEach-Object { Write-Verbose -Verbose $_ }
}

$psPath | Should -Not -BeNullOrEmpty
}

It "MSI should uninstall without error" -Skip:(!(Test-Elevated)) {
{
Invoke-ExeInstaller -Uninstall -ExePath $exePath
} | Should -Not -Throw
}
}
}
4 changes: 2 additions & 2 deletions test/packaging/windows/msi.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Describe -Name "Windows MSI" -Fixture {

It "$Channel MSI should not be installed before test" -Skip:(!(Test-Elevated)) {
$result = @(Get-CimInstance -Query "SELECT Value FROM Win32_Property WHERE Property='UpgradeCode' and Value = '{$msiUpgradeCode}'")
$result.Count | Should -Be 0 -Because "Query should return nothing if $channel x64 is not installed"
$result.Count | Should -Be 0 -Because "Query should return nothing if $channel $runtime is not installed"
}

It "MSI should install without error" -Skip:(!(Test-Elevated)) {
Expand All @@ -117,7 +117,7 @@ Describe -Name "Windows MSI" -Fixture {

It "Upgrade code should be correct" -Skip:(!(Test-Elevated)) {
$result = @(Get-CimInstance -Query "SELECT Value FROM Win32_Property WHERE Property='UpgradeCode' and Value = '{$msiUpgradeCode}'")
$result.Count | Should -Be 1 -Because "Query should return 1 result if Upgrade code is for x64 $channel"
$result.Count | Should -Be 1 -Because "Query should return 1 result if Upgrade code is for $runtime $channel"
}

It "MSI should uninstall without error" -Skip:(!(Test-Elevated)) {
Expand Down
7 changes: 6 additions & 1 deletion tools/ci.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ function Invoke-CIFinish

# the packaging tests find the MSI package using env:PSMsiX64Path
$env:PSMsiX64Path = $artifacts | Where-Object { $_.EndsWith(".msi")}
$env:PSExePath = $artifacts | Where-Object { $_.EndsWith(".exe") }
$env:PSMsiChannel = $Channel
$env:PSMsiRuntime = $Runtime

Expand All @@ -509,8 +510,12 @@ function Invoke-CIFinish
Install-Module Pester -Force -SkipPublisherCheck -MaximumVersion $maximumPesterVersion
Import-Module Pester -Force -MaximumVersion $maximumPesterVersion

$testResultPath = Join-Path -Path $env:TEMP -ChildPath "win-package-$channel-$runtime.xml"

# start the packaging tests and get the results
$packagingTestResult = Invoke-Pester -Script (Join-Path $repoRoot '.\test\packaging\windows\') -PassThru
$packagingTestResult = Invoke-Pester -Script (Join-Path $repoRoot '.\test\packaging\windows\') -PassThru -OutputFormat NUnitXml -OutputFile $testResultPath

Publish-TestResults -Title "win-package-$channel-$runtime" -Path $testResultPath

# fail the CI job if the tests failed, or nothing passed
if(-not $packagingTestResult -is [pscustomobject] -or $packagingTestResult.FailedCount -ne 0 -or $packagingTestResult.PassedCount -eq 0)
Expand Down
Loading