-
Notifications
You must be signed in to change notification settings - Fork 34
Constrain Ruby to only supported versions #40
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
base: main
Are you sure you want to change the base?
Changes from all commits
60ca71a
2c321b2
b6e4b5c
15e26b4
da5be66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| nodejs 24.10.0 | ||
| ruby 3.2.2 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| source 'https://rubygems.org' | ||
| ruby '>= 3.0' | ||
| ruby '>= 3.0', '< 3.4' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using standard syntax in the |
||
|
|
||
| gem 'rails', '7.0.7.2' | ||
|
|
||
|
|
@@ -20,4 +20,4 @@ gem 'puma' | |
|
|
||
| gem 'pry' | ||
|
|
||
| gem 'tzinfo-data', platforms: [:x64_mingw, :mingw, :mswin] | ||
| gem 'tzinfo-data', platforms: [:x64_mingw, :mingw, :mswin] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,39 @@ | ||
| #!/usr/bin/env ruby | ||
|
|
||
| gemfile = File.read("./Gemfile") | ||
| REQUIRED_RUBY_VERSION = gemfile[/ruby ['"]>=(.+)['"]/, 1] | ||
| ACTUAL_RUBY_VERSION = RUBY_VERSION | ||
| PREFERRED_RUBY_VERSION = File.read("../.ruby-version").strip | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we already have a |
||
|
|
||
| HOMEBREW_INSTALLATION_COMMAND = '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"' | ||
| RY_INSTALLATION_COMMAND = "brew update && brew install ry" | ||
|
|
||
| RUBY_VERSION_MANAGER_INSTALLATION_INSTRUCTIONS = { | ||
| "asdf" => { | ||
| "install" => "asdf install ruby #{PREFERRED_RUBY_VERSION}", | ||
| "use" => "asdf set ruby #{PREFERRED_RUBY_VERSION}", | ||
| }, | ||
| "rbenv" => { | ||
| "install" => "rbenv install #{REQUIRED_RUBY_VERSION}", | ||
| "use" => "rbenv shell #{REQUIRED_RUBY_VERSION}", | ||
| "install" => "rbenv install #{PREFERRED_RUBY_VERSION}", | ||
| "use" => "rbenv shell #{PREFERRED_RUBY_VERSION}", | ||
| }, | ||
| "rvm" => { | ||
| "install" => "rvm install #{REQUIRED_RUBY_VERSION}", | ||
| "use" => "rvm #{REQUIRED_RUBY_VERSION}", | ||
| "install" => "rvm install #{PREFERRED_RUBY_VERSION}", | ||
| "use" => "rvm #{PREFERRED_RUBY_VERSION}", | ||
| }, | ||
| "ry" => { | ||
| "install" => "ry install #{REQUIRED_RUBY_VERSION}", | ||
| "use" => "eval $(ry setup); ry use #{REQUIRED_RUBY_VERSION}", | ||
| "install" => "ry install #{PREFERRED_RUBY_VERSION}", | ||
| "use" => "eval $(ry setup); ry use #{PREFERRED_RUBY_VERSION}", | ||
| } | ||
| } | ||
| PREFERRED_RUBY_VERSION_MANAGERS = RUBY_VERSION_MANAGER_INSTALLATION_INSTRUCTIONS.keys.reject { |key| key == "ry" } | ||
| FALLBACK_RUBY_VERSION_MANAGER = "ry" | ||
|
|
||
| def parse_ruby_version_constraints | ||
| File.read("./Gemfile")[/ruby .*/][5..].split(',').map do |constraint| | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic builds on the regex approach already present in this repo and makes some tightly coupled assumptions about the code in this repository (Gemfiles are basically code and parsing them with regex is brittle) - which is not ideal but "fine" and doesn't make the code any worse than before. |
||
| constraint = constraint.gsub(/['"]/, '') | ||
| Gem::Dependency.new('ruby', constraint) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Version constraints are much more complex than how we're treating them so far. At the moment we just assume the number set is the minimum version. We could've just continued down that path and also parsed out a max version to achieve what we need. However, there is already a class that exists to solve this and it's already installed as part of RubyGems - here we start using the Gem::Depencency class to parse all constraints set in the Gemfile to compare the current version of Ruby against any constraints set out. This is simpler and more reliable than what we did before. |
||
| end | ||
| end | ||
|
|
||
| def command_exists?(command) | ||
| system("command -v #{command} &> /dev/null") | ||
| end | ||
|
|
@@ -50,11 +60,13 @@ def ry_needs_to_be_installed? | |
| !command_exists?("ry") | ||
| end | ||
|
|
||
| RUBY_VERSION_CONSTRAINTS = parse_ruby_version_constraints | ||
|
|
||
| puts "" | ||
| puts "🤖 I am The Determinator! Come with me if you want to use the right Ruby version!" | ||
| puts "ℹ️ Minicom uses Ruby #{REQUIRED_RUBY_VERSION} or greater. Let me check what version of Ruby you have…" | ||
| puts "ℹ️ Minicom uses Ruby #{RUBY_VERSION_CONSTRAINTS.map{ |d| d.requirement.to_s }.join(', ')}. Let me check what version of Ruby you have…" | ||
|
|
||
| if REQUIRED_RUBY_VERSION <= ACTUAL_RUBY_VERSION | ||
| if RUBY_VERSION_CONSTRAINTS.all?{ |d| d.match?('ruby', ACTUAL_RUBY_VERSION) } | ||
| puts "✅ You’re using Ruby #{ACTUAL_RUBY_VERSION}. You’re all set!" | ||
| exit(0) | ||
| else | ||
|
|
@@ -73,8 +85,8 @@ else | |
| end | ||
| end | ||
|
|
||
| puts "💎 Install Ruby #{REQUIRED_RUBY_VERSION} with `#{RUBY_VERSION_MANAGER_INSTALLATION_INSTRUCTIONS[ruby_version_manager_to_use]['install']}`" | ||
| puts "💎 Switch to Ruby #{REQUIRED_RUBY_VERSION} with `#{RUBY_VERSION_MANAGER_INSTALLATION_INSTRUCTIONS[ruby_version_manager_to_use]['use']}`" | ||
| puts "💎 Install Ruby #{PREFERRED_RUBY_VERSION} with `#{RUBY_VERSION_MANAGER_INSTALLATION_INSTRUCTIONS[ruby_version_manager_to_use]['install']}`" | ||
| puts "💎 Switch to Ruby #{PREFERRED_RUBY_VERSION} with `#{RUBY_VERSION_MANAGER_INSTALLATION_INSTRUCTIONS[ruby_version_manager_to_use]['use']}`" | ||
| puts "🔄 Run `bin/determinator` again to double-check you’re using the right Ruby version" | ||
|
|
||
| exit(1) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't set the |
||
|
|
||
| cd rails | ||
| ./bin/determinator | ||
| gem install bundler | ||
| bundle install | ||
| bundle exec rake db:setup | ||
| bundle exec rake db:setup | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already seem to have a
.tools-versionfile used by theasdfversion manager, so we might as well support Ruby in there as well.minicom-public/.ruby-version
Line 1 in a7915b1