Skip to content

Instantly share code, notes, and snippets.

@KJTsanaktsidis
Created April 6, 2022 00:37
Show Gist options
  • Save KJTsanaktsidis/56397eb0799ec4234e2be987e4d32df1 to your computer and use it in GitHub Desktop.
Save KJTsanaktsidis/56397eb0799ec4234e2be987e4d32df1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'open3'
# rubocop:disable Lint/MissingCopEnableDirective
# rubocop:disable Style/GlobalVars
$stdout_lock = Mutex.new
$stdout.sync = true
Thread.abort_on_exception = true
# The one bit of the "colorize" gem we actually need.
class String
def cyan
"\e[0;36;49m#{self}\e[0m"
end
def green
"\e[0;32;49m#{self}\e[0m"
end
end
def bundle_install(gemfile_name, cache_path, color)
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
env = {
'BUNDLE_GEMFILE' => gemfile_name,
'BUNDLE_PATH' => cache_path,
}
# --jobs=12 seems to actually make our install times _worse_ (170s for --jobs=1, 190s for --jobs=12)
# TODO: when we upgrade to bundler 2, review if it actually helps then.
cmd = ['bundle', 'install', '--frozen', '--local', '--jobs=1', '--retry=3']
exit_status = nil
Open3.popen2e(env, *cmd) do |_stdin, stdout_and_err, wait_thr|
stdout_and_err.each_line do |ln|
$stdout_lock.synchronize do
puts format("%-14s > %s", gemfile_name, ln.strip).send(color)
end
end
exit_status = wait_thr.value
end
Process.wait Process.spawn(env, 'bundle', 'config', '--delete', 'frozen')
t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
$stdout_lock.synchronize do
puts "------------".send(color)
if exit_status&.success?
puts " Bundle install for #{gemfile_name} completed in #{t2 - t1} seconds".send(color)
else
puts " ERROR ERROR ERROR ERROR ERROR".send(color)
puts " Bundle install for #{gemfile_name} FAILED: #{exit_status.inspect}".send(color)
end
puts "------------".send(color)
end
exit_status
end
statuses = [
Thread.new { bundle_install('Gemfile', '/home/runner/vendor/bundle-50', :cyan) },
Thread.new { bundle_install('Gemfile.next', '/home/runner/vendor/bundle-51', :green) },
].map { |t| t.join.value }
# exit true means success, exit false means failure
exit statuses.all? { |s| s&.success? }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment