module Bozo # Module mixed into the all Bozo executors that provides functionality for # command execution and logging. module Runner # Returns the global parameters. attr_accessor :global_params # Returns the command parameters. attr_accessor :params # Returns the environment variables. attr_accessor :env # Returns the build configuration. attr_accessor :build_configuration # Returns whether the build is being run on a build server. def build_server? global_params[:build_server] end # Returns the environment the build is being execute in. def environment global_params[:environment] end # Executes a command line tool. # # Raises a `Bozo::ExecutionError` if the command responds with a non-zero # exit code. # # @param [Symbol] tool # A friendly identifier for the tool. # @param [Array] args # An array of arguments making up the command to execute. def execute_command(tool, args) args.flatten! executable = File.basename(args.first) arguments = args[1..-1].join(' ') puts " #{tool} - #{executable} #{arguments}".color(:cyan).bright raise Bozo::ExecutionError.new(tool, args, $?.exitstatus) unless system args.join ' ' end # Records a `debug` log message. # # @param [String] msg # The message to log. def log_debug(msg) puts " #{msg.bright.color(:black)}" end # Records a `fatal` log message. # # @param [String] msg # The message to log. def log_fatal(msg) puts msg.color(:red).bright end # Records an `info` log message. # # @param [String] msg # The message to log. def log_info(msg) puts msg.color(:cyan).bright end # Records a `warn` log message. # # @param [String] msg # The message to log. def log_warn(msg) puts msg.color(:yellow).bright end # Returns the build version. def version build_configuration.version end end end