[ruby] Handle exit code 18 gracefully (#8388)

This reverts #8381 and instead supports the "2.7.x" syntax.

- Related to https://github.com/vercel/customer-issues/issues/684
This commit is contained in:
Steven
2022-08-12 15:56:13 -04:00
committed by GitHub
parent 551cd7f688
commit 6d8dbfc7d6
6 changed files with 31 additions and 38 deletions

View File

@@ -47,30 +47,32 @@ async function bundleInstall(
) { ) {
debug(`running "bundle install --deployment"...`); debug(`running "bundle install --deployment"...`);
const bundleAppConfig = await getWriteableDirectory(); const bundleAppConfig = await getWriteableDirectory();
const { exitCode, stderr, stdout } = await execa(
try {
await execa(
bundlePath, bundlePath,
[ ['install', '--deployment', '--gemfile', gemfilePath, '--path', bundleDir],
'install',
'--deployment',
'--gemfile',
gemfilePath,
'--path',
bundleDir,
],
{ {
stdio: 'pipe', stdio: 'pipe',
reject: false,
env: { env: {
...process.env,
BUNDLE_SILENCE_ROOT_WARNING: '1', BUNDLE_SILENCE_ROOT_WARNING: '1',
BUNDLE_APP_CONFIG: bundleAppConfig, BUNDLE_APP_CONFIG: bundleAppConfig,
BUNDLE_JOBS: '4', BUNDLE_JOBS: '4',
}, },
} }
); );
} catch (err) {
debug(`failed to run "bundle install --deployment"...`); if (
throw err; exitCode === 0 ||
(exitCode === 18 && stderr.includes('Gemfile specified -1'))
) {
// Gemfile might contain "2.7.x" so install might exit with code 18 and message:
// "Your Ruby patchlevel is 0, but your Gemfile specified -1"
// See https://github.com/rubygems/bundler/blob/3f0638c6c8d340c2f2405ecb84eb3b39c433e36e/lib/bundler/errors.rb#L49
} else {
throw new Error(
`"bundle install" failed with exit code ${exitCode}: ${stdout}\n${stderr}`
);
} }
} }
@@ -142,14 +144,7 @@ export async function build({
} else { } else {
// try installing. this won't work if native extesions are required. // try installing. this won't work if native extesions are required.
// if that's the case, gems should be vendored locally before deploying. // if that's the case, gems should be vendored locally before deploying.
try {
await bundleInstall(bundlerPath, bundleDir, gemfilePath); await bundleInstall(bundlerPath, bundleDir, gemfilePath);
} catch (err) {
debug(
'unable to build gems from Gemfile. vendor the gems locally with "bundle install --deployment" and retry.'
);
throw err;
}
} }
} }
} else { } else {

View File

@@ -5,15 +5,13 @@ import { Meta, NodeVersion, debug, NowBuildError } from '@vercel/build-utils';
interface RubyVersion extends NodeVersion { interface RubyVersion extends NodeVersion {
minor: number; minor: number;
patch: number;
} }
const allOptions: RubyVersion[] = [ const allOptions: RubyVersion[] = [
{ major: 2, minor: 7, patch: 0, range: '2.7.x', runtime: 'ruby2.7' }, { major: 2, minor: 7, range: '2.7.x', runtime: 'ruby2.7' },
{ {
major: 2, major: 2,
minor: 5, minor: 5,
patch: 0,
range: '2.5.x', range: '2.5.x',
runtime: 'ruby2.5', runtime: 'ruby2.5',
discontinueDate: new Date('2021-11-30'), discontinueDate: new Date('2021-11-30'),
@@ -57,7 +55,7 @@ function getRubyPath(meta: Meta, gemfileContents: string) {
if (isDiscontinued(selection)) { if (isDiscontinued(selection)) {
const latest = getLatestRubyVersion(); const latest = getLatestRubyVersion();
const intro = `Found \`Gemfile\` with discontinued Ruby version: \`${line}.\``; const intro = `Found \`Gemfile\` with discontinued Ruby version: \`${line}.\``;
const hint = `Please set \`ruby "~> ${latest.major}.${latest.minor}.${latest.patch}"\` in your \`Gemfile\` to use the latest Ruby version.`; const hint = `Please set \`ruby "~> ${latest.range}"\` in your \`Gemfile\` to use Ruby ${latest.range}.`;
throw new NowBuildError({ throw new NowBuildError({
code: 'RUBY_DISCONTINUED_VERSION', code: 'RUBY_DISCONTINUED_VERSION',
link: 'http://vercel.link/ruby-version', link: 'http://vercel.link/ruby-version',

View File

@@ -2,6 +2,6 @@
source "https://rubygems.org" source "https://rubygems.org"
ruby "~> 2.7.0" ruby "~> 2.7.x"
gem "cowsay", "~> 0.3.0" gem "cowsay", "~> 0.3.0"

View File

@@ -2,6 +2,6 @@
source "https://rubygems.org" source "https://rubygems.org"
ruby "~> 2.7.0" ruby "~> 2.7.x"
gem "cowsay", "~> 0.3.0" gem "cowsay", "~> 0.3.0"

View File

@@ -2,6 +2,6 @@
source "https://rubygems.org" source "https://rubygems.org"
ruby "~> 2.5.0" ruby "~> 2.5.x"
gem "cowsay", "~> 0.3.0" gem "cowsay", "~> 0.3.0"

View File

@@ -12,7 +12,7 @@ const fixturesPath = path.resolve(__dirname, 'fixtures');
const testsThatFailToBuild = new Map([ const testsThatFailToBuild = new Map([
[ [
'11-version-2-5-error', '11-version-2-5-error',
'Found `Gemfile` with discontinued Ruby version: `ruby "~> 2.5.0".` Please set `ruby "~> 2.7.0"` in your `Gemfile` to use the latest Ruby version.', 'Found `Gemfile` with discontinued Ruby version: `ruby "~> 2.5.x".` Please set `ruby "~> 2.7.x"` in your `Gemfile` to use Ruby 2.7.x.',
], ],
]); ]);