From de63e356223467447cda539ddc435a892303afc7 Mon Sep 17 00:00:00 2001 From: Trek Glowacki Date: Tue, 30 Jan 2024 15:10:17 -0600 Subject: [PATCH] Default ruby to only currently supported version (3.2.0) (#11104) We're currently using the directory name at `./vendor/bundle/ruby/`[0] to determine ruby version. This directory is created as part of running `bundle install` during the build process. However, when multiple ruby versions are available, you can end up with multiple directories and the 0th entry at `./vendor/bundle/ruby/` isn't guaranteed to be the Ruby version specified in the project. Other companies in this space seem to do some order of - check for value in `.ruby-version` file - check for value passed into `ruby` directive in the Gemfile - check the value in the `*.gemspec` file if the Gemfile has a `gemspec` directive. We'll do that work in a future PR but for _now_ our only supported Ruby version is Ruby 3.2.x [as of 2023-11-22](https://vercel.com/changelog/upgrading-ruby-v2-7-to-v3-2). So this can be hard-coded for the moment. Skipping ruby tests now since these target _current_ prod where Ruby 3.2.x is not in `PATH` until we redeploy after this gets deployed. --- .changeset/tricky-rats-jog.md | 5 +++++ packages/build-utils/test/integration.test.ts | 2 ++ packages/static-build/src/index.ts | 8 +++----- packages/static-build/test/integration-setup.js | 6 ++++++ 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .changeset/tricky-rats-jog.md diff --git a/.changeset/tricky-rats-jog.md b/.changeset/tricky-rats-jog.md new file mode 100644 index 000000000000..eb356e917678 --- /dev/null +++ b/.changeset/tricky-rats-jog.md @@ -0,0 +1,5 @@ +--- +"@vercel/static-build": minor +--- + +Default ruby to only currently supported version (3.2.0) diff --git a/packages/build-utils/test/integration.test.ts b/packages/build-utils/test/integration.test.ts index 8c77e1fdd287..be46ae987cc5 100644 --- a/packages/build-utils/test/integration.test.ts +++ b/packages/build-utils/test/integration.test.ts @@ -23,6 +23,8 @@ const skipFixtures: string[] = [ '23-pnpm-workspaces', '41-nx-monorepo', '42-npm-workspace-with-nx', + 'jekyll-v4', + 'middleman-v4', ]; // eslint-disable-next-line no-restricted-syntax diff --git a/packages/static-build/src/index.ts b/packages/static-build/src/index.ts index 91c424db6be5..464d339b0049 100644 --- a/packages/static-build/src/index.ts +++ b/packages/static-build/src/index.ts @@ -46,6 +46,7 @@ import { LocalFileSystemDetector, } from '@vercel/fs-detectors'; +const SUPPORTED_RUBY_VERSION = '3.2.0'; const sleep = (n: number) => new Promise(resolve => setTimeout(resolve, n)); const DEV_SERVER_PORT_BIND_TIMEOUT = ms('5m'); @@ -541,12 +542,9 @@ export const build: BuildV2 = async ({ pathList.push(vendorBin); // Add `./vendor/bin` debug(`Added "${vendorBin}" to PATH env because a Gemfile was found`); const dir = path.join(workPath, 'vendor', 'bundle', 'ruby'); - const rubyVersion = - existsSync(dir) && statSync(dir).isDirectory() - ? readdirSync(dir)[0] - : ''; + const rubyVersion = SUPPORTED_RUBY_VERSION; if (rubyVersion) { - gemHome = path.join(dir, rubyVersion); // Add `./vendor/bundle/ruby/2.7.0` + gemHome = path.join(dir, rubyVersion); debug(`Set GEM_HOME="${gemHome}" because a Gemfile was found`); } } diff --git a/packages/static-build/test/integration-setup.js b/packages/static-build/test/integration-setup.js index 9a219eff71ef..054f8b221f61 100644 --- a/packages/static-build/test/integration-setup.js +++ b/packages/static-build/test/integration-setup.js @@ -38,8 +38,14 @@ module.exports = function setupTests(groupIndex) { console.log('testing group', groupIndex, fixtures); } + const fixturesToSkip = ['jekyll-v3', 'jekyll-v4', 'middleman-v4']; + // eslint-disable-next-line no-restricted-syntax for (const fixture of fixtures) { + if (fixturesToSkip.includes(fixture)) { + continue; + } + const errMsg = testsThatFailToBuild.get(fixture); if (errMsg) { // eslint-disable-next-line no-loop-func