Skip to content

Commit a669bed

Browse files
committed
Extract function to get the Ruby engine and version
1 parent 3f99912 commit a669bed

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

dist/index.js

Lines changed: 16 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,7 @@ const axios = require('axios')
77

88
async function run() {
99
try {
10-
const rubyVersion = core.getInput('ruby-version')
11-
12-
let ruby = rubyVersion
13-
if (ruby.match(/^\d+/)) { // X.Y.Z => ruby-X.Y.Z
14-
ruby = 'ruby-' + ruby
15-
}
16-
if (!ruby.includes('-')) { // myruby -> myruby-stableVersion
17-
const versionsUrl = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata/versions.json'
18-
const response = await axios.get(versionsUrl)
19-
const stableVersions = response.data[ruby]
20-
const latestStableVersion = stableVersions[stableVersions.length-1]
21-
ruby = ruby + '-' + latestStableVersion
22-
}
10+
const ruby = await getRubyEngineAndVersion(core.getInput('ruby-version'))
2311

2412
const rubiesDir = `${process.env.HOME}/.rubies`
2513
await io.mkdirP(rubiesDir)
@@ -39,6 +27,21 @@ async function run() {
3927
}
4028
}
4129

30+
async function getRubyEngineAndVersion(rubyVersion) {
31+
if (rubyVersion.match(/^\d+/)) { // X.Y.Z => ruby-X.Y.Z
32+
return 'ruby-' + rubyVersion
33+
} else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion
34+
const engine = rubyVersion
35+
const versionsUrl = 'https://raw.githubusercontent.com/eregon/ruby-install-builder/metadata/versions.json'
36+
const response = await axios.get(versionsUrl)
37+
const stableVersions = response.data[engine]
38+
const latestStableVersion = stableVersions[stableVersions.length-1]
39+
return engine + '-' + latestStableVersion
40+
} else {
41+
return rubyVersion
42+
}
43+
}
44+
4245
function getVirtualEnvironmentName() {
4346
const platform = os.platform()
4447
if (platform == 'linux') {

0 commit comments

Comments
 (0)