-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathExecute-WinGetTests.ps1
More file actions
128 lines (104 loc) · 4.18 KB
/
Execute-WinGetTests.ps1
File metadata and controls
128 lines (104 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
[CmdletBinding()]
param(
# The version of the client PS module to use.
[string]$ClientModuleVersion,
# The version of the configuration PS module to use.
[string]$ConfigurationModuleVersion,
# The version of the client to use. Use 'existing' to skip updating.
[string]$ClientVersion,
# The version of Powershell to use. Use 'existing' to skip updating.
[string]$PwshVersion,
# The path to the binaries to run the web server.
[string]$LocalhostWebServerPath = (Join-Path $PSScriptRoot "..\LocalhostWebServer"),
# The path to the files to be hosted by the web server.
[string]$HostedFilePath = (Join-Path $PSScriptRoot "..\TestLocalIndex"),
# The path to the certificate that signed the source.msix package.
[string]$SourceCertPath = (Join-Path $PSScriptRoot "..\TestData\AppInstallerTest.cer"),
# The path to the configuration test data.
[string]$ConfigurationTestDataPath = (Join-Path $PSScriptRoot "..\TestData\Configuration"),
# The path to pwsh.exe
[string]$PwshPath = 'C:\Program Files\PowerShell\7\pwsh.exe',
# Switches to prevent installing various runtimes required for the tests
[switch]$SkipVCRuntime,
[switch]$SkipDotNetRuntime,
[switch]$SkipAspNetRuntime,
# The path to write results to.
[string]$ResultsPath = (Join-Path ([System.IO.Path]::GetTempPath()) (New-Guid))
)
# Ensure we can connect to PS Gallery
Install-PackageProvider -Name NuGet -Force | Out-Null
# Get the client module
if ([System.String]::IsNullOrEmpty($ClientModuleVersion))
{
Install-Module Microsoft.WinGet.Client -Force
}
else
{
Install-Module Microsoft.WinGet.Client -RequiredVersion $ClientModuleVersion -Force
}
# Get the client
if ([System.String]::IsNullOrEmpty($ClientVersion))
{
Repair-WingetPackageManager -Latest
}
elseif ($ClientVersion -eq "existing")
{
# Use version already present
}
else
{
Repair-WingetPackageManager -Version $ClientVersion
}
# Get pwsh
if ([System.String]::IsNullOrEmpty($PwshVersion))
{
winget install Microsoft.PowerShell -s winget
}
elseif ($PwshVersion -eq "existing")
{
# Use version already present
}
else
{
winget install Microsoft.PowerShell -s winget -v $PwshVersion
}
# Get VC Runtime
if (-not $SkipVCRuntime)
{
winget install 'Microsoft.VCRedist.2015+.x64' -s winget
}
# Install .NET 6 for the local web server
if (-not $SkipDotNetRuntime)
{
winget install Microsoft.DotNet.Runtime.6 -s winget
}
if (-not $SkipAspNetRuntime)
{
winget install Microsoft.DotNet.AspNetCore.6 -s winget
}
# Generate a new TLS certificate and trust it
$TLSCertificate = New-SelfSignedCertificate -CertStoreLocation "Cert:\LocalMachine\My" -DnsName "localhost"
$CertTempPath = Join-Path $env:TEMP New-Guid
Export-Certificate -Cert $TLSCertificate -FilePath $CertTempPath
Import-Certificate -FilePath $CertTempPath -CertStoreLocation "Cert:\LocalMachine\Root"
# Start local host web server
.\Run-LocalhostWebServer.ps1 -BuildRoot $LocalhostWebServerPath -StaticFileRoot $HostedFilePath -CertPath $TLSCertificate.PSPath -SourceCert $SourceCertPath
# Get the configuration module using pwsh since AllowPrerelease doesn't working in Windows PowerShell baseline
if ([System.String]::IsNullOrEmpty($ConfigurationModuleVersion))
{
& $PwshPath -Command "Install-Module Microsoft.WinGet.Configuration -Force -AllowPrerelease"
}
else
{
& $PwshPath -Command "Install-Module Microsoft.WinGet.Configuration -RequiredVersion $ConfigurationModuleVersion -Force -AllowPrerelease"
}
# Create local PS repo
$InitRepositoryPath = Join-Path $ConfigurationTestDataPath Init-TestRepository.ps1
& $PwshPath -ExecutionPolicy Unrestricted -Command "$InitRepositoryPath -Force"
# Run tests
& $PwshPath -ExecutionPolicy Unrestricted -Command ".\RunTests.ps1 -TargetProduction -ConfigurationTestDataPath $ConfigurationTestDataPath -outputPath $ResultsPath"
# Terminate the local web server
Get-Process LocalhostWebServer -ErrorAction Ignore | Stop-Process -ErrorAction Ignore
Write-Host "Results: $ResultsPath"