diff --git a/dist/index.js b/dist/index.js index 2cc3c6c..0c34bda 100644 --- a/dist/index.js +++ b/dist/index.js @@ -51418,18 +51418,48 @@ async function setupRuby(options = {}) { } if (inputs['bundler'] !== 'none') { + const [gemFile, lockFile] = detectGemfiles() + await common.measure('Installing Bundler', async () => - installBundler(inputs['bundler'], platform, rubyPrefix, engine, version)) + installBundler(inputs['bundler'], lockFile, platform, rubyPrefix, engine, version)) if (inputs['bundler-cache'] === 'true') { await common.measure('bundle install', async () => - bundleInstall(platform, engine, version)) + bundleInstall(gemFile, lockFile, platform, engine, version)) } } core.setOutput('ruby-prefix', rubyPrefix) } +function detectGemfiles() { + const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile' + + if (fs.existsSync(gemfilePath)) { + const lockPath = `${gemfilePath}.lock` + + if (fs.existsSync(lockPath)) { + return [gemfilePath, lockPath] + } else { + return [gemfilePath, null] + } + } + + const gemsPath = "gems.rb" + + if (fs.existsSync(gemsPath)) { + const lockPath = "gems.locked" + + if (fs.existsSync(lockPath)) { + return [gemsPath, lockPath] + } else { + return [gemsPath, null] + } + } + + return [null, null] +} + function parseRubyEngineAndVersion(rubyVersion) { if (rubyVersion === 'default') { if (fs.existsSync('.ruby-version')) { @@ -51525,12 +51555,12 @@ function readBundledWithFromGemfileLock(path) { return null } -async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) { +async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) { var bundlerVersion = bundlerVersionInput if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { - const gemfilePath = `${process.env['BUNDLE_GEMFILE'] || 'Gemfile'}.lock` - bundlerVersion = readBundledWithFromGemfileLock(gemfilePath) + bundlerVersion = readBundledWithFromGemfileLock(lockFile) + if (!bundlerVersion) { bundlerVersion = 'latest' } @@ -51566,15 +51596,16 @@ async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, } } -async function bundleInstall(platform, engine, version) { - if (!fs.existsSync('Gemfile')) { - console.log('No Gemfile, skipping "bundle install" and caching') - return +async function bundleInstall(gemfilePath, lockPath, platform, engine, version) { + if (!fs.existsSync(gemfilePath)) { + console.log('Could not determine gemfile path, skipping "bundle install" and caching') + return false } // config const path = 'vendor/bundle' - const hasGemfileLock = fs.existsSync('Gemfile.lock'); + const hasGemfileLock = fs.existsSync(lockPath) + if (hasGemfileLock) { await exec.exec('bundle', ['config', '--local', 'deployment', 'true']) } @@ -51586,9 +51617,9 @@ async function bundleInstall(platform, engine, version) { let key = baseKey let restoreKeys if (hasGemfileLock) { - key += `-Gemfile.lock-${await common.hashFile('Gemfile.lock')}` + key += `-${lockPath}-${await common.hashFile(lockPath)}` // If only Gemfile.lock we can reuse some of the cache (but it will keep old gem versions in the cache) - restoreKeys = [`${baseKey}-Gemfile.lock-`] + restoreKeys = [`${baseKey}-${lockPath}-`] } else { // Only exact key, to never mix native gems of different platforms or Ruby versions restoreKeys = [] @@ -51634,6 +51665,8 @@ async function bundleInstall(platform, engine, version) { } } } + + return true } async function computeBaseKey(platform, engine, version) { diff --git a/index.js b/index.js index 729e968..e63c540 100644 --- a/index.js +++ b/index.js @@ -61,18 +61,48 @@ export async function setupRuby(options = {}) { } if (inputs['bundler'] !== 'none') { + const [gemFile, lockFile] = detectGemfiles() + await common.measure('Installing Bundler', async () => - installBundler(inputs['bundler'], platform, rubyPrefix, engine, version)) + installBundler(inputs['bundler'], lockFile, platform, rubyPrefix, engine, version)) if (inputs['bundler-cache'] === 'true') { await common.measure('bundle install', async () => - bundleInstall(platform, engine, version)) + bundleInstall(gemFile, lockFile, platform, engine, version)) } } core.setOutput('ruby-prefix', rubyPrefix) } +function detectGemfiles() { + const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile' + + if (fs.existsSync(gemfilePath)) { + const lockPath = `${gemfilePath}.lock` + + if (fs.existsSync(lockPath)) { + return [gemfilePath, lockPath] + } else { + return [gemfilePath, null] + } + } + + const gemsPath = "gems.rb" + + if (fs.existsSync(gemsPath)) { + const lockPath = "gems.locked" + + if (fs.existsSync(lockPath)) { + return [gemsPath, lockPath] + } else { + return [gemsPath, null] + } + } + + return [null, null] +} + function parseRubyEngineAndVersion(rubyVersion) { if (rubyVersion === 'default') { if (fs.existsSync('.ruby-version')) { @@ -168,12 +198,12 @@ function readBundledWithFromGemfileLock(path) { return null } -async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) { +async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) { var bundlerVersion = bundlerVersionInput if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { - const gemfilePath = `${process.env['BUNDLE_GEMFILE'] || 'Gemfile'}.lock` - bundlerVersion = readBundledWithFromGemfileLock(gemfilePath) + bundlerVersion = readBundledWithFromGemfileLock(lockFile) + if (!bundlerVersion) { bundlerVersion = 'latest' } @@ -209,15 +239,16 @@ async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, } } -async function bundleInstall(platform, engine, version) { - if (!fs.existsSync('Gemfile')) { - console.log('No Gemfile, skipping "bundle install" and caching') - return +async function bundleInstall(gemfilePath, lockPath, platform, engine, version) { + if (!fs.existsSync(gemfilePath)) { + console.log('Could not determine gemfile path, skipping "bundle install" and caching') + return false } // config const path = 'vendor/bundle' - const hasGemfileLock = fs.existsSync('Gemfile.lock'); + const hasGemfileLock = fs.existsSync(lockPath) + if (hasGemfileLock) { await exec.exec('bundle', ['config', '--local', 'deployment', 'true']) } @@ -229,9 +260,9 @@ async function bundleInstall(platform, engine, version) { let key = baseKey let restoreKeys if (hasGemfileLock) { - key += `-Gemfile.lock-${await common.hashFile('Gemfile.lock')}` + key += `-${lockPath}-${await common.hashFile(lockPath)}` // If only Gemfile.lock we can reuse some of the cache (but it will keep old gem versions in the cache) - restoreKeys = [`${baseKey}-Gemfile.lock-`] + restoreKeys = [`${baseKey}-${lockPath}-`] } else { // Only exact key, to never mix native gems of different platforms or Ruby versions restoreKeys = [] @@ -277,6 +308,8 @@ async function bundleInstall(platform, engine, version) { } } } + + return true } async function computeBaseKey(platform, engine, version) {