Skip to content

Commit

Permalink
Add support for bundler's retry flag
Browse files Browse the repository at this point in the history
Close #107
  • Loading branch information
gmassanek authored and sikachu committed May 18, 2016
1 parent 18a13bc commit b6d80d6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
25 changes: 18 additions & 7 deletions lib/appraisal/appraisal.rb
Expand Up @@ -7,6 +7,8 @@
module Appraisal
# Represents one appraisal and its dependencies
class Appraisal
DEFAULT_INSTALL_OPTIONS = { "jobs" => 1 }.freeze

attr_reader :name, :gemfile

def initialize(name, source_gemfile)
Expand Down Expand Up @@ -53,11 +55,11 @@ def write_gemfile
end
end

def install(job_size = 1)
def install(options = {})
command = [
check_command,
"||",
install_command(job_size)
install_command(options)
].flatten.join(" ")

if Bundler.settings[:path]
Expand Down Expand Up @@ -101,9 +103,9 @@ def check_command
['bundle', 'check', gemfile_option]
end

def install_command(job_size)
def install_command(options = {})
gemfile_option = "--gemfile='#{gemfile_path}'"
['bundle', 'install', gemfile_option, bundle_parallel_option(job_size)].compact
['bundle', 'install', gemfile_option, bundle_options(options)].compact
end

def update_command(gems)
Expand All @@ -126,15 +128,24 @@ def clean_name
name.gsub(/[^\w\.]/, '_')
end

def bundle_parallel_option(job_size)
if job_size > 1
def bundle_options(options)
full_options = DEFAULT_INSTALL_OPTIONS.dup.merge(options)
options_strings = []
jobs = full_options.delete("jobs")
if jobs > 1
if Utils.support_parallel_installation?
"--jobs=#{job_size}"
options_strings << "--jobs=#{jobs}"
else
warn 'Your current version of Bundler does not support parallel installation. Please ' +
'upgrade Bundler to version >= 1.4.0, or invoke `appraisal` without `--jobs` option.'
end
end

full_options.each do |flag, val|
options_strings << "--#{flag} #{val}"
end

options_strings.join if options_strings != []
end
end
end
4 changes: 3 additions & 1 deletion lib/appraisal/cli.rb
Expand Up @@ -41,11 +41,13 @@ def self.exit_on_failure?
method_option 'jobs', :aliases => 'j', :type => :numeric, :default => 1,
:banner => 'SIZE',
:desc => 'Install gems in parallel using the given number of workers.'
method_option 'retry', :type => :numeric, :default => 1,
:desc => 'Retry network and git requests that have failed'
def install
invoke :generate, [], {}

AppraisalFile.each do |appraisal|
appraisal.install(options[:jobs])
appraisal.install(options)
appraisal.relativize
end
end
Expand Down
15 changes: 13 additions & 2 deletions spec/appraisal/appraisal_spec.rb
Expand Up @@ -41,7 +41,7 @@
stub_const('Bundler::VERSION', '1.3.0')

warning = capture(:stderr) do
@appraisal.install(42)
@appraisal.install("jobs" => 42)
end

expect(Appraisal::Command).to have_received(:new).
Expand All @@ -52,12 +52,19 @@
it 'runs parallel install command on Bundler >= 1.4.0' do
stub_const('Bundler::VERSION', '1.4.0')

@appraisal.install(42)
@appraisal.install("jobs" => 42)

expect(Appraisal::Command).to have_received(:new).
with("#{bundle_check_command} || #{bundle_parallel_install_command}")
end

it 'runs install command with retries on Bundler' do
@appraisal.install("retry" => 3)

expect(Appraisal::Command).to have_received(:new).
with("#{bundle_check_command} || #{bundle_install_command_with_retries}")
end

def bundle_check_command
"bundle check --gemfile='/home/test/test directory'"
end
Expand All @@ -69,5 +76,9 @@ def bundle_single_install_command
def bundle_parallel_install_command
"bundle install --gemfile='/home/test/test directory' --jobs=42"
end

def bundle_install_command_with_retries
"bundle install --gemfile='/home/test/test directory' --retry 3"
end
end
end

0 comments on commit b6d80d6

Please sign in to comment.