Skip to content

Commit

Permalink
Pass full version to bundler as BUNDLER_VERSION
Browse files Browse the repository at this point in the history
In a recent version of bundler, passing a major version like
`BUNDLER_VERSION=2 bundle --version` no longer works.

I suspect this may have happened here: https://github.com/rubygems/rubygems/pull/4750/files

We now need to pass the exact version of bundler we're using, which is a
bit cumbersome as you can see from the diff, and it also means we'll
have to change a few more lines every time we update a version of
bundler.

I don't think the current behavior we were relying on was documented, so
I'm not sure if we can open an issue with the Bundler team.

This seems like the most straight forward fix to me, but I am definitely
open to other suggestions
  • Loading branch information
jurre committed Aug 23, 2021
1 parent 4f58f4c commit 5a5b555
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 24 deletions.
6 changes: 3 additions & 3 deletions bundler/helpers/v1/build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ cd "$install_dir"

# NOTE: Sets `BUNDLED WITH` to match the installed v1 version in Gemfile.lock
# forcing native helpers to run with the same version
BUNDLER_VERSION=1 bundle config set --local path ".bundle"
BUNDLER_VERSION=1 bundle config set --local without "test"
BUNDLER_VERSION=1 bundle install
BUNDLER_VERSION=1.17.3 bundle config set --local path ".bundle"
BUNDLER_VERSION=1.17.3 bundle config set --local without "test"
BUNDLER_VERSION=1.17.3 bundle install
6 changes: 3 additions & 3 deletions bundler/helpers/v2/build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ cd "$install_dir"

# NOTE: Sets `BUNDLED WITH` to match the installed v2 version in Gemfile.lock
# forcing specs and native helpers to run with the same version
BUNDLER_VERSION=2 bundle config set --local path ".bundle"
BUNDLER_VERSION=2 bundle config set --local without "test"
BUNDLER_VERSION=2 bundle install
BUNDLER_VERSION=2.2.26 bundle config set --local path ".bundle"
BUNDLER_VERSION=2.2.26 bundle config set --local without "test"
BUNDLER_VERSION=2.2.26 bundle install
6 changes: 3 additions & 3 deletions bundler/lib/dependabot/bundler/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module Dependabot
module Bundler
module Helpers
V1 = "1"
V2 = "2"
V1 = "1.17.3"
V2 = "2.2.26"
# If we are updating a project with no Gemfile.lock, we default to the
# newest version we support
DEFAULT = V2
Expand All @@ -31,7 +31,7 @@ def self.detected_bundler_version(lockfile)
if (matches = lockfile.content.match(BUNDLER_MAJOR_VERSION_REGEX))
matches[:version]
else
FAILOVER
"1"
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions bundler/lib/dependabot/bundler/native_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ module Bundler
module NativeHelpers
def self.run_bundler_subprocess(function:, args:, bundler_version:)
# Run helper suprocess with all bundler-related ENV variables removed
bundler_major_version = bundler_version.split(".").first
::Bundler.with_original_env do
SharedHelpers.run_helper_subprocess(
command: helper_path(bundler_version: bundler_version),
command: helper_path(bundler_version: bundler_major_version),
function: function,
args: args,
env: {
# Bundler will pick the matching installed major version
"BUNDLER_VERSION" => bundler_version,
"BUNDLE_GEMFILE" => File.join(versioned_helper_path(bundler_version: bundler_version), "Gemfile"),
"BUNDLE_GEMFILE" => File.join(versioned_helper_path(bundler_version: bundler_major_version), "Gemfile"),
# Prevent the GEM_HOME from being set to a folder owned by root
"GEM_HOME" => File.join(versioned_helper_path(bundler_version: bundler_version), ".bundle")
"GEM_HOME" => File.join(versioned_helper_path(bundler_version: bundler_major_version), ".bundle")
}
)
rescue SharedHelpers::HelperSubprocessFailed => e
Expand Down
8 changes: 4 additions & 4 deletions bundler/script/ci-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ bundle exec rspec spec

if [[ "$SUITE_NAME" == "bundler1" ]]; then
cd helpers/v1 \
&& BUNDLER_VERSION=1 bundle install \
&& BUNDLER_VERSION=1 bundle exec rspec spec\
&& BUNDLER_VERSION=1.17.3 bundle install \
&& BUNDLER_VERSION=1.17.3 bundle exec rspec spec\
&& cd -
fi

if [[ "$SUITE_NAME" == "bundler2" ]]; then
cd helpers/v2 \
&& BUNDLER_VERSION=2 bundle install \
&& BUNDLER_VERSION=2 bundle exec rspec spec \
&& BUNDLER_VERSION=2.2.26 bundle install \
&& BUNDLER_VERSION=2.2.26 bundle exec rspec spec \
&& cd -
fi
2 changes: 1 addition & 1 deletion bundler/spec/dependabot/bundler/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@
parser.parse

expect(events.last.payload).to eq(
{ ecosystem: "bundler", package_managers: { "bundler" => PackageManagerHelper.bundler_version } }
{ ecosystem: "bundler", package_managers: { "bundler" => PackageManagerHelper.bundler_major_version } }
)
end
end
Expand Down
13 changes: 8 additions & 5 deletions bundler/spec/dependabot/bundler/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,32 @@
LOCKFILE
end

let(:v1) { "1.17.3" }
let(:v2) { "2.2.26" }

describe "#bundler_version" do
def described_method(lockfile)
described_class.bundler_version(lockfile)
end

it "is 2 if there is no lockfile" do
expect(described_method(no_lockfile)).to eql("2")
expect(described_method(no_lockfile)).to eql(v2)
end

it "is 1 if there is no bundled with string" do
expect(described_method(lockfile_bundled_with_missing)).to eql("1")
expect(described_method(lockfile_bundled_with_missing)).to eql(v1)
end

it "is 1 if it was bundled with a v1.x version" do
expect(described_method(lockfile_bundled_with_v1)).to eql("1")
expect(described_method(lockfile_bundled_with_v1)).to eql(v1)
end

it "is 2 if it was bundled with a v2.x version" do
expect(described_method(lockfile_bundled_with_v2)).to eql("2")
expect(described_method(lockfile_bundled_with_v2)).to eql(v2)
end

it "is 2 if it was bundled with a future version" do
expect(described_method(lockfile_bundled_with_future_version)).to eql("2")
expect(described_method(lockfile_bundled_with_future_version)).to eql(v2)
end
end

Expand Down
8 changes: 6 additions & 2 deletions bundler/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ def self.use_bundler_2?
end

def self.bundler_version
use_bundler_2? ? "2" : "1"
use_bundler_2? ? "2.2.26" : "1.17.3"
end

def self.bundler_major_version
bundler_version.split(".").first
end
end

def bundler_project_dependency_files(project)
project_dependency_files(File.join("bundler#{PackageManagerHelper.bundler_version}", project))
project_dependency_files(File.join("bundler#{PackageManagerHelper.bundler_major_version}", project))
end

def bundler_project_dependency_file(project, filename:)
Expand Down

0 comments on commit 5a5b555

Please sign in to comment.