mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 06:08:07 +00:00
[Windows] Update Resolve-GithubReleaseAssetUrl function (#8981)
This commit is contained in:
@@ -13,7 +13,8 @@ $seleniumMajorVersion = (Get-ToolsetContent).selenium.version
|
||||
$seleniumDownloadUrl = Resolve-GithubReleaseAssetUrl `
|
||||
-Repo "SeleniumHQ/selenium" `
|
||||
-Version "$seleniumMajorVersion.*" `
|
||||
-Asset "selenium-server-*.jar"
|
||||
-Asset "selenium-server-*.jar" `
|
||||
-AllowMultipleMatches
|
||||
|
||||
$seleniumBinPath = Join-Path $seleniumDirectory "selenium-server.jar"
|
||||
Invoke-DownloadWithRetry -Url $seleniumDownloadUrl -Path $seleniumBinPath
|
||||
|
||||
@@ -636,6 +636,10 @@ function Resolve-GithubReleaseAssetUrl {
|
||||
The pattern to match against the download URLs of the release assets.
|
||||
Wildcards (*) can be used to match any characters.
|
||||
|
||||
.PARAMETER AllowMultipleMatches
|
||||
Specifies whether to choose one of multiple assets matching the pattern or consider this behavior to be erroneous.
|
||||
By default, multiple matches are not considered normal behavior and result in an error.
|
||||
|
||||
.EXAMPLE
|
||||
Resolve-GithubReleaseAssetUrl -Repository "myrepo" -Version "1.0" -UrlMatchPattern "*.zip"
|
||||
Retrieves the download URL for the asset in the "myrepo" repository with version "1.0" and a file extension of ".zip".
|
||||
@@ -650,7 +654,8 @@ function Resolve-GithubReleaseAssetUrl {
|
||||
[switch] $AllowPrerelease,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Alias("Pattern", "File", "Asset")]
|
||||
[string] $UrlMatchPattern
|
||||
[string] $UrlMatchPattern,
|
||||
[switch] $AllowMultipleMatches = $false
|
||||
)
|
||||
|
||||
$matchingReleases = Get-GithubReleasesByVersion `
|
||||
@@ -677,9 +682,18 @@ function Resolve-GithubReleaseAssetUrl {
|
||||
Write-Debug "Found no download urls matching pattern ${UrlMatchPattern}"
|
||||
Write-Debug "Available download urls:`n$($matchingReleases.assets.browser_download_url -join "`n")"
|
||||
throw "No assets found in ${Repository} matching version `"${Version}`" and pattern `"${UrlMatchPattern}`""
|
||||
} elseif ($matchedUrl.Count -gt 1) {
|
||||
Write-Debug "Found multiple download urls matching pattern ${UrlMatchPattern}:`n$($matchedUrl -join "`n")"
|
||||
throw "Multiple download urls found in ${Repository} version `"${matchedVersion}`" matching pattern `"${UrlMatchPattern}`":`n$($matchedUrl -join "`n")"
|
||||
}
|
||||
# If multiple urls match the pattern, sort them and take the last one
|
||||
# Will only work with simple number series of no more than nine in a row.
|
||||
if ($matchedUrl.Count -gt 1) {
|
||||
if ($AllowMultipleMatches) {
|
||||
Write-Debug "Found multiple download urls matching pattern ${UrlMatchPattern}:`n$($matchedUrl -join "`n")"
|
||||
Write-Host "Performing sorting of urls to find the most recent version matching the pattern"
|
||||
$matchedUrl = $matchedUrl | Sort-Object -Descending
|
||||
$matchedUrl = $matchedUrl[0]
|
||||
} else {
|
||||
throw "Found multiple assets in ${Repository} matching version `"${Version}`" and pattern `"${UrlMatchPattern}`".`nAvailable assets:`n$($matchedUrl -join "`n")"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Found download url for ${Repository} version ${matchedVersion}: ${matchedUrl}"
|
||||
|
||||
Reference in New Issue
Block a user