@@ -25,7 +25,7 @@ export async function run() {
2525
2626    setupPath ( ruby ,  newPathEntries ) 
2727
28-     await  installBundler ( platform ,  rubyPrefix ) 
28+     await  installBundler ( platform ,  rubyPrefix ,   engine ,   version ) 
2929
3030    core . setOutput ( 'ruby-prefix' ,  rubyPrefix ) 
3131  }  catch  ( error )  { 
@@ -111,11 +111,55 @@ function setupPath(ruby, newPathEntries) {
111111    core . exportVariable ( 'PATH' ,  [ ...newPathEntries ,  ...cleanPath ] . join ( path . delimiter ) ) 
112112} 
113113
114- async  function  installBundler ( platform ,  rubyPrefix )  { 
115-   const  bundle_exe  =  platform  ===  'windows-latest'  ? 'bundle.cmd'  : 'bundle' 
116-   // Install Bundler if not already part of the stdlib 
117-   if  ( ! fs . existsSync ( path . join ( rubyPrefix ,  'bin' ,  bundle_exe ) ) )  { 
118-     await  exec . exec ( path . join ( rubyPrefix ,  'bin' ,  'gem' ) ,  [ 'install' ,  'bundler' ,  '-v' ,  '~> 1' ,  '--no-document' ] ) 
114+ function  readBundledWithFromGemfileLock ( )  { 
115+   if  ( fs . existsSync ( 'Gemfile.lock' ) )  { 
116+     const  contents  =  fs . readFileSync ( 'Gemfile.lock' ,  'utf8' ) 
117+     const  lines  =  contents . split ( / \r ? \n / ) 
118+     const  bundledWithLine  =  lines . findIndex ( line  =>  / ^ B U N D L E D   W I T H $ / . test ( line . trim ( ) ) ) 
119+     if  ( bundledWithLine  !==  - 1 )  { 
120+       const  nextLine  =  lines [ bundledWithLine + 1 ] 
121+       if  ( nextLine  &&  / ^ \d + / . test ( nextLine . trim ( ) ) )  { 
122+         const  bundlerVersion  =  nextLine . trim ( ) 
123+         const  majorVersion  =  bundlerVersion . match ( / ^ \d + / ) [ 0 ] 
124+         console . log ( `Using Bundler ${ majorVersion } ${ bundlerVersion }  ) 
125+         return  majorVersion 
126+       } 
127+     } 
128+   } 
129+   return  null 
130+ } 
131+ 
132+ async  function  installBundler ( platform ,  rubyPrefix ,  engine ,  rubyVersion )  { 
133+   var  bundlerVersion  =  core . getInput ( 'bundler' ) 
134+   if  ( bundlerVersion  ===  'none' )  { 
135+     return 
136+   } 
137+ 
138+   if  ( bundlerVersion  ===  'default'  ||  bundlerVersion  ===  'Gemfile.lock' )  { 
139+     bundlerVersion  =  readBundledWithFromGemfileLock ( ) 
140+     if  ( ! bundlerVersion )  { 
141+       bundlerVersion  =  'latest' 
142+     } 
143+   } 
144+ 
145+   let  versionArray 
146+   if  ( rubyVersion . startsWith ( '2.2' ) )  { 
147+     console . log ( 'Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2' ) 
148+     versionArray  =  [ '-v' ,  '~> 1' ] 
149+   }  else  if  ( / ^ \d + / . test ( bundlerVersion ) )  { 
150+     versionArray  =  [ '-v' ,  `~> ${ bundlerVersion }  ] 
151+   }  else  if  ( bundlerVersion  ===  'latest' )  { 
152+     versionArray  =  [ ] 
153+   }  else  { 
154+     throw  new  Error ( `Cannot parse bundler input: ${ bundlerVersion }  ) 
155+   } 
156+ 
157+   if  ( engine  ===  'rubinius' )  { 
158+     console . log ( `Rubinius only supports the version of Bundler shipped with it` ) 
159+   }  else  if  ( bundlerVersion  ===  '1'  &&  engine  ===  'truffleruby' )  { 
160+     console . log ( `Using the Bundler version shipped with ${ engine }  ) 
161+   }  else  { 
162+     await  exec . exec ( path . join ( rubyPrefix ,  'bin' ,  'gem' ) ,  [ 'install' ,  'bundler' ,  ...versionArray ,  '--no-document' ] ) 
119163  } 
120164} 
121165
0 commit comments