Module: Bard::CLI::Deploy

Defined in:
lib/bard/cli/deploy.rb

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bard/cli/deploy.rb', line 5

def self.included mod
  mod.class_eval do

    option :"skip-ci", type: :boolean
    option :"local-ci", type: :boolean
    desc "deploy [TO=production]", "checks that current branch is a ff with master, checks with ci, merges into master, deploys to target, and then deletes branch."
    def deploy to=:production
      branch = Bard::Git.current_branch

      if branch == "master"
        if !Bard::Git.up_to_date_with_remote?(branch)
          run! "git push origin #{branch}:#{branch}"
        end
        invoke :ci, [branch], options.slice("local-ci") unless options["skip-ci"]

      else
        run! "git fetch origin master:master"

        unless Bard::Git.fast_forward_merge?("origin/master", branch)
          puts "The master branch has advanced. Attempting rebase..."
          run! "git rebase origin/master"
        end

        run! "git push -f origin #{branch}:#{branch}"

        invoke :ci, [branch], options.slice("local-ci") unless options["skip-ci"]

        run! "git push origin #{branch}:master"
        run! "git fetch origin master:master"
      end

      if `git remote` =~ /\bgithub\b/
        run! "git push github"
      end

      config[to].run! "git pull origin master && bin/setup"

      puts green("Deploy Succeeded")

      if branch != "master"
        puts "Deleting branch: #{branch}"
        run! "git push --delete origin #{branch}"

        if branch == Bard::Git.current_branch
          run! "git checkout master"
        end

        run! "git branch -D #{branch}"
      end

      ping to
    rescue Bard::Command::Error => e
      puts red("!!! ") + "Running command failed: #{yellow(e.message)}"
      exit 1
    end

  end
end