@@ -61,14 +61,14 @@ export async function setupRuby(options = {}) {
6161 }
6262
6363 if ( inputs [ 'bundler' ] !== 'none' ) {
64- const [ gemFile , lockFile ] = detectGemfiles ( )
64+ const [ gemfile , lockFile ] = detectGemfiles ( )
6565
6666 await common . measure ( 'Installing Bundler' , async ( ) =>
6767 installBundler ( inputs [ 'bundler' ] , lockFile , platform , rubyPrefix , engine , version ) )
6868
6969 if ( inputs [ 'bundler-cache' ] === 'true' ) {
7070 await common . measure ( 'bundle install' , async ( ) =>
71- bundleInstall ( gemFile , lockFile , platform , engine , version ) )
71+ bundleInstall ( gemfile , lockFile , platform , engine , version ) )
7272 }
7373 }
7474
@@ -77,26 +77,22 @@ export async function setupRuby(options = {}) {
7777
7878function detectGemfiles ( ) {
7979 const gemfilePath = process . env [ 'BUNDLE_GEMFILE' ] || 'Gemfile'
80-
8180 if ( fs . existsSync ( gemfilePath ) ) {
8281 const lockPath = `${ gemfilePath } .lock`
83-
8482 if ( fs . existsSync ( lockPath ) ) {
8583 return [ gemfilePath , lockPath ]
8684 } else {
8785 return [ gemfilePath , null ]
8886 }
8987 }
9088
91- const gemsPath = "gems.rb"
92-
93- if ( fs . existsSync ( gemsPath ) ) {
89+ const gemsRbPath = "gems.rb"
90+ if ( fs . existsSync ( gemsRbPath ) ) {
9491 const lockPath = "gems.locked"
95-
9692 if ( fs . existsSync ( lockPath ) ) {
97- return [ gemsPath , lockPath ]
93+ return [ gemsRbPath , lockPath ]
9894 } else {
99- return [ gemsPath , null ]
95+ return [ gemsRbPath , null ]
10096 }
10197 }
10298
@@ -180,17 +176,17 @@ function envPreInstall() {
180176 }
181177}
182178
183- function readBundledWithFromGemfileLock ( path ) {
184- if ( fs . existsSync ( path ) ) {
185- const contents = fs . readFileSync ( path , 'utf8' )
179+ function readBundledWithFromGemfileLock ( lockFile ) {
180+ if ( lockFile !== null ) {
181+ const contents = fs . readFileSync ( lockFile , 'utf8' )
186182 const lines = contents . split ( / \r ? \n / )
187183 const bundledWithLine = lines . findIndex ( line => / ^ B U N D L E D W I T H $ / . test ( line . trim ( ) ) )
188184 if ( bundledWithLine !== - 1 ) {
189185 const nextLine = lines [ bundledWithLine + 1 ]
190186 if ( nextLine && / ^ \d + / . test ( nextLine . trim ( ) ) ) {
191187 const bundlerVersion = nextLine . trim ( )
192188 const majorVersion = bundlerVersion . match ( / ^ \d + / ) [ 0 ]
193- console . log ( `Using Bundler ${ majorVersion } from ${ path } BUNDLED WITH ${ bundlerVersion } ` )
189+ console . log ( `Using Bundler ${ majorVersion } from ${ lockFile } BUNDLED WITH ${ bundlerVersion } ` )
194190 return majorVersion
195191 }
196192 }
@@ -239,17 +235,16 @@ async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefi
239235 }
240236}
241237
242- async function bundleInstall ( gemfilePath , lockPath , platform , engine , version ) {
243- if ( ! fs . existsSync ( gemfilePath ) ) {
238+ async function bundleInstall ( gemfile , lockFile , platform , engine , version ) {
239+ if ( gemfile === null ) {
244240 console . log ( 'Could not determine gemfile path, skipping "bundle install" and caching' )
245241 return false
246242 }
247243
248244 // config
249245 const path = 'vendor/bundle'
250- const hasGemfileLock = fs . existsSync ( lockPath )
251246
252- if ( hasGemfileLock ) {
247+ if ( lockFile !== null ) {
253248 await exec . exec ( 'bundle' , [ 'config' , '--local' , 'deployment' , 'true' ] )
254249 }
255250 await exec . exec ( 'bundle' , [ 'config' , '--local' , 'path' , path ] )
@@ -259,10 +254,10 @@ async function bundleInstall(gemfilePath, lockPath, platform, engine, version) {
259254 const baseKey = await computeBaseKey ( platform , engine , version )
260255 let key = baseKey
261256 let restoreKeys
262- if ( hasGemfileLock ) {
263- key += `-${ lockPath } -${ await common . hashFile ( lockPath ) } `
257+ if ( lockFile !== null ) {
258+ key += `-${ lockFile } -${ await common . hashFile ( lockFile ) } `
264259 // If only Gemfile.lock we can reuse some of the cache (but it will keep old gem versions in the cache)
265- restoreKeys = [ `${ baseKey } -${ lockPath } -` ]
260+ restoreKeys = [ `${ baseKey } -${ lockFile } -` ]
266261 } else {
267262 // Only exact key, to never mix native gems of different platforms or Ruby versions
268263 restoreKeys = [ ]
0 commit comments