Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ruby 3.3 #11497

Merged
merged 14 commits into from
Apr 30, 2024
5 changes: 5 additions & 0 deletions .changeset/friendly-badgers-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/ruby': patch
---

Add support for Ruby 3.3
9 changes: 9 additions & 0 deletions packages/ruby/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ async function bundleInstall(
gemfilePath,
gemfileContent.replace('ruby "~> 3.2.x"', 'ruby "~> 3.2.0"')
);
} else if (gemfileContent.includes('ruby "~> 3.3.x"')) {
// Gemfile contains "3.3.x" which will cause an error message:
// "Your Ruby patchlevel is 0, but your Gemfile specified -1"
// See https://github.com/rubygems/bundler/blob/3f0638c6c8d340c2f2405ecb84eb3b39c433e36e/lib/bundler/errors.rb#L49
// We must correct to the actual version in the build container.
await writeFile(
gemfilePath,
gemfileContent.replace('ruby "~> 3.3.x"', 'ruby "~> 3.3.0"')
);
}

const bundlerEnv = cloneEnv(process.env, {
Expand Down
1 change: 1 addition & 0 deletions packages/ruby/src/install-ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface RubyVersion extends NodeVersion {

function getOptions() {
const options = [
{ major: 3, minor: 3, range: '3.3.x', runtime: 'ruby3.3' },
{ major: 3, minor: 2, range: '3.2.x', runtime: 'ruby3.2' },
{
major: 2,
Expand Down
2 changes: 1 addition & 1 deletion packages/ruby/test/fixtures/01-cowsay/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

source "https://rubygems.org"

ruby "~> 3.2.x"
ruby "~> 3.3.x"

gem "cowsay", "~> 0.3.0"
2 changes: 1 addition & 1 deletion packages/ruby/test/fixtures/02-cowsay-vendored/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

source "https://rubygems.org"

ruby "~> 3.2.x"
ruby "~> 3.3.x"

gem "cowsay", "~> 0.3.0"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

source "https://rubygems.org"

ruby "~> 3.2.x"
ruby "~> 3.3.x"

gem "cowsay", "~> 0.3.0"
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ GEM

PLATFORMS
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
cowsay (~> 0.3.0)
Expand Down
2 changes: 1 addition & 1 deletion packages/ruby/test/fixtures/05-sinatra/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

ruby "~> 3.2.x"
ruby "~> 3.3.x"

gem "cowsay", "~> 0.3.0"

Expand Down
13 changes: 3 additions & 10 deletions packages/ruby/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.x".` Please set `ruby "~> 3.2.x"` in your `Gemfile` to use Ruby 3.2.x.',
'Found `Gemfile` with discontinued Ruby version: `ruby "~> 2.5.x".` Please set `ruby "~> 3.3.x"` in your `Gemfile` to use Ruby 3.3.x.',
],
]);

Expand All @@ -26,19 +26,12 @@ for (const fixture of fs.readdirSync(fixturesPath)) {
continue;
}

// Ruby endpoints currently require the AL2 build image
const projectSettings = {
nodeVersion: '18.x',
};

const errMsg = testsThatFailToBuild.get(fixture);
if (errMsg) {
// eslint-disable-next-line no-loop-func
it(`should fail to build ${fixture}`, async () => {
try {
await testDeployment(path.join(fixturesPath, fixture), {
projectSettings,
});
await testDeployment(path.join(fixturesPath, fixture));
} catch (err) {
expect(err).toBeTruthy();
expect(err.deployment).toBeTruthy();
Expand All @@ -50,7 +43,7 @@ for (const fixture of fs.readdirSync(fixturesPath)) {
// eslint-disable-next-line no-loop-func
it(`should build ${fixture}`, async () => {
await expect(
testDeployment(path.join(fixturesPath, fixture), { projectSettings })
testDeployment(path.join(fixturesPath, fixture))
).resolves.toBeDefined();
});
}
2 changes: 1 addition & 1 deletion packages/static-build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
import { getHugoUrl } from './utils/hugo';
import { once } from 'events';

const SUPPORTED_RUBY_VERSION = '3.2.0';
const SUPPORTED_RUBY_VERSION = '3.3.0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't dig into this, but we probably need this value to change based on the build image (node 20 or not) we're using.

Ref: https://github.com/vercel/vercel/blob/add-ruby33-to-builder/packages/static-build/src/index.ts#L582

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really critical. This value is used to determine the vendor path where the Gem deps will be installed to. If anything, we should revisit this to install into .vercel/cache instead.

const sleep = (n: number) => new Promise(resolve => setTimeout(resolve, n));

const DEV_SERVER_PORT_BIND_TIMEOUT = ms('5m');
Expand Down