@@ -61,18 +61,48 @@ export async function setupRuby(options = {}) {
6161 }
6262
6363 if ( inputs [ 'bundler' ] !== 'none' ) {
64+ const [ gemFile , lockFile ] = detectGemfiles ( )
65+
6466 await common . measure ( 'Installing Bundler' , async ( ) =>
65- installBundler ( inputs [ 'bundler' ] , platform , rubyPrefix , engine , version ) )
67+ installBundler ( inputs [ 'bundler' ] , lockFile , platform , rubyPrefix , engine , version ) )
6668
6769 if ( inputs [ 'bundler-cache' ] === 'true' ) {
6870 await common . measure ( 'bundle install' , async ( ) =>
69- bundleInstall ( platform , engine , version ) )
71+ bundleInstall ( gemFile , lockFile , platform , engine , version ) )
7072 }
7173 }
7274
7375 core . setOutput ( 'ruby-prefix' , rubyPrefix )
7476}
7577
78+ function detectGemfiles ( ) {
79+ const gemfilePath = process . env [ 'BUNDLE_GEMFILE' ] || 'Gemfile'
80+
81+ if ( fs . existsSync ( gemfilePath ) ) {
82+ const lockPath = `${ gemfilePath } .lock`
83+
84+ if ( fs . existsSync ( lockPath ) ) {
85+ return [ gemfilePath , lockPath ]
86+ } else {
87+ return [ gemfilePath , null ]
88+ }
89+ }
90+
91+ const gemsPath = "gems.rb"
92+
93+ if ( fs . existsSync ( gemsPath ) ) {
94+ const lockPath = "gems.locked"
95+
96+ if ( fs . existsSync ( lockPath ) ) {
97+ return [ gemsPath , lockPath ]
98+ } else {
99+ return [ gemsPath , null ]
100+ }
101+ }
102+
103+ return [ null , null ]
104+ }
105+
76106function parseRubyEngineAndVersion ( rubyVersion ) {
77107 if ( rubyVersion === 'default' ) {
78108 if ( fs . existsSync ( '.ruby-version' ) ) {
@@ -168,12 +198,12 @@ function readBundledWithFromGemfileLock(path) {
168198 return null
169199}
170200
171- async function installBundler ( bundlerVersionInput , platform , rubyPrefix , engine , rubyVersion ) {
201+ async function installBundler ( bundlerVersionInput , lockFile , platform , rubyPrefix , engine , rubyVersion ) {
172202 var bundlerVersion = bundlerVersionInput
173203
174204 if ( bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock' ) {
175- const gemfilePath = ` ${ process . env [ 'BUNDLE_GEMFILE' ] || 'Gemfile' } .lock`
176- bundlerVersion = readBundledWithFromGemfileLock ( gemfilePath )
205+ bundlerVersion = readBundledWithFromGemfileLock ( lockFile )
206+
177207 if ( ! bundlerVersion ) {
178208 bundlerVersion = 'latest'
179209 }
@@ -209,15 +239,16 @@ async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine,
209239 }
210240}
211241
212- async function bundleInstall ( platform , engine , version ) {
213- if ( ! fs . existsSync ( 'Gemfile' ) ) {
214- console . log ( 'No Gemfile , skipping "bundle install" and caching' )
215- return
242+ async function bundleInstall ( gemfilePath , lockPath , platform , engine , version ) {
243+ if ( ! fs . existsSync ( gemfilePath ) ) {
244+ console . log ( 'Could not determine gemfile path , skipping "bundle install" and caching' )
245+ return false
216246 }
217247
218248 // config
219249 const path = 'vendor/bundle'
220- const hasGemfileLock = fs . existsSync ( 'Gemfile.lock' ) ;
250+ const hasGemfileLock = fs . existsSync ( lockPath )
251+
221252 if ( hasGemfileLock ) {
222253 await exec . exec ( 'bundle' , [ 'config' , '--local' , 'deployment' , 'true' ] )
223254 }
@@ -229,9 +260,9 @@ async function bundleInstall(platform, engine, version) {
229260 let key = baseKey
230261 let restoreKeys
231262 if ( hasGemfileLock ) {
232- key += `-Gemfile.lock -${ await common . hashFile ( 'Gemfile.lock' ) } `
263+ key += `-${ lockPath } -${ await common . hashFile ( lockPath ) } `
233264 // If only Gemfile.lock we can reuse some of the cache (but it will keep old gem versions in the cache)
234- restoreKeys = [ `${ baseKey } -Gemfile.lock -` ]
265+ restoreKeys = [ `${ baseKey } -${ lockPath } -` ]
235266 } else {
236267 // Only exact key, to never mix native gems of different platforms or Ruby versions
237268 restoreKeys = [ ]
@@ -277,6 +308,8 @@ async function bundleInstall(platform, engine, version) {
277308 }
278309 }
279310 }
311+
312+ return true
280313}
281314
282315async function computeBaseKey ( platform , engine , version ) {
0 commit comments