Class: Depl::Main
- Inherits:
-
Object
- Object
- Depl::Main
- Defined in:
- lib/depl/main.rb
Instance Method Summary collapse
- #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
- #prefix ⇒ Object
- #remote_sha ⇒ Object
- #reverse_diff ⇒ Object
- #run! ⇒ Object
- #save_sha ⇒ Object
- #up_to_date ⇒ Object
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 = end |
Instance Method Details
#commit_count ⇒ Object
75 76 77 |
# File 'lib/depl/main.rb', line 75 def commit_count diff.split("\n").size end |
#deploy_branch ⇒ Object
26 27 28 |
# File 'lib/depl/main.rb', line 26 def deploy_branch "#{prefix}#{environment}" end |
#diff ⇒ Object
62 63 64 |
# File 'lib/depl/main.rb', line 62 def diff execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' -10 #{remote_sha}..#{local_sha}" end |
#environment ⇒ Object
18 19 20 |
# File 'lib/depl/main.rb', line 18 def environment [:environment] end |
#local_sha ⇒ Object
56 57 58 59 60 |
# File 'lib/depl/main.rb', line 56 def local_sha rev = [:rev] || @config[:branch] || 'head' sha = execute("git rev-parse -q --verify #{rev}").chomp sha if sha != "" end |
#older_local_sha ⇒ Object
70 71 72 73 |
# File 'lib/depl/main.rb', line 70 def older_local_sha return false unless remote_sha execute("git merge-base --is-ancestor #{local_sha} #{remote_sha}") && $?.exitstatus == 0 end |
#prefix ⇒ Object
22 23 24 |
# File 'lib/depl/main.rb', line 22 def prefix @config[:prefix] || "deploy-" end |
#remote_sha ⇒ Object
46 47 48 49 50 |
# File 'lib/depl/main.rb', line 46 def remote_sha `git fetch origin` sha = execute("git rev-parse -q --verify origin/#{deploy_branch}").chomp sha if sha != "" end |
#reverse_diff ⇒ Object
66 67 68 |
# File 'lib/depl/main.rb', line 66 def reverse_diff execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' -10 #{local_sha}..#{remote_sha}" end |
#run! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/depl/main.rb', line 34 def run! if @config['before_hook'] `#{@config['before_hook']}` end save_sha if @config['after_hook'] `#{@config['after_hook']}` end end |
#save_sha ⇒ Object
30 31 32 |
# File 'lib/depl/main.rb', line 30 def save_sha execute("git push --force origin #{local_sha}:refs/heads/#{deploy_branch}") end |
#up_to_date ⇒ Object
52 53 54 |
# File 'lib/depl/main.rb', line 52 def up_to_date local_sha == remote_sha end |