mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-19 00:06:45 +00:00
added Start-DownloadWithRetry function
This commit is contained in:
@@ -161,7 +161,134 @@ Hashtable for service arguments
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-VS19ExtensionVersion
|
|
||||||
|
function Start-DownloadWithRetry
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[string] $Url,
|
||||||
|
[string] $FullFilePath = "${env:Temp}\Default.exe",
|
||||||
|
[int] $retries = 20
|
||||||
|
)
|
||||||
|
#Default retry logic for the package.
|
||||||
|
while($retries -gt 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Write-Host "Downloading package from: $Url to path $FilePath ."
|
||||||
|
(New-Object System.Net.WebClient).DownloadFile($Url, $FilePath)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Write-Host "There is an error during package downloading"
|
||||||
|
$_
|
||||||
|
|
||||||
|
$retries--
|
||||||
|
|
||||||
|
if ($retries -eq 0)
|
||||||
|
{
|
||||||
|
Write-Host "File can't be downloaded. Please try later or check that file exists by url: $Url"
|
||||||
|
$_
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Waiting 30 seconds before retrying. Retries left: $retries"
|
||||||
|
Start-Sleep -Seconds 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $FullFilePath
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function Install-VsixExtension
|
||||||
|
{
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[string] $Url,
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string] $Name,
|
||||||
|
[string] $FilePath,
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string] $VSversion,
|
||||||
|
[int] $retries = 20,
|
||||||
|
[switch] $InstallOnly
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!$InstallOnly)
|
||||||
|
{
|
||||||
|
$FilePath = "${env:Temp}\$Name"
|
||||||
|
|
||||||
|
while($retries -gt 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Write-Host "Downloading $Name..."
|
||||||
|
(New-Object System.Net.WebClient).DownloadFile($Url, $FilePath)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Write-Host "There is an error during $Name downloading"
|
||||||
|
$_
|
||||||
|
|
||||||
|
$retries--
|
||||||
|
|
||||||
|
if ($retries -eq 0)
|
||||||
|
{
|
||||||
|
Write-Host "File can't be downloaded"
|
||||||
|
$_
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Waiting 30 seconds before retrying. Retries left: $retries"
|
||||||
|
Start-Sleep -Seconds 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ArgumentList = ('/quiet', "`"$FilePath`"")
|
||||||
|
|
||||||
|
Write-Host "Starting Install $Name..."
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#There are 2 types of packages at the moment - exe and vsix
|
||||||
|
if ($Name -match "vsix")
|
||||||
|
{
|
||||||
|
$process = Start-Process -FilePath "C:\Program Files (x86)\Microsoft Visual Studio\$VSversion\Enterprise\Common7\IDE\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
|
||||||
|
}
|
||||||
|
|
||||||
|
$exitCode = $process.ExitCode
|
||||||
|
|
||||||
|
if ($exitCode -eq 0 -or $exitCode -eq 1001) # 1001 means the extension is already installed
|
||||||
|
{
|
||||||
|
Write-Host "$Name installed successfully"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host "Unsuccessful exit code returned by the installation process: $exitCode."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#Cleanup downloaded installation files
|
||||||
|
if (!$InstallOnly)
|
||||||
|
{
|
||||||
|
Remove-Item -Force -Confirm:$false $FilePath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-VSExtensionVersion
|
||||||
{
|
{
|
||||||
param (
|
param (
|
||||||
[string] [Parameter(Mandatory=$true)] $packageName
|
[string] [Parameter(Mandatory=$true)] $packageName
|
||||||
@@ -187,3 +314,40 @@ function Get-VS19ExtensionVersion
|
|||||||
|
|
||||||
return $packageVersion
|
return $packageVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function Get-ToolcachePackages {
|
||||||
|
$toolcachePath = Join-Path $env:ROOT_FOLDER "toolcache.json"
|
||||||
|
Get-Content -Raw $toolcachePath | ConvertFrom-Json
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-ToolsByName {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory = $True)]
|
||||||
|
[string]$SoftwareName
|
||||||
|
)
|
||||||
|
|
||||||
|
(Get-ToolcachePackages).PSObject.Properties | Where-Object { $_.Name -match $SoftwareName } | ForEach-Object {
|
||||||
|
$packageNameParts = $_.Name.Split("-")
|
||||||
|
[PSCustomObject] @{
|
||||||
|
ToolName = $packageNameParts[1]
|
||||||
|
Versions = $_.Value
|
||||||
|
Architecture = $packageNameParts[3,4] -join "-"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-WinVersion
|
||||||
|
{
|
||||||
|
(Get-WmiObject -class Win32_OperatingSystem).Caption
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-IsWin19
|
||||||
|
{
|
||||||
|
(Get-WinVersion) -match "2019"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-IsWin16
|
||||||
|
{
|
||||||
|
(Get-WinVersion) -match "2016"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user