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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/bard/cli/deploy.rb', line 7
def self.included mod
mod.class_eval do
option :"skip-ci", type: :boolean
option :"local-ci", type: :boolean
option :ci, type: :string
option :clone, type: :boolean
option :target, type: :string, default: "production"
desc "deploy [BRANCH]", "deploys branch to target (default: current branch to production)"
def deploy branch=nil
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", "ci") unless options["skip-ci"]
else
run! "git fetch origin"
if Bard::Git.current_branch != "master"
run! "git fetch origin master:master"
end
unless Bard::Git.fast_forward_merge?("origin/master", branch)
puts "The master branch has advanced. Attempting rebase..."
if branch == Bard::Git.current_branch
run! "git rebase origin/master"
else
tmpdir = Dir.mktmpdir("bard-rebase")
begin
run! "git worktree add --detach #{tmpdir} #{branch}"
success = Dir.chdir(tmpdir) { system("git rebase origin/master") }
rebased_sha = Dir.chdir(tmpdir) { `git rev-parse HEAD`.strip } if success
run! "git worktree remove #{tmpdir} --force"
unless success
puts red("!!! ") + "Rebase failed due to conflicts."
puts "Please rebase #{branch} manually:"
puts " git checkout #{branch}"
puts " git rebase origin/master"
exit 1
end
run! "git branch -f #{branch} #{rebased_sha}"
ensure
FileUtils.rm_rf(tmpdir) if Dir.exist?(tmpdir)
end
end
end
run! "git push -f origin #{branch}:#{branch}"
invoke :ci, [branch], options.slice("local-ci", "ci") unless options["skip-ci"]
run! "git push origin #{branch}:master"
if Bard::Git.current_branch != "master"
run! "git fetch origin master:master"
else
run! "git pull origin master"
end
end
if `git remote` =~ /\bgithub\b/
run! "git push github"
end
to = options[:target].to_sym
if options[:clone]
config[to].run! "git clone git@github.com:botandrosedesign/#{project_name} #{config[to].path}", home: true
invoke :master_key, [], from: "local", to: to
config[to].run! "bin/setup && bard setup"
else
target = config[to]
if target.respond_to?(:deploy_strategy) && target.deploy_strategy
require "bard/deploy_strategy/#{target.deploy_strategy}"
strategy = target.deploy_strategy_instance
strategy.deploy
elsif target.respond_to?(:github_pages) && target.github_pages
require "bard/github_pages"
Bard::GithubPages.new(self).deploy(target)
else
target.run! "git pull origin master && bin/setup"
end
end
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
|