[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"...`);
const bundleAppConfig = await getWriteableDirectory();
try {
await execa(
const { exitCode, stderr, stdout } = await execa(
bundlePath,
[
'install',
'--deployment',
'--gemfile',
gemfilePath,
'--path',
bundleDir,
],
['install', '--deployment', '--gemfile', gemfilePath, '--path', bundleDir],
{
stdio: 'pipe',
reject: false,
env: {
...process.env,
BUNDLE_SILENCE_ROOT_WARNING: '1',
BUNDLE_APP_CONFIG: bundleAppConfig,
BUNDLE_JOBS: '4',
},
}
);
} catch (err) {
debug(`failed to run "bundle install --deployment"...`);
throw err;
if (
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 {
// try installing. this won't work if native extesions are required.
// if that's the case, gems should be vendored locally before deploying.
try {
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 {

View File

@@ -5,15 +5,13 @@ import { Meta, NodeVersion, debug, NowBuildError } from '@vercel/build-utils';
interface RubyVersion extends NodeVersion {
minor: number;
patch: number;
}
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,
minor: 5,
patch: 0,
range: '2.5.x',
runtime: 'ruby2.5',
discontinueDate: new Date('2021-11-30'),
@@ -57,7 +55,7 @@ function getRubyPath(meta: Meta, gemfileContents: string) {
if (isDiscontinued(selection)) {
const latest = getLatestRubyVersion();
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({
code: 'RUBY_DISCONTINUED_VERSION',
link: 'http://vercel.link/ruby-version',

View File

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

View File

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

View File

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

View File

@@ -12,7 +12,7 @@ const fixturesPath = path.resolve(__dirname, 'fixtures');
const testsThatFailToBuild = new Map([
[
'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.',
],
]);