Skip to content
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

Fix Ruby version conflict error detection for new Bundler versions #4820

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class LockfileUpdater
require_relative "gemspec_updater"
require_relative "gemspec_sanitizer"
require_relative "gemspec_dependency_name_finder"
require_relative "ruby_requirement_setter"

LOCKFILE_ENDING =
/(?<ending>\s*(?:RUBY VERSION|BUNDLED WITH).*)/m.freeze
Expand Down Expand Up @@ -80,23 +79,10 @@ def build_updated_lockfile
)
end
post_process_lockfile(lockfile_body)
rescue SharedHelpers::HelperSubprocessFailed => e
raise unless ruby_lock_error?(e)

@dont_lock_ruby_version = true
retry
end

def ruby_lock_error?(error)
return false unless error.error_class == "Bundler::VersionConflict"
return false unless error.message.include?(" for gem \"ruby\0\"")
return false if @dont_lock_ruby_version

dependency_files.any? { |f| f.name.end_with?(".gemspec") }
end

def write_temporary_dependency_files
File.write(gemfile.name, prepared_gemfile_content(gemfile))
File.write(gemfile.name, updated_gemfile_content(gemfile))
File.write(lockfile.name, sanitized_lockfile_body)

top_level_gemspecs.each do |gemspec|
Expand Down Expand Up @@ -236,21 +222,6 @@ def replacement_version_for_gemspec(gemspec_content)
end
# rubocop:enable Metrics/PerceivedComplexity

def prepared_gemfile_content(file)
content =
GemfileUpdater.new(
dependencies: dependencies,
gemfile: file
).updated_gemfile_content
return content if @dont_lock_ruby_version

top_level_gemspecs.each do |gs|
content = RubyRequirementSetter.new(gemspec: gs).rewrite(content)
end

content
end

def updated_gemfile_content(file)
GemfileUpdater.new(
dependencies: dependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def error_due_to_restrictive_upper_bound?(error)
end

def ruby_lock_error?(error)
return false unless error.message.include?(" for gem \"ruby\0\"")
return false unless error.message.include?(" for the Ruby\0 version") || # Bundler 2
error.message.include?(" for gem \"ruby\0\"") # Bundler 1
return false if @gemspec_ruby_unlocked

dependency_files.any? { |f| f.name.end_with?(".gemspec") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,15 @@
to eq(Gem::Version.new("2.0.1"))
end

context "that isn't satisfied by the dependencies", :bundler_v2_only do
context "that isn't satisfied by the dependencies" do
let(:dependency_files) do
bundler_project_dependency_files("imports_gemspec_version_clash_old_required_ruby_no_lockfile")
end
let(:current_version) { "3.0.1" }

it "raises a DependencyFileNotResolvable error" do
expect { subject }.
to raise_error(Dependabot::DependencyFileNotResolvable)
it "ignores the minimum ruby version in the gemspec" do
expect(resolver.latest_resolvable_version_details[:version]).
to eq(Gem::Version.new("7.2.0"))
end
end
end
Expand Down