sanger/sequencescape

View on GitHub
bin/setup

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
require 'fileutils'

# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)

def system!(*args)
  system(*args) || abort("\n== Command #{args} failed ==")
end

FileUtils.chdir APP_ROOT do
  # This script is a starting point to setup your application.
  # Add necessary setup steps to this file.
  puts '== Checking basics'
  expected_version = (/[\d.]+/.match(File.read('.ruby-version')))[0]
  unless RUBY_VERSION == expected_version
    puts "Expected ruby #{expected_version} got #{RUBY_VERSION}"
    puts "Please install ruby #{expected_version}"
    puts 'You may want to install a ruby version manager'
    puts 'https://github.com/rbenv/rbenv'
  end

  puts '== Installing dependencies =='

  # Set SKIP_AUTOMATIC_GEM_INSTALLATION to disable bundle install here on the CI
  # suite as we've already done it, and this section gets a little clever.
  unless ENV['SKIP_AUTOMATIC_GEM_INSTALLATION']
    system! 'gem install bundler --conservative'

    system('bundle check') || system!('bundle install --jobs 4 --retry 3')
  end

  # Install JavaScript dependencies if using Yarn
  system('bin/yarn')

  puts "\n== Preparing database =="
  system 'bin/rails db:setup'

  puts "\n== Removing old logs and tempfiles =="
  system! 'bin/rails log:clear tmp:clear'

  puts "\n== Restarting application server =="
  system! 'bin/rails restart'
end