Try stable versions first, and then try non-head versions

* Fixes https://github.com/ruby/setup-ruby/issues/115
This commit is contained in:
Benoit Daloze
2020-12-05 12:52:21 +01:00
parent bacba738b2
commit 2a0be7a409
3 changed files with 15 additions and 3 deletions
+7 -1
View File
@@ -132,7 +132,13 @@ function validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVe
let version = parsedVersion
if (!engineVersions.includes(parsedVersion)) {
const latestToFirstVersion = engineVersions.slice().reverse()
const found = latestToFirstVersion.find(v => common.isStableVersion(v) && v.startsWith(parsedVersion))
// Try to match stable versions first, so an empty version (engine-only) matches the latest stable version
let found = latestToFirstVersion.find(v => common.isStableVersion(v) && v.startsWith(parsedVersion))
if (!found) {
// Exclude head versions, they must be exact matches
found = latestToFirstVersion.find(v => !common.isHeadVersion(v) && v.startsWith(parsedVersion))
}
if (found) {
version = found
} else {