From a669bed6a4f7d4af0ad480ff7223e56083ded371 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 2 Jan 2020 16:06:43 +0100 Subject: [PATCH] Extract function to get the Ruby engine and version --- dist/index.js | 29 ++++++++++++++++------------- index.js | 29 ++++++++++++++++------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6f1f58f..f66c5a4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1794,19 +1794,7 @@ const axios = __webpack_require__(53) async function run() { try { - const rubyVersion = core.getInput('ruby-version') - - let ruby = rubyVersion - if (ruby.match(/^\d+/)) { // X.Y.Z => ruby-X.Y.Z - ruby = 'ruby-' + ruby - } - if (!ruby.includes('-')) { // myruby -> myruby-stableVersion - const versionsUrl = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata/versions.json' - const response = await axios.get(versionsUrl) - const stableVersions = response.data[ruby] - const latestStableVersion = stableVersions[stableVersions.length-1] - ruby = ruby + '-' + latestStableVersion - } + const ruby = await getRubyEngineAndVersion(core.getInput('ruby-version')) const rubiesDir = `${process.env.HOME}/.rubies` await io.mkdirP(rubiesDir) @@ -1826,6 +1814,21 @@ async function run() { } } +async function getRubyEngineAndVersion(rubyVersion) { + if (rubyVersion.match(/^\d+/)) { // X.Y.Z => ruby-X.Y.Z + return 'ruby-' + rubyVersion + } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion + const engine = rubyVersion + const versionsUrl = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata/versions.json' + const response = await axios.get(versionsUrl) + const stableVersions = response.data[engine] + const latestStableVersion = stableVersions[stableVersions.length-1] + return engine + '-' + latestStableVersion + } else { + return rubyVersion + } +} + function getVirtualEnvironmentName() { const platform = os.platform() if (platform == 'linux') { diff --git a/index.js b/index.js index 3e67f31..03b1831 100644 --- a/index.js +++ b/index.js @@ -7,19 +7,7 @@ const axios = require('axios') async function run() { try { - const rubyVersion = core.getInput('ruby-version') - - let ruby = rubyVersion - if (ruby.match(/^\d+/)) { // X.Y.Z => ruby-X.Y.Z - ruby = 'ruby-' + ruby - } - if (!ruby.includes('-')) { // myruby -> myruby-stableVersion - const versionsUrl = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata/versions.json' - const response = await axios.get(versionsUrl) - const stableVersions = response.data[ruby] - const latestStableVersion = stableVersions[stableVersions.length-1] - ruby = ruby + '-' + latestStableVersion - } + const ruby = await getRubyEngineAndVersion(core.getInput('ruby-version')) const rubiesDir = `${process.env.HOME}/.rubies` await io.mkdirP(rubiesDir) @@ -39,6 +27,21 @@ async function run() { } } +async function getRubyEngineAndVersion(rubyVersion) { + if (rubyVersion.match(/^\d+/)) { // X.Y.Z => ruby-X.Y.Z + return 'ruby-' + rubyVersion + } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion + const engine = rubyVersion + const versionsUrl = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata/versions.json' + const response = await axios.get(versionsUrl) + const stableVersions = response.data[engine] + const latestStableVersion = stableVersions[stableVersions.length-1] + return engine + '-' + latestStableVersion + } else { + return rubyVersion + } +} + function getVirtualEnvironmentName() { const platform = os.platform() if (platform == 'linux') {