class Trent
Communicate with all of the Trent
library with this class.
Public Class Methods
new(params = {})
click to toggle source
Initialize Trent
instance. color - Color of shell output you want Trent
to use. local - Run Trent
locally on your own machine instead of a CI server.
# File lib/trent.rb, line 16 def initialize(params = {}) running_local = params.fetch(:local, false) Log.fatal('Trent is designed to run on Travis-CI builds. Run it on Travis-CI.') unless TravisCI.running_on_travis? || running_local @color = params.fetch(:color, :blue) @sh = Sh.new @paths = {} end
Public Instance Methods
config_github(api_key)
click to toggle source
Configure how to communicate with GitHub
# File lib/trent.rb, line 32 def config_github(api_key) @github = GitHub.new(api_key) end
config_ssh(username, host, options = nil)
click to toggle source
Configure how to run remote SSH
commmands on server.
# File lib/trent.rb, line 27 def config_ssh(username, host, options = nil) @ssh = SSH.new(username, host, options) end
config_travis(api_key, private_repo)
click to toggle source
Configure how to communicate with Travis
# File lib/trent.rb, line 37 def config_travis(api_key, private_repo) @travis = TravisCI.new(api_key: api_key, private_repo: private_repo) end
github()
click to toggle source
path(command, path)
click to toggle source
While working with bash commands, some commands are not added to the path. That's annoying. Convenient method to assign a command to a path for replacing. Example: ci.path(“docker-compose”, “/opt/bin/docker-compose”) Now, when you use ci.sh(“docker-compose -f … up -d”), it will run “/opt/bin/docker-compose -f … up -d” instead.
# File lib/trent.rb, line 46 def path(command, path) @paths[command] = path end
sh(command, fail_non_success: true)
click to toggle source
Run local bash command
# File lib/trent.rb, line 64 def sh(command, fail_non_success: true) command = Command.path_replace(command, @paths) puts command.colorize(@color) result = @sh.run(command) process_shell_result(result, fail_non_success) result end
ssh(command, fail_non_success: true)
click to toggle source
Run ssh command
# File lib/trent.rb, line 51 def ssh(command, fail_non_success: true) command = Command.path_replace(command, @paths) Log.fatal('You did not configure SSH yet.') unless @ssh puts command.colorize(@color) result = @ssh.run(command) process_shell_result(result, fail_non_success) result end
Private Instance Methods
process_shell_result(result, fail_non_success)
click to toggle source
# File lib/trent.rb, line 88 def process_shell_result(result, fail_non_success) return if result[:result] if fail_non_success Log.fatal('Command failed with a non 0 exit status.') else Log.warning('Command failed with a non 0 exit status.') end end