[Windows] Split VSIX installation helper into two (#8872)

This commit is contained in:
Vasilii Polikarpov
2023-11-23 11:58:34 +01:00
committed by GitHub
parent 1bd9214f41
commit 1254bc94a5
4 changed files with 46 additions and 57 deletions

View File

@@ -14,7 +14,7 @@ $vsixPackagesList | ForEach-Object {
# Retrieve cdn endpoint to avoid HTTP error 429 https://github.com/actions/runner-images/issues/3074 # Retrieve cdn endpoint to avoid HTTP error 429 https://github.com/actions/runner-images/issues/3074
$vsixPackage = Get-VsixExtenstionFromMarketplace -ExtensionMarketPlaceName $_ $vsixPackage = Get-VsixExtenstionFromMarketplace -ExtensionMarketPlaceName $_
if ($vsixPackage.FileName.EndsWith(".vsix")) { if ($vsixPackage.FileName.EndsWith(".vsix")) {
Install-VsixExtension -Url $vsixPackage.DownloadUri -Name $vsixPackage.FileName Install-VSIXFromUrl $vsixPackage.DownloadUri
} else { } else {
Install-Binary ` Install-Binary `
-Url $vsixPackage.DownloadUri ` -Url $vsixPackage.DownloadUri `

View File

@@ -30,7 +30,6 @@ Install-Binary -Type EXE `
-ExpectedSignature $wdkSignatureThumbprint -ExpectedSignature $wdkSignatureThumbprint
# Need to install the VSIX to get the build targets when running VSBuild # Need to install the VSIX to get the build targets when running VSBuild
$wdkExtensionPath = Resolve-Path -Path $wdkExtensionPath Install-VSIXFromFile (Resolve-Path -Path $wdkExtensionPath)
Install-VsixExtension -FilePath $wdkExtensionPath -Name "WDK.vsix" -InstallOnly
Invoke-PesterTests -TestFile "WDK" Invoke-PesterTests -TestFile "WDK"

View File

@@ -29,7 +29,8 @@ Export-ModuleMember -Function @(
'Set-SvcWithErrHandling' 'Set-SvcWithErrHandling'
'Start-DownloadWithRetry' 'Start-DownloadWithRetry'
'Get-VsixExtenstionFromMarketplace' 'Get-VsixExtenstionFromMarketplace'
'Install-VsixExtension' 'Install-VSIXFromFile'
'Install-VSIXFromUrl'
'Get-VSExtensionVersion' 'Get-VSExtensionVersion'
'Get-WinVersion' 'Get-WinVersion'
'Test-IsWin22' 'Test-IsWin22'

View File

@@ -297,74 +297,63 @@ function Get-VsixExtenstionFromMarketplace {
} }
} }
function Install-VsixExtension function Install-VSIXFromFile {
{
Param Param
( (
[string] $Url,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string] $Name,
[string] $FilePath, [string] $FilePath,
[int] $Retries = 20, [int] $Retries = 20
[switch] $InstallOnly
) )
if (-not $InstallOnly) Write-Host "Installing VSIX from $FilePath..."
{ while ($True) {
$FilePath = Start-DownloadWithRetry -Url $Url -Name $Name $installerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\VSIXInstaller.exe"
} try {
$process = Start-Process `
$argumentList = ('/quiet', "`"$FilePath`"") -FilePath $installerPath `
-ArgumentList @('/quiet', "`"$FilePath`"") `
do -Wait -PassThru
{ } catch {
Write-Host "Starting Install $Name..." Write-Host "Failed to start VSIXInstaller.exe with error:"
try
{
$installPath = ${env:ProgramFiles(x86)}
# There are 2 types of packages at the moment - exe and vsix
if ($Name -match "vsix")
{
$process = Start-Process -FilePath "${installPath}\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\VSIXInstaller.exe" -ArgumentList $argumentList -Wait -PassThru
}
else
{
$process = Start-Process -FilePath ${env:Temp}\$Name /Q -Wait -PassThru
}
}
catch
{
Write-Host "There is an error during $Name installation"
$_ $_
exit 1 exit 1
} }
$exitCode = $process.ExitCode $exitCode = $process.ExitCode
if ($exitCode -eq 0 -or $exitCode -eq 1001) # 1001 means the extension is already installed if ($exitCode -eq 0) {
{ Write-Host "VSIX installed successfully."
Write-Host "$Name installed successfully" break
} elseif ($exitCode -eq 1001) {
Write-Host "VSIX is already installed."
break
} }
else
{
Write-Host "Unsuccessful exit code returned by the installation process: $exitCode."
$Retries--
if ($Retries -eq 0) {
Write-Host "The $Name couldn't be installed after 20 attempts."
exit 1
} else {
Write-Host "Waiting 10 seconds before retrying. Retries left: $Retries"
Start-Sleep -Seconds 10
}
}
} until ($exitCode -eq 0 -or $exitCode -eq 1001 -or $Retries -eq 0 )
#Cleanup downloaded installation files Write-Host "VSIX installation failed with exit code $exitCode."
if (-not $InstallOnly)
{ $Retries--
Remove-Item -Force -Confirm:$false $FilePath if ($Retries -eq 0) {
Write-Host "VSIX installation failed after $Retries retries."
exit 1
} }
Write-Host "Waiting 10 seconds before retrying. Retries left: $Retries"
Start-Sleep -Seconds 10
}
}
function Install-VSIXFromUrl {
Param
(
[Parameter(Mandatory = $true)]
[string] $Url,
[int] $Retries = 20
)
$name = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetRandomFileName()) + ".vsix"
$filePath = Start-DownloadWithRetry -Url $Url -Name $Name
Install-VSIXFromFile -FilePath $filePath -Retries $Retries
Remove-Item -Force -Confirm:$false $filePath
} }
function Get-VSExtensionVersion function Get-VSExtensionVersion