mirror of
https://github.com/actions/runner-images.git
synced 2025-12-16 06:40:32 +00:00
[Windows] Pin MongoDB to the specific version defined in the toolset (#4418)
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -29,6 +29,8 @@ Export-ModuleMember -Function @(
|
||||
'Test-IsWin19'
|
||||
'Test-IsWin16'
|
||||
'Choco-Install'
|
||||
'Send-RequestToCocolateyPackages'
|
||||
'Get-LatestChocoPackageVersion'
|
||||
'Extract-7Zip'
|
||||
'Get-CommandResult'
|
||||
'Get-WhichTool'
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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*"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -422,5 +422,8 @@
|
||||
},
|
||||
"node": {
|
||||
"default": "14"
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,5 +454,8 @@
|
||||
},
|
||||
"node": {
|
||||
"default": "14"
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,5 +304,8 @@
|
||||
},
|
||||
"node": {
|
||||
"default": "14"
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "5"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user