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

ignore errors installing gems due to a gem version not allowed on the current ruby version #33

Merged
merged 1 commit into from
Mar 29, 2024
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
2 changes: 1 addition & 1 deletion lib/bundler/multilock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def write_lockfile(lockfile_definition,
Installer.install(gemfile.dirname, current_definition, {})
end
end
rescue RubyVersionMismatch, GemNotFound, SolveFailure
rescue RubyVersionMismatch, GemNotFound, SolveFailure, InstallError, ProductionError
# ignore
end
end
Expand Down
35 changes: 34 additions & 1 deletion spec/bundler/multilock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,39 @@
end
end

it "ignores installation errors when an alternate lockfile specifies a gem " \
"version incompatible with the current ruby" do
with_gemfile(<<~RUBY) do
gem "nokogiri"

lockfile do
end

lockfile "alt" do
end
RUBY
invoke_bundler("install")

incompatible_nokogiri_version = case RUBY_VERSION
when ("3.3"..)
"1.15.6"
when ("3.0"..)
skip "There isn't a recent nokogiri version incompatible " \
"with this version of ruby; just rely on this test " \
"running on other ruby versions"
else
"1.16.0"
end

replace_lockfile_pin("Gemfile.lock", "nokogiri", incompatible_nokogiri_version)
replace_lockfile_pin("Gemfile.alt.lock", "nokogiri", incompatible_nokogiri_version)

expect { invoke_bundler("check") }.to raise_error(/The following gems are missing/)

invoke_bundler("install")
end
end

private

def create_local_gem(name, content = "", subdirectory: true)
Expand Down Expand Up @@ -988,7 +1021,7 @@ def invoke_bundler(subcommand, env: {}, allow_failure: false)
# @param gem [String] The gem's name
# @param version [String] The new version to "pin" the gem to
def replace_lockfile_pin(lockfile, gem, version)
new_contents = File.read(lockfile).gsub(%r{#{gem} \([0-9.]+\)}, "#{gem} (#{version})")
new_contents = File.read(lockfile).gsub(%r{#{gem} \([0-9a-z.]+((?:-[a-z0-9_]+)*)\)}, "#{gem} (#{version}\\1)")

File.write(lockfile, new_contents)
end
Expand Down
Loading