-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a stubbed v2 native helper that raised NYI for all functions
- Loading branch information
Showing
8 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
BUNDLE_PATH: ".bundle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/.bundle/* | ||
!/.bundle/config | ||
/.env | ||
/tmp | ||
/dependabot-*.gem | ||
Gemfile.lock | ||
spec/fixtures/projects/*/.bundle/ | ||
!spec/fixtures/projects/**/Gemfile.lock | ||
!spec/fixtures/projects/**/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
# NOTE: Used to run native helper specs | ||
group :test do | ||
gem "byebug", "11.1.3" | ||
gem "rspec", "3.10.0" | ||
gem "rspec-its", "1.3.0" | ||
gem "vcr", "6.0.0" | ||
gem "webmock", "3.12.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
install_dir=$1 | ||
if [ -z "$install_dir" ]; then | ||
echo "usage: $0 INSTALL_DIR" | ||
exit 1 | ||
fi | ||
|
||
helpers_dir="$(dirname "${BASH_SOURCE[0]}")" | ||
cp -r \ | ||
"$helpers_dir/.bundle" \ | ||
"$helpers_dir/lib" \ | ||
"$helpers_dir/monkey_patches" \ | ||
"$helpers_dir/run.rb" \ | ||
"$helpers_dir/Gemfile" \ | ||
"$install_dir" | ||
|
||
cd "$install_dir" | ||
|
||
# NOTE: Sets `BUNDLED WITH` to match the installed v1 version in Gemfile.lock | ||
# forcing specs and native helpers to run with the same version | ||
# | ||
# TODO: Change to BUNDLER_VERSION=2 once it is installed | ||
BUNDLER_VERSION=1 bundle install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module Functions | ||
class NotImplementedError < StandardError; end | ||
|
||
def self.parsed_gemfile(lockfile_name:, gemfile_name:, dir:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.parsed_gemspec(lockfile_name:, gemspec_name:, dir:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.vendor_cache_dir(dir:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.update_lockfile(dir:, gemfile_name:, lockfile_name:, using_bundler2:, | ||
credentials:, dependencies:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.force_update(dir:, dependency_name:, target_version:, gemfile_name:, | ||
lockfile_name:, using_bundler2:, credentials:, | ||
update_multiple_dependencies:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.dependency_source_type(gemfile_name:, dependency_name:, dir:, | ||
credentials:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.depencency_source_latest_git_version(gemfile_name:, dependency_name:, | ||
dir:, credentials:, | ||
dependency_source_url:, | ||
dependency_source_branch:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.private_registry_versions(gemfile_name:, dependency_name:, dir:, | ||
credentials:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.resolve_version(dependency_name:, dependency_requirements:, | ||
gemfile_name:, lockfile_name:, using_bundler2:, | ||
dir:, credentials:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.jfrog_source(dir:, gemfile_name:, credentials:, using_bundler2:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.git_specs(dir:, gemfile_name:, credentials:, using_bundler2:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.set_bundler_flags_and_credentials(dir:, credentials:, | ||
using_bundler2:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
|
||
def self.conflicting_dependencies(dir:, dependency_name:, target_version:, | ||
lockfile_name:, using_bundler2:, credentials:) | ||
raise NotImplementedError, "Bundler 2 adapter does not yet implement #{__method__}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "bundler" | ||
require "json" | ||
|
||
$LOAD_PATH.unshift(File.expand_path("./lib", __dir__)) | ||
$LOAD_PATH.unshift(File.expand_path("./monkey_patches", __dir__)) | ||
|
||
# Bundler monkey patches | ||
require "definition_ruby_version_patch" | ||
require "definition_bundler_version_patch" | ||
require "git_source_patch" | ||
|
||
require "functions" | ||
|
||
def output(obj) | ||
print JSON.dump(obj) | ||
end | ||
|
||
begin | ||
request = JSON.parse($stdin.read) | ||
|
||
function = request["function"] | ||
args = request["args"].transform_keys(&:to_sym) | ||
|
||
output({ result: Functions.send(function, **args) }) | ||
rescue => error | ||
output( | ||
{ error: error.message, error_class: error.class, trace: error.backtrace } | ||
) | ||
exit(1) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require "native_spec_helper" | ||
|
||
RSpec.describe Functions do | ||
# Verify v1 method signatures are exist, but raise as NYI | ||
{ | ||
parsed_gemfile: [ :lockfile_name, :gemfile_name, :dir ], | ||
parsed_gemspec: [ :lockfile_name, :gemspec_name, :dir ], | ||
vendor_cache_dir: [ :dir ], | ||
update_lockfile: [ :dir, :gemfile_name, :lockfile_name, :using_bundler2, :credentials, :dependencies ], | ||
force_update: [ :dir, :dependency_name, :target_version, :gemfile_name, :lockfile_name, :using_bundler2, | ||
:credentials, :update_multiple_dependencies ], | ||
dependency_source_type: [ :gemfile_name, :dependency_name, :dir, :credentials ], | ||
depencency_source_latest_git_version: [ :gemfile_name, :dependency_name, :dir, :credentials, :dependency_source_url, | ||
:dependency_source_branch ], | ||
private_registry_versions: [:gemfile_name, :dependency_name, :dir, :credentials ], | ||
resolve_version: [:dependency_name, :dependency_requirements, :gemfile_name, :lockfile_name, :using_bundler2, | ||
:dir, :credentials], | ||
jfrog_source: [:dir, :gemfile_name, :credentials, :using_bundler2], | ||
git_specs: [:dir, :gemfile_name, :credentials, :using_bundler2], | ||
set_bundler_flags_and_credentials: [:dir, :credentials, :using_bundler2], | ||
conflicting_dependencies: [:dir, :dependency_name, :target_version, :lockfile_name, :using_bundler2, :credentials] | ||
}.each do |function, kwargs| | ||
describe "::#{function}" do | ||
let(:args) do | ||
kwargs.inject({}) do |args, keyword| | ||
args.merge({ keyword => anything }) | ||
end | ||
end | ||
|
||
it "raises a NYI" do | ||
expect { Functions.send(function, **args) }.to raise_error(Functions::NotImplementedError) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rspec/its" | ||
require "webmock/rspec" | ||
require "byebug" | ||
|
||
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__)) | ||
# TODO: Fork `v1/monkey_patches` into `v2/monkey_patches` ? | ||
$LOAD_PATH.unshift(File.expand_path("../../v1/monkey_patches", __dir__)) | ||
|
||
# Bundler monkey patches | ||
require "definition_ruby_version_patch" | ||
require "definition_bundler_version_patch" | ||
require "git_source_patch" | ||
|
||
require "functions" | ||
|
||
RSpec.configure do |config| | ||
config.color = true | ||
config.order = :rand | ||
config.mock_with(:rspec) { |mocks| mocks.verify_partial_doubles = true } | ||
config.raise_errors_for_deprecations! | ||
end | ||
|
||
# Duplicated in lib/dependabot/bundler/file_updater/lockfile_updater.rb | ||
# TODO: Stop sanitizing the lockfile once we have bundler 2 installed | ||
LOCKFILE_ENDING = /(?<ending>\s*(?:RUBY VERSION|BUNDLED WITH).*)/m.freeze | ||
|
||
def project_dependency_files(project) | ||
project_path = File.expand_path(File.join("../../spec/fixtures/projects/bundler1", project)) | ||
Dir.chdir(project_path) do | ||
# NOTE: Include dotfiles (e.g. .npmrc) | ||
files = Dir.glob("**/*", File::FNM_DOTMATCH) | ||
files = files.select { |f| File.file?(f) } | ||
files.map do |filename| | ||
content = File.read(filename) | ||
if filename == "Gemfile.lock" | ||
content = content.gsub(LOCKFILE_ENDING, "") | ||
end | ||
{ | ||
name: filename, | ||
content: content | ||
} | ||
end | ||
end | ||
end | ||
|
||
def fixture(*name) | ||
File.read(File.join("../../spec/fixtures", File.join(*name))) | ||
end |