[Windows] Pin MongoDB to the specific version defined in the toolset (#4418)

This commit is contained in:
Maksim Shilov
2021-11-10 21:43:42 +03:00
committed by GitHub
parent 596859266e
commit fef060bec8
7 changed files with 48 additions and 2 deletions

View File

@@ -29,4 +29,36 @@ function Choco-Install {
}
}
}
}
function Send-RequestToCocolateyPackages {
param(
[Parameter(Mandatory)]
[string] $FilterQuery,
[string] $Url = "https://community.chocolatey.org/api",
[int] $ApiVersion = 2
)
$response = Invoke-RestMethod "$Url/v$ApiVersion/Packages()?$filterQuery"
return $response
}
function Get-LatestChocoPackageVersion {
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 = (Send-RequestToCocolateyPackages -FilterQuery $filterQuery).properties.Version |
Sort-Object {[version]$_} |
Select-Object -Last 1
return $latestVersion
}