mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 14:17:22 +00:00
* [Windows] Refactor base Installer helper functions * Fix helper name * Fix name gen logic and improve error handling * Fix hash checking logic * Fix Install-VsixExtension invocation * Fix variable name in Install-OpenSSL.ps1 * Fix type for git downloadUrl
51 lines
1.6 KiB
PowerShell
51 lines
1.6 KiB
PowerShell
function Install-ChocoPackage {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string] $PackageName,
|
|
[string[]] $ArgumentList,
|
|
[int] $RetryCount = 5
|
|
)
|
|
|
|
process {
|
|
$count = 1
|
|
while ($true) {
|
|
Write-Host "Running [#$count]: choco install $packageName -y $argumentList"
|
|
choco install $packageName -y @argumentList --no-progress
|
|
|
|
$pkg = choco list --localonly $packageName --exact --all --limitoutput
|
|
if ($pkg) {
|
|
Write-Host "Package installed: $pkg"
|
|
break
|
|
} else {
|
|
$count++
|
|
if ($count -ge $retryCount) {
|
|
Write-Host "Could not install $packageName after $count attempts"
|
|
exit 1
|
|
}
|
|
Start-Sleep -Seconds 30
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function Resolve-ChocoPackageVersion {
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string] $PackageName,
|
|
[Parameter(Mandatory)]
|
|
[string] $TargetVersion
|
|
)
|
|
|
|
$versionNumbers = $TargetVersion.Split(".")
|
|
[int]$versionNumbers[-1] += 1
|
|
$incrementedVersion = $versionNumbers -join "."
|
|
$filterQuery = "`$filter=(Id eq '$PackageName') and (IsPrerelease eq false) and (Version ge '$TargetVersion') and (Version lt '$incrementedVersion')"
|
|
$latestVersion = (Invoke-RestMethod "https://community.chocolatey.org/api/v2/Packages()?$filterQuery").properties.Version |
|
|
Where-Object { $_ -Like "$TargetVersion.*" -or $_ -eq $TargetVersion } |
|
|
Sort-Object { [version]$_ } |
|
|
Select-Object -Last 1
|
|
|
|
return $latestVersion
|
|
}
|