@@ -7,19 +7,7 @@ const axios = require('axios')
77
88async 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+
4245function getVirtualEnvironmentName ( ) {
4346 const platform = os . platform ( )
4447 if ( platform == 'linux' ) {
0 commit comments