mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-18 15:56:47 +00:00
[Windows] Cleanup various scripts (#8942)
* Use Resolve-GithubReleaseAssetUrl more widely * Add the Get-ChecksumFromUrl function * Sort exported functions and add docs * Remove alias and fix typo * Fix kind checksum url and syntax * Fix checksums url for gh cli and msys2 * [Windows] Cleanup various scripts * Add spaces after type specifications * Rename the Take-Part function
This commit is contained in:
committed by
GitHub
parent
ed911223ab
commit
5ed2615017
@@ -1,4 +1,25 @@
|
||||
function Install-ChocoPackage {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A function to install a Chocolatey package with retries.
|
||||
|
||||
.DESCRIPTION
|
||||
This function attempts to install a specified Chocolatey package. If the
|
||||
installation fails, it retries a specified number of times.
|
||||
|
||||
.PARAMETER PackageName
|
||||
The name of the Chocolatey package to install.
|
||||
|
||||
.PARAMETER ArgumentList
|
||||
An array of arguments to pass to the choco install command.
|
||||
|
||||
.PARAMETER RetryCount
|
||||
The number of times to retry the installation if it fails. Default is 5.
|
||||
|
||||
.EXAMPLE
|
||||
Install-ChocoPackage -PackageName "git" -RetryCount 3
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
@@ -30,6 +51,25 @@ function Install-ChocoPackage {
|
||||
}
|
||||
|
||||
function Resolve-ChocoPackageVersion {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Resolves the latest version of a Chocolatey package.
|
||||
|
||||
.DESCRIPTION
|
||||
This function takes a package name and a target version as input and returns the latest
|
||||
version of the package that is greater than or equal to the target version.
|
||||
|
||||
.PARAMETER PackageName
|
||||
The name of the Chocolatey package.
|
||||
|
||||
.PARAMETER TargetVersion
|
||||
The target version of the package.
|
||||
|
||||
.EXAMPLE
|
||||
Resolve-ChocoPackageVersion -PackageName "example-package" -TargetVersion "1.0.0"
|
||||
Returns the latest version of the "example-package" that is greater than or equal to "1.0.0".
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string] $PackageName,
|
||||
@@ -38,12 +78,12 @@ function Resolve-ChocoPackageVersion {
|
||||
)
|
||||
|
||||
$versionNumbers = $TargetVersion.Split(".")
|
||||
[int]$versionNumbers[-1] += 1
|
||||
[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]$_ } |
|
||||
Sort-Object { [version] $_ } |
|
||||
Select-Object -Last 1
|
||||
|
||||
return $latestVersion
|
||||
|
||||
Reference in New Issue
Block a user