heroku_san 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.rdoc +5 -1
  2. data/VERSION +1 -1
  3. data/lib/heroku_san/tasks.rb +74 -38
  4. metadata +4 -4
data/README.rdoc CHANGED
@@ -67,7 +67,8 @@ A full list of tasks provided:
67
67
 
68
68
  rake all # Select all Heroku apps for later command
69
69
  rake console # Opens a remote console
70
- rake deploy # Deploys, migrates and restarts latest code.
70
+ rake deploy[commit] # Pushes the given commit, migrates and restarts (default: HEAD)
71
+ rake deploy:force[commit] # Force-pushes the given commit, migrates and restarts (default: HEAD)
71
72
  rake after_deploy # Callback after deploys
72
73
  rake before_deploy # Callback before deploys
73
74
  rake capture # Captures a bundle on Heroku
@@ -75,8 +76,11 @@ A full list of tasks provided:
75
76
  rake heroku:create # Creates the Heroku app
76
77
  rake heroku:create_config # Creates an example configuration file
77
78
  rake heroku:gems # Generate the Heroku gems manifest from gem dependencies
79
+ rake heroku:push # Pushes the given commit (default: HEAD)
80
+ rake heroku:push:force # Force-pushes the given commit (default: HEAD)
78
81
  rake heroku:remotes # Add git remotes for all apps in this project
79
82
  rake heroku:rack_env # Add proper RACK_ENV to each application
83
+ rake heroku:rake[task] # Runs a rake task remotely
80
84
  rake heroku:share # Adds a collaborator
81
85
  rake heroku:unshare # Removes a collaborator
82
86
  rake migrate # Migrates and restarts remote servers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -24,7 +24,7 @@ namespace :heroku do
24
24
  desc "Creates the Heroku app"
25
25
  task :create do
26
26
  each_heroku_app do |name, app, repo|
27
- system_with_echo "heroku create #{app}"
27
+ sh "heroku create #{app}"
28
28
  end
29
29
  end
30
30
 
@@ -58,17 +58,17 @@ namespace :heroku do
58
58
  $stdout.flush
59
59
  email = $stdin.gets
60
60
  each_heroku_app do |name, app, repo|
61
- system_with_echo "heroku sharing:add --app #{app} #{email}"
61
+ sh "heroku sharing:add --app #{app} #{email}"
62
62
  end
63
63
  end
64
64
 
65
- desc 'Adds a collaborator'
65
+ desc 'Removes a collaborator'
66
66
  task :unshare do
67
67
  print "Email address of collaborator to remove: "
68
68
  $stdout.flush
69
69
  email = $stdin.gets
70
70
  each_heroku_app do |name, app, repo|
71
- system_with_echo "heroku sharing:remove --app #{app} #{email}"
71
+ sh "heroku sharing:remove --app #{app} #{email}"
72
72
  end
73
73
  end
74
74
 
@@ -88,7 +88,7 @@ namespace :heroku do
88
88
  puts command
89
89
  config = Hash[`#{command}`.scan(/^(.+?)\s*=>\s*(.+)$/)]
90
90
  if config['RACK_ENV'] != name
91
- system_with_echo "heroku config:add --app #{app} RACK_ENV=#{name}"
91
+ sh "heroku config:add --app #{app} RACK_ENV=#{name}"
92
92
  end
93
93
  end
94
94
  end
@@ -101,26 +101,58 @@ namespace :heroku do
101
101
  else
102
102
  puts "Copied example config to config/heroku.yml"
103
103
  FileUtils.cp(example, HEROKU_CONFIG_FILE)
104
- system_with_echo("#{ENV['EDITOR']} #{HEROKU_CONFIG_FILE}")
104
+ sh("#{ENV['EDITOR']} #{HEROKU_CONFIG_FILE}")
105
105
  end
106
106
  end
107
- end
108
107
 
109
- desc "Deploys, migrates and restarts latest code"
110
- task :deploy => :before_deploy do
111
- each_heroku_app do |name, app, repo|
112
- branch = `git branch`.scan(/^\* (.*)\n/).flatten.first.to_s
113
- if branch.present?
108
+ desc 'Runs a rake task remotely'
109
+ task :rake, :task do |t, args|
110
+ each_heroku_app do |name, app, repo|
111
+ sh "heroku rake --app #{app} #{args[:task]}"
112
+ end
113
+ end
114
+
115
+ desc "Pushes the given commit (default: HEAD)"
116
+ task :push, :commit do |t, args|
117
+ each_heroku_app do |name, app, repo|
118
+ push(args[:commit], repo)
119
+ end
120
+ end
121
+
122
+ namespace :push do
123
+ desc "Force-pushes the given commit (default: HEAD)"
124
+ task :force, :commit do |t, args|
114
125
  @git_push_arguments ||= []
115
- system_with_echo "git push #{repo} #{@git_push_arguments.join(' ')} #{branch}:master && heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
116
- else
117
- puts "Unable to determine the current git branch, please checkout the branch you'd like to deploy"
118
- exit(1)
126
+ @git_push_arguments << '--force'
127
+ Rake::Task[:'heroku:push'].execute(args)
119
128
  end
120
129
  end
130
+
131
+ end
132
+
133
+ desc "Pushes the given commit, migrates and restarts (default: HEAD)"
134
+ task :deploy, :commit, :needs => :before_deploy do |t, args|
135
+ each_heroku_app do |name, app, repo|
136
+ push(args[:commit], repo)
137
+ migrate(app)
138
+ end
121
139
  Rake::Task[:after_deploy].execute
122
140
  end
123
141
 
142
+ namespace :deploy do
143
+ desc "Force-pushes the given commit, migrates and restarts (default: HEAD)"
144
+ task :force, :commit do |t, args|
145
+ @git_push_arguments ||= []
146
+ @git_push_arguments << '--force'
147
+ Rake::Task[:deploy].execute(args)
148
+ end
149
+ end
150
+
151
+ # Deprecated.
152
+ task :force_deploy do
153
+ Rake::Task[:'deploy:force'].invoke
154
+ end
155
+
124
156
  desc "Callback before deploys"
125
157
  task :before_deploy do
126
158
  end
@@ -129,62 +161,50 @@ desc "Callback after deploys"
129
161
  task :after_deploy do
130
162
  end
131
163
 
132
- desc "Force deploys, migrates and restarts latest code"
133
- task :force_deploy do
134
- @git_push_arguments ||= []
135
- @git_push_arguments << '--force'
136
- Rake::Task[:deploy].execute
137
- end
138
-
139
164
  desc "Captures a bundle on Heroku"
140
165
  task :capture do
141
166
  each_heroku_app do |name, app, repo|
142
- system_with_echo "heroku bundles:capture --app #{app}"
167
+ sh "heroku bundles:capture --app #{app}"
143
168
  end
144
169
  end
145
170
 
146
171
  desc "Opens a remote console"
147
172
  task :console do
148
173
  each_heroku_app do |name, app, repo|
149
- system_with_echo "heroku console --app #{app}"
174
+ sh "heroku console --app #{app}"
150
175
  end
151
176
  end
152
177
 
153
178
  desc "Restarts remote servers"
154
179
  task :restart do
155
180
  each_heroku_app do |name, app, repo|
156
- system_with_echo "heroku restart --app #{app}"
181
+ sh "heroku restart --app #{app}"
157
182
  end
158
183
  end
159
184
 
160
185
  desc "Migrates and restarts remote servers"
161
186
  task :migrate do
162
187
  each_heroku_app do |name, app, repo|
163
- system_with_echo "heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
188
+ migrate(app)
164
189
  end
165
190
  end
166
191
 
167
192
  namespace :db do
168
193
  task :pull do
169
194
  each_heroku_app do |name, app, repo|
170
- system_with_echo "heroku pgdumps:capture --app #{app}"
195
+ sh "heroku pgdumps:capture --app #{app}"
171
196
  dump = `heroku pgdumps --app #{app}`.split("\n").last.split(" ").first
172
- system_with_echo "mkdir -p #{Rails.root}/db/dumps"
197
+ sh "mkdir -p #{Rails.root}/db/dumps"
173
198
  file = "#{Rails.root}/db/dumps/#{dump}.sql.gz"
174
199
  url = `heroku pgdumps:url --app #{app} #{dump}`.chomp
175
- system_with_echo "wget", url, "-O", file
176
- system_with_echo "rake db:drop db:create"
177
- system_with_echo "gunzip -c #{file} | #{Rails.root}/script/dbconsole"
178
- system_with_echo "rake jobs:clear"
200
+ sh "wget", url, "-O", file
201
+ sh "rake db:drop db:create"
202
+ sh "gunzip -c #{file} | #{Rails.root}/script/dbconsole"
203
+ sh "rake jobs:clear"
179
204
  end
180
205
  end
181
206
  end
182
207
 
183
- def system_with_echo(*args)
184
- puts args.join(' ')
185
- system(*args)
186
- end
187
-
188
208
  def each_heroku_app
189
209
  if @heroku_apps.blank? && HEROKU_SETTINGS['apps'].size == 1
190
210
  app = HEROKU_SETTINGS['apps'].keys.first
@@ -209,3 +229,19 @@ def each_heroku_app
209
229
  exit(1)
210
230
  end
211
231
  end
232
+
233
+ def push(commit, repo)
234
+ commit ||= "HEAD"
235
+ @git_push_arguments ||= []
236
+ begin
237
+ sh "git update-ref refs/heroku_san/deploy #{commit}"
238
+ sh "git push #{repo} #{@git_push_arguments.join(' ')} refs/heroku_san/deploy:refs/heads/master"
239
+ ensure
240
+ sh "git update-ref -d refs/heroku_san/deploy"
241
+ end
242
+ end
243
+
244
+ def migrate(app)
245
+ sh "heroku rake --app #{app} db:migrate"
246
+ sh "heroku restart --app #{app}"
247
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_san
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Elijah Miller
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-22 00:00:00 -04:00
19
+ date: 2010-11-11 00:00:00 -06:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency