rubocop / rubocop-rails

A RuboCop extension focused on enforcing Rails best practices and coding conventions.
https://docs.rubocop.org/rubocop-rails
MIT License
819 stars 263 forks source link

Gem installation fails due to new Rails 7 release #597

Closed prayeshshah closed 2 years ago

prayeshshah commented 2 years ago

rubocop-rails has a dependency on activesupport >= 4.2.0. So after the latest Rails 7 release, it's trying to install activesupport-7.0.0. But activesupport-7.0.0 has a minimum Ruby dependency of version >=2.7 So, if you're using Ruby <2.7, the gem installation fails.

Note: We're using rubocop-rails in a style check Github action. So, it tries to install the latest activesupport-7.0.0 on the specified ruby version in .ruby-version which in our case is v2.6.6 and fails.


Expected behavior

Gem installation should not fail for Ruby versions < 2.7

Actual behavior

Screenshot 2021-12-17 at 5 30 31 PM

Steps to reproduce the problem

RuboCop version

NA

Co-authored by: @radiantshaw

pirj commented 2 years ago

Can you please give a little more context on this please? What Ruby version do you use? What bundler version? Do you install with bundle or with gem install? Are you using the latest versions of Bundler and RubyGems?

koic commented 2 years ago

When using Rails 7.0, Active Support should use 7.0. And RuboCop Rails accepts Rails 4.2 and newer. So, RuboCop Rails can use Active Support 7.0 (Rails 7.0) with Ruby 2.7 and newer.

Ruby 2.7 or newer is required to use RuboCop Rails with Rails 7.0. Can you confirm that?

prayeshshah commented 2 years ago

@pirj I'm using ruby v2.6.6 Bundler version is 1.17.3. And we used the gem install

radiantshaw commented 2 years ago

Sure @pirj. We're using GitHub Actions with the Reviewdog plugin to run RuboCop for each PRs. Reviewdog spins up a container and tries installing Ruby v2.6.6 which it picks up from our project's .ruby-version. In out RuboCop config file (.rubocop.yml), we've specified rubocop-rails as a dependency. The version of rubocop-rails we've specified in the GitHub actions workflow config file is v2.11.

rubocop-rails v2.11 has a dependency on activesupport >= 4.2.0. Initially, it was picking up some old version of activesupport, but since Rails released v7, it's picking up activesupport v7.0 now. But activesupport v7.0 has specified Ruby >= 2.7 in its gemspec file. Which is where it fails.

radiantshaw commented 2 years ago

@koic We're on Rails 5.2 BTW.

pirj commented 2 years ago

But activesupport v7.0 has specified Ruby >= 2.7 in its gemspec file. Which is where it fails.

This sounds like a Bundler's issue. It should not resolve to activesupport 7.0 if the current Ruby version (2.6.6) does not meet the requirements to support it.

Can you understand in the logs what Bundler version is used? RSpec in its internal CI tests, e.g. explicitly updates RubyGems and Bundler to the latest versions. I can only recommend doing the same if Reviewdog allows for such tuning.

There is nothing we can do on our side to prevent this dependency resolution issue.

pirj commented 2 years ago

Might be related https://github.com/rubygems/rubygems/issues/3870

radiantshaw commented 2 years ago

@pirj My initial thought was that rubocop-rails shouldn't just suggest activesupport >= 4.2.0, and instead it should do something like activesupport >= 4.2.0, < 7.0. But now that you've mentioned it, it does make sense that this might be a dependency resolution issue from either Bundler or from the gem command.

Thanks for such a quick response BTW, you guys are doing an awesome job!

pirj commented 2 years ago

Bundler version is 1.17.3

This may be the problem. I suggest you to switch to Bunder 2, preferrably the latest version of it.

@koic I don't have permissions to close this, would you?

javierjulio commented 2 years ago

I'm running into the same error as reported with Ruby 2.6.x but we are already on Bundler 2 for reviewdog. @prayeshshah @radiantshaw were you able to workaround the issue?

radiantshaw commented 2 years ago

@javierjulio Yes. What we did was specify in the GitHub action config to just use Ruby v2.7. And that solved the issue.

javierjulio commented 2 years ago

@radiantshaw great, thank you! I just did the same now and it works. Appreciate it!

pirj commented 2 years ago

We experience this problem ourselves, too 😄 https://app.circleci.com/pipelines/github/rubocop/rubocop-rails/1463/workflows/4757f75a-69cc-4953-8ceb-8059d9ee543b/jobs/9541

Found a bundler issue https://github.com/rubygems/bundler/issues/6471 and fix https://github.com/rubygems/bundler/pull/6728.

The recommendation remains: use the latest bundler 2.x