[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

@@ -30,3 +30,35 @@ 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
}

View File

@@ -29,6 +29,8 @@ Export-ModuleMember -Function @(
'Test-IsWin19'
'Test-IsWin16'
'Choco-Install'
'Send-RequestToCocolateyPackages'
'Get-LatestChocoPackageVersion'
'Extract-7Zip'
'Get-CommandResult'
'Get-WhichTool'

View File

@@ -3,7 +3,9 @@
## Desc: Install MongoDB
####################################################################################
Choco-Install -PackageName mongodb
$toolsetVersion = (Get-ToolsetContent).mongodb.version
$latestChocoPackage = Get-LatestChocoPackageVersion -TargetVersion $toolsetVersion -PackageName "mongodb"
Choco-Install -PackageName mongodb -ArgumentList "--version $latestChocoPackage"
$mongoPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'mongodb'").PathName
$mongoBin = Split-Path -Path $mongoPath.split('"')[1]
Add-MachinePathItem "$mongoBin"

View File

@@ -3,7 +3,8 @@ Describe "MongoDB" {
@{ ToolName = "mongo" }
@{ ToolName = "mongod" }
) {
"$ToolName --version" | Should -ReturnZeroExitCode
$toolsetVersion = (Get-ToolsetContent).mongodb.version
(&$ToolName --version)[2].Split('"')[-2] | Should -BeLike "$toolsetVersion*"
}
}

View File

@@ -422,5 +422,8 @@
},
"node": {
"default": "14"
},
"mongodb": {
"version": "5"
}
}

View File

@@ -454,5 +454,8 @@
},
"node": {
"default": "14"
},
"mongodb": {
"version": "5"
}
}

View File

@@ -304,5 +304,8 @@
},
"node": {
"default": "14"
},
"mongodb": {
"version": "5"
}
}