From 2a0be7a409f7fad3aa515592db8ad37a4adb562a Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 19 Nov 2020 00:03:27 +0100 Subject: [PATCH] Try stable versions first, and then try non-head versions * Fixes https://github.com/ruby/setup-ruby/issues/115 --- .github/workflows/test.yml | 2 +- dist/index.js | 8 +++++++- index.js | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d396bf4..17f12f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: matrix: os: [ ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11.0, windows-2016, windows-2019 ] # Use various version syntax here for testing - ruby: [ 2.1, 2.2, 2.3, 2.4, 2.5, 2.6.6, 2.7, ruby-3.0.0-preview1, ruby-head, debug, jruby-9.1, jruby, jruby-head, truffleruby, truffleruby-head ] + ruby: [ 2.1, 2.2, 2.3, 2.4, 2.5, 2.6.6, 2.7, 3.0, ruby-head, debug, jruby-9.1, jruby, jruby-head, truffleruby, truffleruby-head ] include: - { os: windows-2016, ruby: mingw } - { os: windows-2019, ruby: mingw } diff --git a/dist/index.js b/dist/index.js index ff901aa..dbedbec 100644 --- a/dist/index.js +++ b/dist/index.js @@ -51304,7 +51304,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 { diff --git a/index.js b/index.js index a926f32..4d5468b 100644 --- a/index.js +++ b/index.js @@ -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 {