Class: Depl::Main
- Inherits:
-
Object
- Object
- Depl::Main
- Defined in:
- lib/depl/main.rb
Instance Method Summary collapse
- #advance_branch_pointer ⇒ Object
- #commit_count ⇒ Object
- #deploy_branch ⇒ Object
- #diff ⇒ Object
- #environment ⇒ Object
-
#initialize(options) ⇒ Main
constructor
A new instance of Main.
- #local_sha ⇒ Object
- #older_local_sha ⇒ Object
- #origin ⇒ Object
- #prefix ⇒ Object
- #remote_sha ⇒ Object
- #reverse_diff ⇒ Object
- #run! ⇒ Object
- #tag_name ⇒ Object
- #tag_release ⇒ Object
- #up_to_date? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Main
Returns a new instance of Main.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/depl/main.rb', line 5 def initialize() config_path = [:config_file] || "./.deploy" @config = [:config] if File.exist? config_path @config ||= YAML::load_file(config_path) else @config ||= {} end @options = end |
Instance Method Details
#advance_branch_pointer ⇒ Object
43 44 45 |
# 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 ⇒ Object
89 90 91 |
# File 'lib/depl/main.rb', line 89 def commit_count diff.split("\n").size end |
#deploy_branch ⇒ Object
30 31 32 |
# File 'lib/depl/main.rb', line 30 def deploy_branch [prefix, environment].join('') end |
#diff ⇒ Object
76 77 78 |
# File 'lib/depl/main.rb', line 76 def diff execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' #{remote_sha}..#{local_sha}" end |
#environment ⇒ Object
18 19 20 |
# File 'lib/depl/main.rb', line 18 def environment @options[:environment] end |
#local_sha ⇒ Object
70 71 72 73 74 |
# File 'lib/depl/main.rb', line 70 def local_sha rev = @options[:rev] || @config[:branch] || 'head' sha = execute("git rev-parse -q --verify #{rev}") sha && sha.chomp || raise("missing local sha: #{rev}") end |
#older_local_sha ⇒ Object
84 85 86 87 |
# File 'lib/depl/main.rb', line 84 def older_local_sha return false unless remote_sha !!execute("git merge-base --is-ancestor #{local_sha} #{remote_sha}") end |
#origin ⇒ Object
26 27 28 |
# File 'lib/depl/main.rb', line 26 def origin @config[:origin] || "origin" end |
#prefix ⇒ Object
22 23 24 |
# File 'lib/depl/main.rb', line 22 def prefix @config[:prefix] || "deploy-" end |
#remote_sha ⇒ Object
60 61 62 63 64 |
# File 'lib/depl/main.rb', line 60 def remote_sha `git fetch #{origin}` sha = execute("git rev-parse -q --verify #{origin}/#{deploy_branch}") sha && sha.chomp || raise("missing remote sha for #{origin}/#{deploy_branch}") end |
#reverse_diff ⇒ Object
80 81 82 |
# File 'lib/depl/main.rb', line 80 def reverse_diff execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' #{local_sha}..#{remote_sha}" end |
#run! ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
34 35 36 37 |
# 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 ⇒ Object
39 40 41 |
# File 'lib/depl/main.rb', line 39 def tag_release execute("git tag -a '#{tag_name}' #{local_sha}") end |
#up_to_date? ⇒ Boolean
66 67 68 |
# File 'lib/depl/main.rb', line 66 def up_to_date? local_sha == remote_sha end |