@@ -35,19 +35,43 @@ export async function install(platform, engine, version) {
3535 common . setupPath ( [ path . join ( rubyPrefix , 'bin' ) ] )
3636
3737 if ( ! inToolCache ) {
38- await downloadAndExtract ( platform , engine , version , rubyPrefix ) ;
38+ await preparePrefix ( rubyPrefix )
39+ if ( engine === 'truffleruby+graalvm' ) {
40+ await installWithRubyBuild ( engine , version , rubyPrefix )
41+ } else {
42+ await downloadAndExtract ( platform , engine , version , rubyPrefix )
43+ }
3944 }
4045
4146 return rubyPrefix
4247}
4348
44- async function downloadAndExtract ( platform , engine , version , rubyPrefix ) {
49+ async function preparePrefix ( rubyPrefix ) {
4550 const parentDir = path . dirname ( rubyPrefix )
4651
4752 await io . rmRF ( rubyPrefix )
4853 if ( ! ( fs . existsSync ( parentDir ) && fs . statSync ( parentDir ) . isDirectory ( ) ) ) {
4954 await io . mkdirP ( parentDir )
5055 }
56+ }
57+
58+ async function installWithRubyBuild ( engine , version , rubyPrefix ) {
59+ const tmp = process . env [ 'RUNNER_TEMP' ] || os . tmpdir ( )
60+ const rubyBuildDir = path . join ( tmp , 'ruby-build-for-setup-ruby' )
61+ await common . measure ( 'Cloning ruby-build' , async ( ) => {
62+ await exec . exec ( 'git' , [ 'clone' , 'https://github.com/rbenv/ruby-build.git' , rubyBuildDir ] )
63+ } )
64+
65+ const rubyName = `${ engine } -${ version === 'head' ? 'dev' : version } `
66+ await common . measure ( `Installing ${ engine } -${ version } with ruby-build` , async ( ) => {
67+ await exec . exec ( `${ rubyBuildDir } /bin/ruby-build` , [ rubyName , rubyPrefix ] )
68+ } )
69+
70+ await io . rmRF ( rubyBuildDir )
71+ }
72+
73+ async function downloadAndExtract ( platform , engine , version , rubyPrefix ) {
74+ const parentDir = path . dirname ( rubyPrefix )
5175
5276 const downloadPath = await common . measure ( 'Downloading Ruby' , async ( ) => {
5377 const url = getDownloadURL ( platform , engine , version )
0 commit comments