Sha256: 1ef74cde1624fb14021c1a93c6218648c3fa122c6ea4702d938f20896a857d10

Contents?: true

Size: 907 Bytes

Versions: 6

Compression:

Stored size: 907 Bytes

Contents

module Shuttle
  class Hook
    def initialize(deploy)
      @deploy = deploy
    end

    def run(commands, allow_failures = false)
      [commands].flatten.compact.uniq.each do |cmd|
        if cmd =~ /^task=\s?([A-Za-z\d\_]+)\s?/
          Shuttle::Task.new(@deploy, $1.strip, allow_failures).run
        else
          execute(cmd, allow_failures)
        end
      end
    end

    private

    def execute(cmd, allow_failures)
      @deploy.log %{Executing "#{cmd.strip}"}

      command = cmd

      if @deploy.ssh.directory_exists?(@deploy.release_path)
        command = "cd #{@deploy.release_path} && #{command}"
      end

      result = @deploy.ssh.run(command)

      if result.failure? && allow_failures == false
        @deploy.error("Failed: #{result.output}")
      else
        if !result.output.empty?
          @deploy.stream_output(result.output)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shuttle-deploy-0.4.0 lib/shuttle/hook.rb
shuttle-deploy-0.3.3 lib/shuttle/hook.rb
shuttle-deploy-0.3.2 lib/shuttle/hook.rb
shuttle-deploy-0.3.1 lib/shuttle/hook.rb
shuttle-deploy-0.3.0 lib/shuttle/hook.rb
shuttle-deploy-0.3.0.beta1 lib/shuttle/hook.rb