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