Skip to content

Commit ffaeb2e

Browse files
committed
Scope to JRuby 9.2 and log error
1 parent 8ce8cac commit ffaeb2e

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

tasks/github.rake

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -356,20 +356,18 @@ namespace :github do
356356
env = { 'BUNDLE_GEMFILE' => task['gemfile'] }
357357
cmd = 'bundle check || bundle install'
358358

359-
# For JRuby 9.2, the `bundle install` command failed ocassionally with the NameError.
360-
#
361-
# Mitigate the flakiness by retrying the command up to 3 times.
362-
#
363-
# https://github.com/jruby/jruby/issues/7508
364-
# https://github.com/jruby/jruby/issues/3656
365-
retries = 0
366-
begin
359+
if RUBY_PLATFORM == 'java' && RUBY_ENGINE_VERSION.start_with?('9.2')
360+
# For JRuby 9.2, the `bundle install` command failed ocassionally with the NameError.
361+
#
362+
# Mitigate the flakiness by retrying the command up to 3 times.
363+
#
364+
# https://github.com/jruby/jruby/issues/7508
365+
# https://github.com/jruby/jruby/issues/3656
366+
with_retry do
367+
Bundler.with_unbundled_env { sh(env, cmd) }
368+
end
369+
else
367370
Bundler.with_unbundled_env { sh(env, cmd) }
368-
rescue StandardError
369-
sleep(2**retries)
370-
retries += 1
371-
retry if retries < 3
372-
raise
373371
end
374372
end
375373
end
@@ -384,5 +382,21 @@ namespace :github do
384382
Bundler.with_unbundled_env { sh(env, cmd) }
385383
end
386384
end
385+
386+
def with_retry(&block)
387+
retries = 0
388+
begin
389+
yield
390+
rescue StandardError => e
391+
rake_output_message(
392+
"Bundle install failure (Attempt: #{retries + 1}): #{e.class.name}: #{e.message}, \
393+
Source:\n#{Array(e.backtrace).join("\n")}"
394+
)
395+
sleep(2**retries)
396+
retries += 1
397+
retry if retries < 3
398+
raise
399+
end
400+
end
387401
end
388402
# rubocop:enable Metrics/BlockLength

0 commit comments

Comments
 (0)