Skip to content

Commit

Permalink
Bundler: support ruby 2.7 and 3.0 in gemspecs
Browse files Browse the repository at this point in the history
Support gemspecs with `required_ruby_version` requirements matching 2.7
and 3.0. Also updated the other major versions to the latest available
version to match stricted requirements.

I'm not sure why we actually do this re-write from a requirement `>=
2.7.2` to `2.7.2`. Removing this logic seems to still work for some
updates that previously failed but fail with others so I don't yet feel
confident in re-writing this.

Tested that this fix works for projects that require ruby 2.7+ but don't
rely on bundler 2 gems:

`bin/dry-run.rb bundler "HerbCSO/carstens-butler" --dir="/." --commit=331380d8f3e1b7d594405cb973d09f202c3ccfb6 --cache=files`

For projects that rely on gems that requireme bundler 2 the updater now
raises a `dependency_file_not_resolvable` error:

`bin/dry-run.rb bundler sider/runners --commit=c272ab680b5bf2f1a4f0f268e154941c77085bdf`

This should be fixed by upgrading bundler.
  • Loading branch information
feelepxyz committed Jan 7, 2021
1 parent 91733ec commit 622470c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ module Dependabot
module Bundler
class FileUpdater
class RubyRequirementSetter
RUBY_VERSIONS =
%w(1.8.7 1.9.3 2.0.0 2.1.10 2.2.10 2.3.8 2.4.7 2.5.6 2.6.4).freeze
class RubyVersionNotFound < StandardError; end

RUBY_VERSIONS = %w(
1.8.7 1.9.3 2.0.0 2.1.10 2.2.10 2.3.8 2.4.10 2.5.8 2.6.6 2.7.2 3.0.0
).freeze

attr_reader :gemspec

Expand Down Expand Up @@ -53,7 +56,7 @@ def ruby_version
map { |v| Gem::Version.new(v) }.sort.
find { |v| requirement.satisfied_by?(v) }

raise "Couldn't find Ruby version!" unless ruby_version
raise RubyVersionNotFound unless ruby_version

ruby_version
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@
let(:content) { fixture("ruby", "gemfiles", "Gemfile") }
let(:gemspec_body) { fixture("ruby", "gemspecs", "impossible_ruby") }

specify { expect { rewrite }.to raise_error(/Ruby version/) }
specify { expect { rewrite }.to raise_error(described_class::RubyVersionNotFound) }
end

context "when requiring ruby 3" do
let(:gemspec_body) { fixture("ruby", "gemspecs", "require_ruby_3") }
let(:content) { fixture("ruby", "gemfiles", "Gemfile") }
it { is_expected.to include("ruby '3.0.0'\n") }
it { is_expected.to include(%(gem "business", "~> 1.4.0")) }
end

context "that can't be evaluated" do
Expand Down
22 changes: 22 additions & 0 deletions bundler/spec/fixtures/ruby/gemspecs/require_ruby_3
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = "example"
spec.version = "0.9.3"
spec.summary = "Automated dependency management"
spec.description = "Core logic for updating a GitHub repos dependencies"

spec.author = "Dependabot"
spec.email = "[email protected]"
spec.homepage = "https://github.com/hmarr/example"
spec.license = "MIT"

spec.require_path = "lib"
spec.files = Dir["CHANGELOG.md", "LICENSE.txt", "README.md",
"lib/**/*", "helpers/**/*"]

spec.required_ruby_version = ">= 3.0.0"
spec.required_rubygems_version = ">= 2.6.11"

spec.add_dependency 'business', '~> 1.0'
end

0 comments on commit 622470c

Please sign in to comment.