Repository navigation
feat(ruby): read .ruby-version when resolving the version - #290
Merged
Merged
Conversation
Version resolution now reads .ruby-version, the file rbenv, chruby and
ruby/setup-ruby use to pin a project's Ruby version, through the same
upward walk and precedence as the Node.js and Python version files.
Within one directory .dtvem/runtimes.json still comes first.
- An exact (3.3.6) or partial (3.3) version is accepted, with the
optional ruby- prefix rbenv strips and setup-ruby reads. A partial
version resolves to the highest installed match.
- An exact pre-release (4.0.0-preview2, 3.4.0-rc1) is accepted too,
since dtvem can install Ruby previews.
- Other engines (jruby-..., truffleruby-...), engine-only names, system,
and anything else dtvem cannot install are reported as unsupported
instead of falling back to the global version.
Version comparison now ranks a pre-release below the release it
precedes. Before, "4.0.0-preview2" and "4.0.0" compared equal, so a
partial "4.0" could pick either one, both in version files and in
dtvem install. A partial version still picks a pre-release when it is
the only match ("3.5" -> "3.5.0-preview1"), so a version file and the
dtvem install command it suggests agree.
10 of 19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
dtvem now reads
.ruby-versionwhen resolving the Ruby version. It's the file rbenv, chruby andruby/setup-rubyuse to pin a project's Ruby. A repository that pins Ruby for CI, or already carries the file for rbenv or chruby, gets the same version on a dtvem machine without a second, dtvem-specific file.It reuses the version-file mechanism from #286 and #288.
Type of Change
Related Issues
Resolves #285
Relates to #283, #284, #287
Changes Made
.dtvem/runtimes.json, so subdirectories inherit the file. The nearest directory wins. Within one directory.dtvem/runtimes.jsoncomes first, then.ruby-version, and the global version stays the fallback.3.3.6) or partial (3.3) version, with the optionalruby-prefix (ruby-3.3.6) that rbenv strips and setup-ruby reads.x.y.z-previewNorx.y.z-rcN, since dtvem's Ruby manifest includes previews (3.5.0-preview1,4.0.0-preview2). A partial pre-release such as4.0-preview2is rejected.#comments are skipped, and the first word of the first remaining line is used.jruby-9.4.5.0,truffleruby-24.1.0)ruby,truffleruby)system2.0.0-p648internal/versionnow ranks a pre-release below the release it precedes. Before,4.0.0-preview2and4.0.0compared equal, so with both available, a partial4.0or4could pick either.dtvem install ruby 4.0, which uses the same matcher.3.5→3.5.0-preview1). That keeps a version file consistent with thedtvem install ruby 3.5command the shim suggests: excluding previews only on the resolution side would leave that install unrecognized.23.0.0-rc.1-style versions, where the digits afterrc.used to count as a fourth version part and ranked the pre-release above its release.versionFileRulesgainsprereleases, set only for Ruby. Node.js and Python still reject pre-release suffixes.dtvem install ruby <version>, anddtvem currentshows the file in its Source column.gemand the other Ruby shims follow the file too.dtvem current --help, and the CLAUDE.md "Version Resolution" section.Testing
Test Environment
Test Steps
./rnr check: gofmt, golangci-lint (0 issues), and all tests pass.src/internal/version/matcher_test.go:rc.1.src/internal/config/versionfile_test.go:ruby-prefix, partial, preview, rc with prefix, comments.3.5.0-preview1,4.0.0-preview2and4.0.0:4.0and4pick4.0.0,3.5picks the preview, and an exact preview resolves as written.runtimes.json, and an unsupported file not falling back to the global version.ruby.exeandgem.exe, and ran them against the real install from temp project directories.Test Results
ruby -e 'puts RUBY_VERSION'3.4.7(global).ruby-version=3.3.93.3.9ruby-3.3.93.3.9# CI pin+3.3, run fromlib/deep3.3.9.dtvem/runtimes.json=3.3.9+.ruby-version=3.4.73.3.9jruby-9.4.5.0system4.0.0-preview2(not installed)Set by:the file,dtvem install ruby 4.0.0-preview2, exit 13.2(not installed)Set by:the file,dtvem install ruby 3.2, exit 1With
.ruby-version=3.3,gem envreported Ruby 3.3.9, anddtvem current rubyshowed3.3.9with the file as its Source. Preview-over-release isn't covered end to end, because no 4.0 versions are installed locally; the unit tests cover it with installed-version fixtures.Checklist
golangci-lint runand fixed all issues (includes gofmt, govet, and 40+ linters)go mod tidyto clean up dependencies (no dependency changes in this PR)go test ./...)Breaking Changes
None intended. As with the other version files, a
.ruby-versionin any parent directory now affects the Ruby shims. One holdingsystemor another engine, such as an rbenv or chruby user's~/.ruby-version, makes them stop with an error where they used to run the global version.Additional Notes
Out of scope, as the issue lists: the Gemfile
rubydirective,mise.toml, and.tool-versions(#287, next).