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
Set Ruby version in Gemfile and .ruby-version by default #30016
Set Ruby version in Gemfile and .ruby-version by default #30016
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
@@ -1,4 +1,5 @@ | |||
source 'https://rubygems.org' | |||
ruby <%= "'#{RUBY_VERSION}'" %> |
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.
Could you put this after the git_source
entry?
@rafaelfranca Done. As it was a minor change I have already squashed commits. In case requested changes implied more lines, would you prefer first to review the changes? After it is done I would proceed squashing commits. |
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.
That is great! Could you add a CHANGELOG entry too and squash the commits?
Done. @rafaelfranca |
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.
Looking good, waiting for CI to merge
@@ -1,5 +1,6 @@ | |||
source 'https://rubygems.org' | |||
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |||
ruby <%= "'#{RUBY_VERSION}'" %> |
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.
What about using ruby RUBY_VERSION
here? Seems a bit DRYer.
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.
I use this "trick", but I haven't tried it with heroku
, so maybe it doesn't work well, not sure.
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.
Thanks @deivid-rodriguez , I already tried that and generating the app with bundle exec rails new ~/my-test-app --dev
caused the following error parsing the Gemfile:
[!] There was an error parsing `Gemfile`: unexpected fraction part after numeric literal - ruby 2.3.1
^
/Users/alberto.almagro/my-test-app/Gemfile:3: syntax error, unexpected tIDENTIFIER, expecting end-of-input
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
^. Bundler cannot continue.
# from /Users/alberto.almagro/my-test-app/Gemfile:2
# -------------------------------------------
# source 'https://rubygems.org'
> ruby 2.3.1
# git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# -------------------------------------------
I've surrounded it with single quotes, which is what is used in the line above for the source entry.
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.
Sorry @albertoalmagro, totally forgot to answer this. What I meant is not to generate ruby 2.3.1
without quotes, but to generate ruby RUBY_VERSION
, which I think would be generated by using ruby RUBY_VERSION
(wihout <%=
, %>
block).
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.
This defeats the point of putting Ruby version in the Gemfile. Now any version you are using will be valid from 1.8.7 to 2.4.1.
I think we should revert this.
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.
@schneems - I can't see how that would happen as long as the . Am I missing something?.ruby_version
file is committed
Nice! Would you be up for reading the Ruby version out of the Happy to put in a PR if so. |
@greysteil What about |
@deivid-rodriguez interesting. It makes an assumption about the Ruby manager respecting the @albertoalmagro - any thoughts? |
I suppose one minor objection to the environment variable approach would be that it's less explicit where the Ruby version is being set. Might cause confusion, particularly for a newer developer? And if the |
ISTM that having Locally, hard-coding the Ruby version inside the Gemfile prevents it from resolving if someone is trying to As for Heroku, the |
It should be useful - Given the confusion, I'm not sure the environment variable approach is clear enough, though - I think I prefer reading the |
I'll create a new PR so we're not spamming poor @albertoalmagro. This is still a rad contribution though - nice one @albertoalmagro. |
Nice one @greysteil . Opportunities to learn something new and fresh ideas are never spam ;) |
Not everybody uses a Ruby version manager. |
I use chruby which does not use the .ruby-version file. It would be better to have rbenv understand how to read the ruby version from Gemfile.lock. I would like to revert this change. |
I reverted the change a8f5904. The good news is you get to keep your contributor points for contributors.rubyonrails.org !! Reverts don't actually remove a commit, it adds an extra "undo" commit that changes back all your changes. Thanks for the PR, sorry I wasn't paying more attention before. It's always better to have people involved earlier than later. I appreciate all the effort that went into making this. |
@schneems Lets get more on my next PR, which is already in CR. The most important thing is to make Rails better, thanks. |
I think we've crossed wires here a bit. Given that I originally requested this feature, perhaps I was unclear with the rational. I'm fine with the fact that the version is duplicated between .ruby-version and Gemfile. Just as long as they're set by default. If at some point rbenv learns to read the version from a Gemfile, then we can drop the .ruby-version. But until that I'd like that to stay. |
Setting the Ruby version in the Gemfile just raises an exception if it doesn't match. You still need to ensure that the correct Ruby version is actually running, which is what .ruby-version supplies for rbenv and rvm. |
I reverted the revert. Sorry for the confusion! Happy to drop .ruby-version if the day should come that rbenv and rvm support parsing the Gemfile to get the Ruby version. But it seems uncertain whether, and if so, when that would happen. In the mean time this will do. |
Ahh, yes. Sorry. I made the mistake here. |
@dhh rvm already support Ruby version detection through Gemfile : https://rvm.io/workflow/projects#supported-files |
.ruby-version does not work the same way with JRuby and has led to #32639. It needs to be engine-engine_version to correctly be able to switch to JRuby. I would strongly advocate against using .ruby-version, however, since we have many users on JRuby that use both JRuby and CRuby interchangeably for local development. |
Those users can remove the file, if they want. I don't think we should avoid using a good feature that make sure everyone in the same project is using the same version of Ruby that works in 80% of the cases just because it doesn't work for 20%. |
This .ruby_version is compatible with both CRuby and JRuby: #32649 |
@rafaelfranca Fair enough...we'll see if anyone cares. |
I mean, we should fix, with Guillermo PR, I don't think JRuby should be broken by default. I just think that the cases where you need to have different implementations, which is not common, should be handled differently. One could say that if people want to use JRuby and CRuby for local development they can use |
Rails 5.2.0 will give us ActiveStorage and all sorts of other goodies: http://edgeguides.rubyonrails.org/5_2_release_notes.html rails/rails#30016 introduced `Rails::AppBuilder#ruby_version` to create a .ruby_version file. To avoid getting stuck in an overwrite prompt when we try to create our own .ruby_version file based on `Suspenders::RUBY_VERSION`, I overrode `ruby_version`. Rails 5.2.0 adds bootsnap to the Gemfile and to config/boot.rb. I added it to our Gemfile, but we could also `skip_bootsnap` by default if we don't want to use it.
Rails 5.2.0 will give us ActiveStorage and all sorts of other goodies: http://edgeguides.rubyonrails.org/5_2_release_notes.html rails/rails#30016 introduced `Rails::AppBuilder#ruby_version` to create a .ruby_version file. To avoid getting stuck in an overwrite prompt when we try to create our own .ruby_version file based on `Suspenders::RUBY_VERSION`, I overrode `ruby_version`. Rails 5.2.0 adds bootsnap to the Gemfile and to config/boot.rb. I added it to our Gemfile, but we could also `skip_bootsnap` by default if we don't want to use it.
Since rails#30016 Rails generates `.ruby-version` file in order to help Ruby version manager tools like `rbenv`, `rvm` determine which Ruby version should be used for the current Rails project. Since rails#32649 Rails sets Ruby version to the file compatible with MRI/JRuby by default. Pull Request rails#31496 reports that `.ruby-version` doesn't match ruby version other than stable version and recommends to use `ENV["RBENV_VERSION"]`, and `ENV["rvm_ruby_string"]` in order to set correct Ruby version to the file that `rbenv` or `rvm` can understand. Also, there is another similar issue that reports the same case if use JRuby jruby/jruby#5144. Closes rails#31496, jruby/jruby#5144.
This updates the version of ruby tested in the application to be ruby 2.6.0. This still relies on the `RUBY_VERSION` constant that's defined in ruby to know what version of ruby to include. This also removes the code that will add the ruby version to the Gemfile. Rails 5.2 will add the ruby version to the Gemfile for you, based on this contribution: rails/rails#30016.
This updates the version of ruby tested in the application to be ruby 2.6.0. This still relies on the `RUBY_VERSION` constant that's defined in ruby to know what version of ruby to include. This also removes the code that will add the ruby version to the Gemfile. Rails 5.2 will add the ruby version to the Gemfile for you, based on this contribution: rails/rails#30016.
This updates the version of ruby tested in the application to be ruby 2.6.0. This still relies on the `RUBY_VERSION` constant that's defined in ruby to know what version of ruby to include. This also removes the code that will add the ruby version to the Gemfile. Rails 5.2 will add the ruby version to the Gemfile for you, based on this contribution: rails/rails#30016.
This updates the version of ruby tested in the application to be ruby 2.6.1. This still relies on the `RUBY_VERSION` constant that's defined in ruby to know what version of ruby to include. This also removes the code that will add the ruby version to the Gemfile. Rails 5.2 will add the ruby version to the Gemfile for you, based on this contribution: rails/rails#30016. The latest Circle images utilize bundler >= 2, which is causing issues for the template install process. This circumvents that by modifying the image to remove the currently-installed version of bundler, and replacing it with a specific version that's known to work. Additional effort will be required to support bundler >= 2.
Rails 5.2.0 will give us ActiveStorage and all sorts of other goodies: http://edgeguides.rubyonrails.org/5_2_release_notes.html rails/rails#30016 introduced `Rails::AppBuilder#ruby_version` to create a .ruby_version file. To avoid getting stuck in an overwrite prompt when we try to create our own .ruby_version file based on `Suspenders::RUBY_VERSION`, I overrode `ruby_version`. Rails 5.2.0 adds bootsnap to the Gemfile and to config/boot.rb. I added it to our Gemfile, but we could also `skip_bootsnap` by default if we don't want to use it.
Rails 5.2.0 will give us ActiveStorage and all sorts of other goodies: http://edgeguides.rubyonrails.org/5_2_release_notes.html rails/rails#30016 introduced `Rails::AppBuilder#ruby_version` to create a .ruby_version file. To avoid getting stuck in an overwrite prompt when we try to create our own .ruby_version file based on `Suspenders::RUBY_VERSION`, I overrode `ruby_version`. Rails 5.2.0 adds bootsnap to the Gemfile and to config/boot.rb. I added it to our Gemfile, but we could also `skip_bootsnap` by default if we don't want to use it.
Summary
This pull request sets current Ruby version in the Gemfile and .ruby-version by default.
When running
rails new my-app
the generated application will include by default:.ruby-version
file, containing the default Ruby version.Gemfile
, with the formatruby '2.x.x'
with the same default Ruby version.Implications
Among other usages:
.ruby-version
will help ruby version manager tools such asrbenv
to determine which Ruby version should be used for the current Rails project.ruby 'version'
in theGemfile
may be used by deployment tools (i.e. Heroku) to determine the Ruby version that should be used to run Rails.