Extract function to get the Ruby engine and version

This commit is contained in:
Benoit Daloze
2020-01-02 16:15:42 +01:00
parent 3f99912f55
commit a669bed6a4
2 changed files with 32 additions and 26 deletions
+16 -13
View File
@@ -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') {