@@ -17,7 +17,7 @@ async function main() {
1717 process . chdir ( core . getInput ( 'working-directory' ) )
1818
1919 const platform = common . getVirtualEnvironmentName ( )
20- const [ engine , version ] = parseRubyEngineAndVersion ( core . getInput ( 'ruby-version' ) )
20+ const [ engine , parsedVersion ] = parseRubyEngineAndVersion ( core . getInput ( 'ruby-version' ) )
2121
2222 let installer
2323 if ( platform === 'windows-latest' && engine !== 'jruby' ) {
@@ -27,13 +27,13 @@ async function main() {
2727 }
2828
2929 const engineVersions = installer . getAvailableVersions ( platform , engine )
30- const ruby = validateRubyEngineAndVersion ( platform , engineVersions , engine , version )
30+ const version = validateRubyEngineAndVersion ( platform , engineVersions , engine , parsedVersion )
3131
3232 createGemRC ( )
3333
34- const [ rubyPrefix , newPathEntries ] = await installer . install ( platform , ruby )
34+ const [ rubyPrefix , newPathEntries ] = await installer . install ( platform , engine , version )
3535
36- setupPath ( ruby , newPathEntries )
36+ setupPath ( newPathEntries )
3737
3838 if ( core . getInput ( 'bundler' ) !== 'none' ) {
3939 await common . measure ( 'Installing Bundler' , async ( ) =>
@@ -78,24 +78,25 @@ function parseRubyEngineAndVersion(rubyVersion) {
7878 return [ engine , version ]
7979}
8080
81- function validateRubyEngineAndVersion ( platform , engineVersions , engine , version ) {
81+ function validateRubyEngineAndVersion ( platform , engineVersions , engine , parsedVersion ) {
8282 if ( ! engineVersions ) {
8383 throw new Error ( `Unknown engine ${ engine } on ${ platform } ` )
8484 }
8585
86- if ( ! engineVersions . includes ( version ) ) {
86+ let version = parsedVersion
87+ if ( ! engineVersions . includes ( parsedVersion ) ) {
8788 const latestToFirstVersion = engineVersions . slice ( ) . reverse ( )
88- const found = latestToFirstVersion . find ( v => v !== 'head' && v . startsWith ( version ) )
89+ const found = latestToFirstVersion . find ( v => v !== 'head' && v . startsWith ( parsedVersion ) )
8990 if ( found ) {
9091 version = found
9192 } else {
92- throw new Error ( `Unknown version ${ version } for ${ engine } on ${ platform }
93+ throw new Error ( `Unknown version ${ parsedVersion } for ${ engine } on ${ platform }
9394 available versions for ${ engine } on ${ platform } : ${ engineVersions . join ( ', ' ) }
9495 File an issue at https://github.com/ruby/setup-ruby/issues if would like support for a new version` )
9596 }
9697 }
9798
98- return engine + '-' + version
99+ return version
99100}
100101
101102function createGemRC ( ) {
@@ -105,7 +106,7 @@ function createGemRC() {
105106 }
106107}
107108
108- function setupPath ( ruby , newPathEntries ) {
109+ function setupPath ( newPathEntries ) {
109110 const originalPath = process . env [ 'PATH' ] . split ( path . delimiter )
110111 let cleanPath = originalPath . filter ( entry => ! / \b r u b y \b / i. test ( entry ) )
111112
@@ -164,7 +165,7 @@ async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
164165 throw new Error ( `Cannot parse bundler input: ${ bundlerVersion } ` )
165166 }
166167
167- if ( engine === 'ruby' && isHeadVersion ( rubyVersion ) && bundlerVersion === '2' ) {
168+ if ( engine === 'ruby' && common . isHeadVersion ( rubyVersion ) && bundlerVersion === '2' ) {
168169 console . log ( `Using Bundler 2 shipped with ${ engine } -${ rubyVersion } ` )
169170 } else if ( engine === 'truffleruby' && bundlerVersion === '1' ) {
170171 console . log ( `Using Bundler 1 shipped with ${ engine } ` )
@@ -176,8 +177,4 @@ async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
176177 }
177178}
178179
179- function isHeadVersion ( rubyVersion ) {
180- return rubyVersion === 'head' || rubyVersion === 'mingw' || rubyVersion === 'mswin'
181- }
182-
183180if ( __filename . endsWith ( 'index.js' ) ) { run ( ) }
0 commit comments