class Depl::Main
Public Class Methods
new(options)
click to toggle source
# File lib/depl/main.rb, line 5 def initialize(options) config_path = options[:config_file] || "./.deploy" @config = options[:config] if File.exist? config_path @config ||= YAML::load_file(config_path) else @config ||= {} end @options = options end
Public Instance Methods
advance_branch_pointer()
click to toggle source
# File lib/depl/main.rb, line 43 def advance_branch_pointer execute("git push --follow-tags --force #{origin} #{local_sha}:refs/heads/#{deploy_branch}") end
commit_count()
click to toggle source
# File lib/depl/main.rb, line 89 def commit_count diff.split("\n").size end
deploy_branch()
click to toggle source
# File lib/depl/main.rb, line 30 def deploy_branch [prefix, environment].join('') end
diff()
click to toggle source
# File lib/depl/main.rb, line 76 def diff execute_output "git log --pretty=format:' %h %<(20)%an %ar\t %s' #{remote_sha}..#{local_sha}" end
environment()
click to toggle source
# File lib/depl/main.rb, line 18 def environment @options[:environment] end
local_sha()
click to toggle source
# File lib/depl/main.rb, line 70 def local_sha rev = @options[:rev] || @config[:branch] || 'head' sha = execute_output("git rev-parse -q --verify #{rev}") sha && sha.chomp || raise("missing local sha: #{rev}") end
older_local_sha()
click to toggle source
# File lib/depl/main.rb, line 84 def older_local_sha return false unless remote_sha !!execute_output("git merge-base --is-ancestor #{local_sha} #{remote_sha}") end
origin()
click to toggle source
# File lib/depl/main.rb, line 26 def origin @config[:origin] || "origin" end
prefix()
click to toggle source
# File lib/depl/main.rb, line 22 def prefix @config[:prefix] || "deploy-" end
remote_sha()
click to toggle source
# File lib/depl/main.rb, line 60 def remote_sha `git fetch #{origin}` sha = execute_output("git rev-parse -q --verify #{origin}/#{deploy_branch}") sha && sha.chomp || raise("missing remote sha for #{origin}/#{deploy_branch}") end
reverse_diff()
click to toggle source
# File lib/depl/main.rb, line 80 def reverse_diff execute_output "git log --pretty=format:' %h %<(20)%an %ar\t %s' #{local_sha}..#{remote_sha}" end
run!()
click to toggle source
# File lib/depl/main.rb, line 47 def run! if @config['before_hook'] `#{@config['before_hook']}` end tag_release advance_branch_pointer if @config['after_hook'] `#{@config['after_hook']}` end end
tag_name()
click to toggle source
# File lib/depl/main.rb, line 34 def tag_name date = Time.now.strftime('%Y-%m-%d-%H-%M-%S') [prefix, environment, '-', date].join('') end
tag_release()
click to toggle source
# File lib/depl/main.rb, line 39 def tag_release execute("git tag -a '#{tag_name}' #{local_sha}") end
up_to_date?()
click to toggle source
# File lib/depl/main.rb, line 66 def up_to_date? local_sha == remote_sha end
Protected Instance Methods
execute(cmd)
click to toggle source
# File lib/depl/main.rb, line 105 def execute(cmd) pid = spawn(cmd) pid, status = Process.wait2(pid) status.exitstatus == 0 end
execute_output(cmd)
click to toggle source
# File lib/depl/main.rb, line 95 def execute_output(cmd) rd, wr = IO.pipe pid = spawn(cmd, out: wr, err: wr) pid, status = Process.wait2(pid) wr.close status.exitstatus == 0 && rd.read end