Top Level Namespace

Defined Under Namespace

Classes: Wait

Instance Method Summary collapse

Instance Method Details

#check_env ⇒ Object



11
12
13
# File 'lib/tasks/ci/common.rb', line 11

def check_env
  abort 'SDK_HOME env variable must be defined in your Rakefile to used this gem.' unless ENV['SDK_HOME']
end

#in_venv ⇒ Object



35
36
37
# File 'lib/tasks/ci/common.rb', line 35

def in_venv
  ENV['RUN_VENV'] && ENV['RUN_VENV'] == 'true' ? true : false
end

#install_requirements(req_file, pip_options = nil, output = nil, use_venv = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tasks/ci/common.rb', line 39

def install_requirements(req_file, pip_options = nil, output = nil, use_venv = nil)
  pip_command = use_venv ? "#{ENV['SDK_HOME']}/venv/bin/pip" : 'pip'
  redirect_output = output ? "2>&1 >> #{output}" : ''
  pip_options = '' if pip_options.nil?
  File.exist?(req_file) && File.open(req_file, 'r') do |f|
    f.each_line do |line|
      line.strip!
      unless line.empty? || line.start_with?('#')
        sh %(#{pip_command} install #{line} #{pip_options} #{redirect_output}\
             || echo 'Unable to install #{line}' #{redirect_output})
      end
    end
  end
end

#integration_tests(ci_dir) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tasks/ci/common.rb', line 60

def integration_tests(ci_dir)
  sdk_dir = File.join(ci_dir, '..')
  integrations = []
  untested = []
  testable = []
  test_files(sdk_dir).each do |check|
    integration_name = /test_((\w|_)+).py$/.match(check)[1]
    integrations.push(integration_name)
    if Dir.exist?(File.join(sdk_dir, integration_name))
      testable.push(check)
    else
      untested.push(check)
    end
  end
  [testable, untested]
end

#section(name) ⇒ Object



28
29
30
31
32
33
# File 'lib/tasks/ci/common.rb', line 28

def section(name)
  timestamp = Time.now.utc.iso8601
  puts ''
  puts "[#{timestamp}] >>>>>>>>>>>>>> #{name} STAGE".black.on_white
  puts ''
end

#sed(source, a, b, mods) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/tasks/ci/common.rb', line 15

def sed(source, a, b, mods)
  if RUBY_PLATFORM.include? 'darwin'
    sh "sed -i '' \"s/#{a}/#{b}/#{mods}\" #{source}"
  else
    sh "sed -i \"s/#{a}/#{b}/#{mods}\" #{source}"
  end
end

#sleep_for(secs) ⇒ Object



23
24
25
26
# File 'lib/tasks/ci/common.rb', line 23

def sleep_for(secs)
  puts "Sleeping for #{secs}s".blue
  sleep(secs)
end

#test_files(sdk_dir) ⇒ Object



54
55
56
57
58
# File 'lib/tasks/ci/common.rb', line 54

def test_files(sdk_dir)
  Dir.glob(File.join(sdk_dir, '**/test_*.py')).reject do |path|
    !%r{#{sdk_dir}/embedded/.*$}.match(path).nil? || !%r{#{sdk_dir}\/venv\/.*$}.match(path).nil?
  end
end