Top Level Namespace
Defined Under Namespace
Modules: CIScripts, Demo, Docker, Files, Git, Go, Ruby, RubyDig, RubyDotDig
Classes: Array, Hash
Instance Method Summary
collapse
Instance Method Details
#capture_command(*options) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/ci_scripts/helpers.rb', line 42
def capture_command(*options)
output, status = Open3.capture2(*options)
unless status.success?
log_error("Attempted to capture output of `#{options.join ' '}` but received exit code #{status.to_i}")
log_error(output)
exit status.to_i
end
output
end
|
#classify(s) ⇒ Object
88
89
90
91
92
|
# File 'lib/ci_scripts/helpers.rb', line 88
def classify(s)
s = s.to_s.split('_').collect(&:capitalize).join
s[0] = s[0].capitalize
s
end
|
#command(*options) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/ci_scripts/helpers.rb', line 24
def command(*options)
log_info(options.join(" "))
t = Time.now
system(*options)
log_success("#{(Time.now - t).round(2)}s\n ")
if $CHILD_STATUS && $CHILD_STATUS.exitstatus != 0
log_error("Exit status #{$CHILD_STATUS.exitstatus}")
exit $CHILD_STATUS.exitstatus
end
end
|
#env_check(key, value) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/ci_scripts/helpers.rb', line 63
def env_check(key, value)
unless ENV[key]
puts "Setting #{key} to #{value}"
ENV[key] = value
end
end
|
#env_fetch(key, default = nil) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/ci_scripts/helpers.rb', line 79
def env_fetch(key, default = nil)
if ENV[key]
ENV[key]
else
default
end
end
|
#env_require(key) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/ci_scripts/helpers.rb', line 70
def env_require(key)
val = ENV[key]
if val.nil? || val == ""
log_error "Required environment variable #{key} not set"
exit 1
end
val
end
|
#installed?(binary) ⇒ Boolean
58
59
60
|
# File 'lib/ci_scripts/helpers.rb', line 58
def installed?(binary)
test_command?("command", "-v", binary)
end
|
#log_error(s) ⇒ Object
14
15
16
|
# File 'lib/ci_scripts/helpers.rb', line 14
def log_error(s)
puts("\x1b[31m#{s}\x1b[0m")
end
|
#log_info(s) ⇒ Object
6
7
8
|
# File 'lib/ci_scripts/helpers.rb', line 6
def log_info(s)
puts("\x1b[34m#{s}\x1b[0m")
end
|
#log_success(s) ⇒ Object
10
11
12
|
# File 'lib/ci_scripts/helpers.rb', line 10
def log_success(s)
puts("\x1b[32m#{s}\x1b[0m")
end
|
#nice_exit(code, msg = "Something happened") ⇒ Object
18
19
20
21
|
# File 'lib/ci_scripts/helpers.rb', line 18
def nice_exit(code, msg = "Something happened")
log_error(msg)
exit code
end
|
#test_command?(*options) ⇒ Boolean
53
54
55
56
|
# File 'lib/ci_scripts/helpers.rb', line 53
def test_command?(*options)
system(*options, out: File::NULL)
$CHILD_STATUS == 0
end
|
#timed_run(name) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/ci_scripts/helpers.rb', line 35
def timed_run(name)
log_info(name)
t = Time.now
yield
log_success("#{(Time.now - t).round(2)}s\n ")
end
|
#unindent(s) ⇒ Object
94
95
96
97
|
# File 'lib/ci_scripts/helpers.rb', line 94
def unindent(s)
indent = s.split("\n").select { |line| !line.strip.empty? }.map { |line| line.index(/[^\s]/) }.compact.min || 0
s.gsub(/^[[:blank:]]{#{indent}}/, '')
end
|