Skip to content

fix(ruby): support multi-part version constraints in Gemfile - #193

Open
gauravtiwari wants to merge 8 commits into
railwayapp:mainfrom
gauravtiwari:fix-ruby-version-detection
Open

fix(ruby): support multi-part version constraints in Gemfile#193
gauravtiwari wants to merge 8 commits into
railwayapp:mainfrom
gauravtiwari:fix-ruby-version-detection

Conversation

@gauravtiwari

Copy link
Copy Markdown
Contributor

This occurred because the regex pattern for extracting Ruby version constraints from Gemfiles was too restrictive and only matched single version numbers, not multi-part constraints like ruby '>= 3.2.0', '< 3.5.0'.

This fix enables Railpack to properly handle Ruby applications with version constraints in their Gemfiles, such as Mastodon and other modern Ruby applications that specify version ranges rather than exact versions.

Problem

The original regex pattern ruby (?:'|")(.*)(?:'|")[^>]" was designed to match single version strings but failed to properly extract complex version constraints that are common in modern Ruby applications.

Fix

  1. Fixed regex pattern: Updated gemfileVersionRegex to ruby\s+(?:'|")([^'"]+)(?:'|") to properly capture full version constraints
  2. Enhanced version filtering: Added logic to skip preview/dev/rc versions when resolving constraints, ensuring only stable Ruby versions are selected
  3. Improved constraint resolution: Integrated with Mise's GetAllVersions method and github.com/Masterminds/semver/v3 to dynamically resolve the highest version satisfying the constraint
  4. Updated priority order: Ensured constraint-based version resolution takes precedence over other version sources

Tests

  • Added comprehensive tests using real example projects

Comment thread core/providers/ruby/ruby.go
Comment thread core/providers/ruby/ruby.go Outdated
@iloveitaly

Copy link
Copy Markdown
Collaborator

@gauravtiwari can you rebase this on master or give me edit privileges on the PR so I can resolve the snapshot conflicts?

@coffee-cup this PR LGTM once merge conflicts are handled—anything else you want done here?

@coffee-cup

Copy link
Copy Markdown
Contributor

This looks good once conflicts are resolved

@gauravtiwari
gauravtiwari force-pushed the fix-ruby-version-detection branch from ab50da6 to 6b235bb Compare September 24, 2025 20:01
@gauravtiwari

Copy link
Copy Markdown
Contributor Author

Hi Michael & Jake - This is ready for another pass and merge. Thanks!

@iloveitaly iloveitaly changed the title Fix ruby version detection fix(ruby): support multi-part version constraints in Gemfile Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants