Top Level Namespace

Defined Under Namespace

Modules: Geordi Classes: Gitpt, PngOptimizer

Instance Method Summary collapse

Instance Method Details

#_setup_vncObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/geordi/commands/_setup_vnc.rb', line 2

def _setup_vnc
  `clear`

  Interaction.note 'This script will help you install a VNC server and a VNC viewer.'
  puts
  puts Util.strip_heredoc <<-TEXT
    With those you will be able to use our cucumber script without being
    disturbed by focus-stealing Selenium windows. Instead, they will open
    inside a VNC session.

    You can still inspect everything with:
  TEXT
  Interaction.note_cmd 'geordi vnc'
  puts
  Interaction.note 'Please open a second shell to execute instructions.'
  Interaction.prompt 'Continue ...'

  Interaction.announce 'Setup VNC server'

  vnc_server_installed = system('which vncserver > /dev/null 2>&1')
  if vnc_server_installed
    Interaction.success 'It appears you already have a VNC server installed. Good job!'
  else
    puts 'Please run:'
    Interaction.note_cmd 'sudo apt-get install vnc4server'
    Interaction.prompt 'Continue ...'

    puts
    Interaction.note 'We will now set a password for your VNC server.'
    puts Util.strip_heredoc <<-TEXT
      When running our cucumber script, you will not actually need this
      password, and there is no security risk. However, if you start a vncserver
      without our cucumber script, a user with your password can connect to
      your machine.

    TEXT
    puts 'Please run:'
    Interaction.note_cmd 'vncserver :20'
    Interaction.warn 'Enter a secure password!'
    Interaction.prompt 'Continue ...'

    puts 'Now stop the server again. Please run:'
    Interaction.note_cmd 'vncserver -kill :20'
    Interaction.prompt 'Continue ...'
  end

  Interaction.announce 'Setup VNC viewer'

  vnc_viewer_installed = system('which vncviewer > /dev/null 2>&1')
  if vnc_viewer_installed
    Interaction.success 'It appears you already have a VNC viewer installed. Good job!'
  else
    puts 'Please run:'
    Interaction.note_cmd 'sudo apt-get install xtightvncviewer'
    Interaction.prompt 'Continue ...'
  end

  puts
  puts Util.strip_heredoc <<-TEXT
    All done. Our cucumber script will now automatically run Selenium features
    in VNC.
  TEXT

  Interaction.success 'Happy cuking!'
end

#apache_site(*args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/geordi/commands/apache_site.rb', line 2

def apache_site(*args)
  site = args.shift
  old_cwd = Dir.pwd
  Dir.chdir '/etc/apache2/sites-available/'

  # show available sites if no site was passed as argument
  unless site
    puts 'ERROR: Argument site is missing.'
    puts 'Please call: apache-site my-site'
    puts
    puts 'Available sites:'
    Dir.new('.').each do |file|
      puts "- #{file}" if file != '.' && file != '..'
    end
    exit
  end

  has_default = File.exist?('default')
  exec "sudo a2dissite \*; sudo a2ensite #{'default ' if has_default}#{site} && sudo apache2ctl restart"
  Dir.chdir old_cwd
end

#bundle_installObject



2
3
4
5
6
7
# File 'lib/geordi/commands/bundle_install.rb', line 2

def bundle_install
  if File.exist?('Gemfile') && !system('bundle check > /dev/null 2>&1')
    Interaction.announce 'Bundling'
    Util.system! 'bundle install'
  end
end

#capistrano(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/geordi/commands/capistrano.rb', line 6

def capistrano(*args)
  targets = Dir['config/deploy/*.rb'].map { |file| File.basename(file, '.rb') }.sort

  Interaction.note 'Found the following deploy targets:'
  puts targets
  Interaction.prompt('Continue?', 'n', /y|yes/) || Interaction.fail('Cancelled.')

  targets << nil if targets.empty? # default target
  targets.each do |stage|
    Interaction.announce 'Target: ' + (stage || '(default)')

    command = "bundle exec cap #{stage} " + args.join(' ')
    Interaction.note_cmd command

    Util.system!(command, fail_message: 'Capistrano failed. Have a look!')
  end
end

#chromedriver_updateObject



9
10
11
12
13
# File 'lib/geordi/commands/chromedriver_update.rb', line 9

def chromedriver_update
  require 'geordi/chromedriver_updater'

  ChromedriverUpdater.new.run
end

#cleanObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/geordi/commands/clean.rb', line 2

def clean

  Interaction.announce 'Removing tempfiles'
  for pattern in %w[ webrat-* capybara-* tmp/webrat-* tmp/capybara-* tmp/rtex/* log/*.log ]
    Interaction.note pattern
    puts `rm -vfR #{pattern}`
  end

  Interaction.announce 'Finding recursively and removing backup files'
  %w[*~].each do |pattern|
    Interaction.note pattern
    `find . -name #{pattern} -exec rm {} ';'`
  end
end

#commit(*git_args) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/geordi/commands/commit.rb', line 15

def commit(*git_args)
  raise <<-TEXT if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1')
Unsupported Ruby Version #{RUBY_VERSION}. `geordi commit` requires Ruby 2.1+.
  TEXT

  require 'geordi/gitpt'

  Gitpt.new.run(git_args)
end

#console(target = 'development', *_args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/geordi/commands/console.rb', line 11

def console(target = 'development', *_args)
  require 'geordi/remote'

  if target == 'development'
    invoke_cmd 'yarn_install'

    Interaction.announce 'Opening a local Rails console'

    Util.system! Util.console_command(target)
  else
    Interaction.announce 'Opening a Rails console on ' + target

    Geordi::Remote.new(target).console(options)
  end
end

#create_database_ymlObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/geordi/commands/create_database_yml.rb', line 2

def create_database_yml
  real_yml = 'config/database.yml'
  sample_yml = 'config/database.sample.yml'

  if File.exist?(sample_yml) && !File.exist?(real_yml)
    Interaction.announce 'Creating ' + real_yml

    sample = File.read(sample_yml)
    adapter = sample.match(/adapter: (\w+)\n/).captures.first

    print "Please enter your #{adapter} password: "
    db_password = STDIN.gets.strip

    real = sample.gsub(/password:.*$/, "password: #{db_password}")
    File.open(real_yml, 'w') { |f| f.write(real) }

    Interaction.note "Created #{real_yml}."
  end
end

#create_databasesObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/geordi/commands/create_databases.rb', line 2

def create_databases
  invoke_cmd 'create_database_yml'
  invoke_cmd 'bundle_install'

  Interaction.announce 'Creating databases'

  if File.exist?('config/database.yml')
    command = 'bundle exec rake db:create:all'
    command << ' parallel:create' if Util.file_containing?('Gemfile', /parallel_tests/)

    Util.system! command
  else
    puts 'config/database.yml does not exist. Nothing to do.'
  end
end

#cucumber(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/geordi/commands/cucumber.rb', line 31

def cucumber(*args)
  if args.empty?
    # This is not testable as there is no way to stub `git` :(
    if options.modified?
      modified_features = `git status --short`.split($INPUT_RECORD_SEPARATOR).map do |line|
        indicators = line.slice!(0..2) # Remove leading indicators
        line if line.include?('.feature') && !indicators.include?('D')
      end.compact
      args = modified_features
    end

    if options.containing
      matching_features = `grep -lri '#{options.containing}' --include=*.feature features/`.split($INPUT_RECORD_SEPARATOR)
      args = matching_features.uniq
    end
  end

  if File.directory?('features')
    require 'geordi/cucumber'

    invoke_cmd 'bundle_install'
    invoke_cmd 'yarn_install'

    cmd_opts, files = args.partition { |f| f.start_with? '-' }
    cmd_opts << '--format' << 'pretty' << '--backtrace' if options.debug

    # Serial run of @solo scenarios ############################################
    if files.any? { |f| f.include? ':' }
      Interaction.note '@solo run skipped when called with line numbers' if options.verbose
    else
      solo_files = if files.empty?
        'features' # Proper grepping
      else
        files.join(' ')
      end

      solo_tag_usages = `grep -r '@solo' #{solo_files}`.split("\n")

      if solo_tag_usages.any?
        solo_cmd_opts = cmd_opts.dup
        solo_cmd_opts << '--tags' << '@solo'

        Interaction.announce 'Running @solo features'
        solo_success = Geordi::Cucumber.new.run files, solo_cmd_opts, verbose: options.verbose, parallel: false
        solo_success || Interaction.fail('Features failed.')
      end
    end

    # Parallel run of all given features + reruns ##############################
    Interaction.announce 'Running features'
    normal_run_successful = Geordi::Cucumber.new.run(files, cmd_opts, verbose: options.verbose)

    unless normal_run_successful
      cmd_opts << '--profile' << 'rerun'

      # Reruns
      (options.rerun + 1).times do |i|
        Interaction.fail 'Features failed.' if i == options.rerun # All reruns done?

        Interaction.announce "Rerun ##{i + 1} of #{options.rerun}"
        break if Geordi::Cucumber.new.run([], cmd_opts, verbose: options.verbose, parallel: false)
      end
    end

    Interaction.success 'Features green.'

  else
    Interaction.note 'Cucumber not employed.'
  end
end

#delete_dumps(dump_directory = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/geordi/commands/delete_dumps.rb', line 13

def delete_dumps(dump_directory = nil)
  deletable_dumps = []
  dump_directories = if dump_directory.nil?
    [
      File.join(Dir.home, 'dumps'),
      Dir.pwd,
    ]
  else
    [dump_directory]
  end
  Interaction.announce 'Looking for *.dump in ' << dump_directories.join(',')
  dump_directories.each do |d|
    d_2 = File.expand_path(d)
    unless File.directory? File.realdirpath(d_2)
      Interaction.warn "Directory #{d_2} does not exist"
      next
    end
    deletable_dumps.concat(Dir.glob("#{d_2}/**/*.dump"))
  end
  if deletable_dumps.empty?
    Interaction.success 'No dumps to delete' if deletable_dumps.empty?
    exit 0
  end
  deletable_dumps.uniq!.sort!
  Interaction.note 'The following dumps can be deleted:'
  puts
  puts deletable_dumps
  Interaction.prompt('Delete those dumps', 'n', /y|yes/) || raise('Cancelled.')
  deletable_dumps.each do |dump|
    File.delete dump unless File.directory? dump
  end
end

#deploy(target_stage = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/geordi/commands/deploy.rb', line 38

def deploy(target_stage = nil)
  # Set/Infer default values
  branch_stage_map = { 'master' => 'staging', 'production' => 'production' }
  if target_stage && !Util.deploy_targets.include?(target_stage)
    # Target stage autocompletion from available stages
    target_stage = Util.deploy_targets.find { |t| t.start_with? target_stage }
    target_stage || Interaction.warn('Given deployment stage not found')
  end

  # Ask for required information
  target_stage ||= Interaction.prompt 'Deployment stage:', branch_stage_map.fetch(Util.current_branch, 'staging')
  if options.current_branch
    stage_file = "config/deploy/#{target_stage}.rb"
    Util.file_containing?(stage_file, 'DEPLOY_BRANCH') || Interaction.fail(<<-ERROR)
To deploy from the current branch, configure #{stage_file} to respect the
environment variable DEPLOY_BRANCH. Example:

set :branch, ENV['DEPLOY_BRANCH'] || 'master'
    ERROR

    source_branch = target_branch = Util.current_branch
  else
    source_branch = Interaction.prompt 'Source branch:', Util.current_branch
    target_branch = Interaction.prompt 'Deploy branch:', branch_stage_map.invert.fetch(target_stage, 'master')
  end

  merge_needed = (source_branch != target_branch)
  push_needed = merge_needed || `git cherry -v | wc -l`.strip.to_i > 0
  push_needed = false if Util.testing? # Hard to test

  Interaction.announce "Checking whether your #{source_branch} branch is ready" ############
  Util.system! "git checkout #{source_branch}"
  if (`git status -s | wc -l`.strip != '0') && !Util.testing?
    Interaction.warn "Your #{source_branch} branch holds uncommitted changes."
    Interaction.prompt('Continue anyway?', 'n', /y|yes/) || raise('Cancelled.')
  else
    Interaction.note 'All good.'
  end

  if merge_needed
    Interaction.announce "Checking what's in your #{target_branch} branch right now" #######
    Util.system! "git checkout #{target_branch} && git pull"
  end

  Interaction.announce 'You are about to:' #################################################
  Interaction.note "Merge branch #{source_branch} into #{target_branch}" if merge_needed
  if push_needed
    Interaction.note 'Push these commits:' if push_needed
    Util.system! "git --no-pager log origin/#{target_branch}..#{source_branch} --oneline"
  end
  Interaction.note "Deploy to #{target_stage}"
  Interaction.note "From current branch #{source_branch}" if options.current_branch

  if Interaction.prompt('Go ahead with the deployment?', 'n', /y|yes/)
    puts
    git_call = []
    git_call << "git merge #{source_branch}" if merge_needed
    git_call << 'git push' if push_needed

    capistrano_call = "cap #{target_stage} deploy"
    capistrano_call << ':migrations' unless Util.gem_major_version('capistrano') == 3 || options.no_migrations
    capistrano_call = "bundle exec #{capistrano_call}" if Util.file_containing?('Gemfile', /capistrano/)
    capistrano_call = "DEPLOY_BRANCH=#{source_branch} #{capistrano_call}" if options.current_branch

    if git_call.any?
      Util.system! git_call.join(' && '), show_cmd: true
    end

    invoke_cmd 'bundle_install'

    Util.system! capistrano_call, show_cmd: true

    Interaction.success 'Deployment complete.'
  else
    Util.system! "git checkout #{source_branch}"
    Interaction.fail 'Deployment cancelled.'
  end
end

#drop_databasesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/geordi/commands/drop_databases.rb', line 29

def drop_databases
  require 'geordi/db_cleaner'
  Interaction.fail '-P and -M are mutually exclusive' if options.postgres_only && options.mysql_only
  mysql_flags = nil
  postgres_flags = nil

  unless options.mysql.nil?
    begin
      mysql_port = Integer(options.mysql)
      mysql_flags = "--port=#{mysql_port} --protocol=TCP"
    rescue AttributeError
      unless File.exist? options.mysql
        Interaction.fail "Path #{options.mysql} is not a valid MySQL socket"
      end
      mysql_flags = "--socket=#{options.mysql}"
    end
  end

  unless options.postgres.nil?
    postgres_flags = "--port=#{options.postgres}"
  end

  extra_flags = { 'mysql' => mysql_flags,
                 'postgres' => postgres_flags }
  cleaner = DBCleaner.new(extra_flags)
  cleaner.clean_mysql unless options.postgres_only
  cleaner.clean_postgres unless options.mysql_only

  Interaction.success 'Done.'
end

#dump(target = nil, *_args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/geordi/commands/dump.rb', line 26

def dump(target = nil, *_args)
  require 'geordi/dump_loader'
  require 'geordi/remote'

  if target.nil?
    if options.load
      # validate load option
      Interaction.fail 'Missing a dump file.' if options.load == 'load'
      File.exist?(options.load) || raise('Could not find the given dump file: ' + options.load)

      loader = DumpLoader.new(options.load)

      Interaction.announce "Sourcing dump into the #{loader.config['database']} db"
      loader.load

      Interaction.success "Your #{loader.config['database']} database has now the data of #{options.load}."

    else
      Interaction.announce 'Dumping the development database'
      Util.system! 'dumple development'
      Interaction.success 'Successfully dumped the development database.'
    end

  else
    Interaction.announce 'Dumping the database of ' + target
    dump_path = Geordi::Remote.new(target).dump(options)

    if options.load
      loader = DumpLoader.new(dump_path)

      Interaction.announce "Sourcing dump into the #{loader.config['database']} db"
      loader.load

      Interaction.success "Your #{loader.config['database']} database has now the data of #{target}."
    end
  end
end

#eurestObject



2
3
4
# File 'lib/geordi/commands/eurest.rb', line 2

def eurest
  Util.system! %(file="Speiseplan_KW`date +%V`.pdf" && wget -O/tmp/$file http://www.eurest-extranet.de/eurest/export/sites/default/sigma-technopark/de/downloads/$file && xdg-open /tmp/$file)
end

#firefox(*command) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/geordi/commands/firefox.rb', line 16

def firefox(*command)
  if options.setup
    Interaction.fail 'Firefox version required (e.g. --setup 24.0)' if options.setup == 'setup'

    require 'geordi/firefox_for_selenium'
    Geordi::FirefoxForSelenium.install(options.setup)

  else
    require 'geordi/cucumber'

    Cucumber.new.setup_vnc
    FirefoxForSelenium.setup_firefox

    puts
    Interaction.note_cmd command.join(' ')
    system *command # Util.system! would reset the Firefox PATH
  end
end

#migrateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/geordi/commands/migrate.rb', line 10

def migrate
  invoke_cmd 'bundle_install'
  invoke_cmd 'yarn_install'
  Interaction.announce 'Migrating'

  if File.directory?('db/migrate')
    if Util.file_containing?('Gemfile', /parallel_tests/)
      Interaction.note 'Development and parallel test databases'
      puts

      Util.system! 'bundle exec rake db:migrate parallel:prepare'
    else
      invoke_cmd 'rake', 'db:migrate'
    end
  else
    Interaction.note 'No migrations directory found.'
  end
end

#png_optimize(path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/geordi/commands/png_optimize.rb', line 10

def png_optimize(path)
  require 'fileutils'

  Interaction.announce 'Optimizing .png files'

  if `which pngcrush`.strip.empty?
    Interaction.fail 'Please install pngcrush first (sudo apt-get install pngcrush)'
  end

  po = PngOptimizer.new
  if File.directory?(path)
    po.batch_optimize_inplace(path)
  elsif File.file?(path)
    po.optimize_inplace(path)
  else
    Interaction.fail 'Neither directory nor file: ' + path
  end

  Interaction.success 'PNG optimization completed.'
end

#rake(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/geordi/commands/rake.rb', line 12

def rake(*args)
  %w[development test cucumber].each do |env| # update long_desc when changing this
    if File.exist? "config/environments/#{env}.rb"
      call = %w[bundle exec rake] + args + ["RAILS_ENV=#{env}"]
      Interaction.note_cmd call.join(' ')

      Util.system! *call
    end
  end
end

#remove_executable_flagsObject



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/geordi/commands/remove_executable_flags.rb', line 2

def remove_executable_flags
  Interaction.announce 'Removing executable-flags'

  patterns = %w[
    *.rb *.html *.erb *.haml *.yml *.css *.sass *.rake *.png *.jpg
    *.gif *.pdf *.txt *.rdoc *.feature Rakefile VERSION README Capfile
  ]
  patterns.each do |pattern|
    Interaction.note pattern
    `find . -name "#{pattern}" -exec chmod -x {} ';'`
  end
  puts 'Done.'
end

#rspec(*files) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/geordi/commands/rspec.rb', line 9

def rspec(*files)
  if File.exist?('spec/spec_helper.rb')
    invoke_cmd 'bundle_install'
    invoke_cmd 'yarn_install'

    Interaction.announce 'Running specs'

    if Util.file_containing?('Gemfile', /parallel_tests/) && files.empty?
      Interaction.note 'All specs at once (using parallel_tests)'
      Util.system! 'bundle exec rake parallel:spec', fail_message: 'Specs failed.'

    else
      # tell which specs will be run
      if files.empty?
        files << 'spec/'
        Interaction.note 'All specs in spec/'
      else
        Interaction.note 'Only: ' + files.join(', ')
      end

      command = ['bundle exec']
      command << if File.exist?('script/spec')
        'spec -c' # RSpec 1
      elsif File.exist?('bin/rspec')
        'bin/rspec'
      else
        'rspec'
      end
      command << '-r rspec_spinner -f RspecSpinner::Bar' if Util.file_containing?('Gemfile', /rspec_spinner/)
      command << files.join(' ')

      puts
      Util.system! command.join(' '), fail_message: 'Specs failed.'
    end
  else
    Interaction.note 'RSpec not employed.'
  end
end

#security_update(step = 'prepare') ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/geordi/commands/security_update.rb', line 11

def security_update(step = 'prepare')
  case step
  when 'prepare'
    Interaction.announce 'Preparing for security update'
    Interaction.warn 'Please read https://makandracards.com/makandra/1587 before applying security updates!'
    Interaction.note 'About to checkout production and pull'
    Interaction.prompt('Continue?', 'y', /y|yes/) || Interaction.fail('Cancelled.')

    Util.system! 'git checkout production', show_cmd: true
    Util.system! 'git pull', show_cmd: true

    Interaction.success 'Successfully prepared for security update'
    puts
    Interaction.note 'Please apply the security update now and commit your changes.'
    Interaction.note 'When you are done, run `geordi security-update finish`.'


  when 'f', 'finish'
    # ensure everything is committed
    `git status --porcelain`.empty? || Interaction.fail('Please commit your changes before finishing the update.')

    Interaction.announce 'Finishing security update'
    Interaction.note 'Working directory clean.'
    Interaction.prompt('Have you successfully run all tests?', 'n', /y|yes/) || Interaction.fail('Please run tests first.')

    Interaction.note 'About to: push production, checkout & pull master, merge production, push master'
    Interaction.prompt('Continue?', 'n', /y|yes/) || Interaction.fail('Cancelled.')

    Util.system! 'git push', show_cmd: true
    Util.system! 'git checkout master', show_cmd: true
    Util.system! 'git pull', show_cmd: true
    Util.system! 'git merge production', show_cmd: true
    Util.system! 'git push', show_cmd: true

    Interaction.announce 'Deploying all targets'
    deploy = (Util.gem_major_version('capistrano') == 3) ? 'deploy' : 'deploy:migrations'
    invoke_cmd 'capistrano', deploy

    Interaction.success 'Successfully pushed and deployed security update'
    puts
    Interaction.note 'Now send an email to customer and project lead, informing them about the update.'
    Interaction.note 'Do not forget to make a joblog on a security budget, if available.'
  end
end

#server(port = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/geordi/commands/server.rb', line 8

def server(port = nil)
  invoke_cmd 'bundle_install'
  invoke_cmd 'yarn_install'
  require 'geordi/util'

  Interaction.announce 'Booting a development server'
  port ||= options.port
  Interaction.note "URL: http://#{File.basename(Dir.pwd)}.vcap.me:#{port}"
  puts

  command = Util.server_command
  command << ' -b 0.0.0.0' if options.public
  command << ' -p ' << port
  Util.system! command
end

#setupObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/geordi/commands/setup.rb', line 26

def setup
  if File.exist? 'bin/setup'
    Interaction.announce 'Running bin/setup'
    Interaction.note "Geordi's own setup routine is skipped"

    Util.system! 'bin/setup'
  else
    invoke_cmd 'create_databases'
    invoke_cmd 'migrate'
  end

  Interaction.success 'Successfully set up the project.'

  invoke_cmd 'dump', options.dump, load: true if options.dump
  invoke_cmd 'tests' if options.test
end

#shelll(target, *_args) ⇒ Object

This method has a triple ‘l’ because :shell is a Thor reserved word. However, it can still be called with ‘geordi shell` :)



14
15
16
17
18
19
# File 'lib/geordi/commands/shell.rb', line 14

def shelll(target, *_args)
  require 'geordi/remote'

  Interaction.announce 'Opening a shell on ' + target
  Geordi::Remote.new(target).shell(options)
end

#testsObject



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/geordi/commands/tests.rb', line 2

def tests
  rake_result = invoke_cmd 'with_rake'

  # Since `rake` usually is configured to run all tests, only run them if `rake`
  # did not perform
  if rake_result == :did_not_perform
    invoke_cmd 'unit'
    invoke_cmd 'rspec'
    invoke_cmd 'cucumber'
  end

  Interaction.success 'Successfully ran tests.'
end

#unitObject



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/geordi/commands/unit.rb', line 2

def unit
  if File.exist?('test/test_helper.rb')
    invoke_cmd 'bundle_install'
    invoke_cmd 'yarn_install'

    Interaction.announce 'Running Test::Unit'
    Util.system! 'bundle exec rake test'
  else
    Interaction.note 'Test::Unit not employed.'
  end
end

#updateObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/geordi/commands/update.rb', line 23

def update
  Interaction.announce 'Updating repository'
  Util.system! 'git pull', show_cmd: true

  invoke_cmd 'migrate'

  Interaction.success 'Successfully updated the project.'

  invoke_cmd 'dump', options.dump, load: true if options.dump
  invoke_cmd 'tests' if options.test
end

#versionObject



2
3
4
5
# File 'lib/geordi/commands/version.rb', line 2

def version
  require 'geordi/version'
  puts 'Geordi ' + Geordi::VERSION
end

#vncObject



13
14
15
16
17
18
19
20
# File 'lib/geordi/commands/vnc.rb', line 13

def vnc
  if options.setup
    invoke_cmd :_setup_vnc
  else
    require 'geordi/cucumber'
    Geordi::Cucumber.new.launch_vnc_viewer
  end
end

#with_rakeObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/geordi/commands/with_rake.rb', line 2

def with_rake
  if Util.file_containing?('Rakefile', /^task.+default.+(spec|test|feature)/)
    invoke_cmd 'bundle_install'
    invoke_cmd 'yarn_install'

    Interaction.announce 'Running tests with `rake`'
    Util.system! 'rake'
  else
    Interaction.note '`rake` does not run tests.'
    :did_not_perform
  end
end

#yarn_installObject



3
4
5
6
7
8
# File 'lib/geordi/commands/yarn_install.rb', line 3

def yarn_install
  if File.exist?('package.json') && !system('yarn check --integrity > /dev/null 2>&1')
    Interaction.announce 'Yarn install'
    Util.system! 'yarn install'
  end
end