Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make the task description parser a bit smarter, so that heredocs can …

…be used for task descriptions again

git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6495 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 0e774ac0d009427aeecd7be4bcdb0e1ca8b69967 1 parent 669bb75
Jamis Buck jamis authored
332 lib/capistrano/recipes/deploy.rb
@@ -49,37 +49,43 @@
49 49 set(:run_method) { fetch(:use_sudo, true) ? :sudo : :run }
50 50
51 51 namespace :deploy do
52   -desc "Deploys your project. This calls both `update' and `restart'. Note that \
53   -this will generally only work for applications that have already been deployed \
54   -once. For a \"cold\" deploy, you'll want to take a look at the `cold_deploy' \
55   -task, which handles the cold start specifically."
  52 + desc <<-DESC
  53 + Deploys your project. This calls both `update' and `restart'. Note that \
  54 + this will generally only work for applications that have already been deployed \
  55 + once. For a "cold" deploy, you'll want to take a look at the `cold_deploy' \
  56 + task, which handles the cold start specifically.
  57 + DESC
56 58 task :default do
57 59 update
58 60 restart
59 61 end
60 62
61   -desc "Prepares one or more servers for deployment. Before you can use any \
62   -of the Capistrano deployment tasks with your project, you will need to make \
63   -sure all of your servers have been prepared with `cap setup'. When you add a \
64   -new server to your cluster, you can easily run the setup task on just that \
65   -server by specifying the HOSTS environment variable:
  63 + desc <<-DESC
  64 + Prepares one or more servers for deployment. Before you can use any \
  65 + of the Capistrano deployment tasks with your project, you will need to \
  66 + make sure all of your servers have been prepared with `cap setup'. When \
  67 + you add a new server to your cluster, you can easily run the setup task \
  68 + on just that server by specifying the HOSTS environment variable:
66 69
67   - $ cap HOSTS=new.server.com setup
  70 + $ cap HOSTS=new.server.com setup
68 71
69   -It is safe to run this task on servers that have already been set up; it will \
70   -not destroy any deployed revisions or data."
  72 + It is safe to run this task on servers that have already been set up; it \
  73 + will not destroy any deployed revisions or data.
  74 + DESC
71 75 task :setup, :except => { :no_release => true } do
72 76 dirs = [deploy_to, releases_path, shared_path]
73 77 dirs += %w(system log pids).map { |d| File.join(shared_path, d) }
74 78 run "umask 02 && mkdir -p #{dirs.join(' ')}"
75 79 end
76 80
77   -desc "Copies your project and updates the symlink. It does this in a transaction, \
78   -so that if either `update_code' or `symlink' fail, all changes made to the \
79   -remote servers will be rolled back, leaving your system in the same state it \
80   -was in before `update' was invoked. Usually, you will want to call `deploy' \
81   -instead of `update', but `update' can be handy if you want to deploy, but not \
82   -immediately restart your application."
  81 + desc <<-DESC
  82 + Copies your project and updates the symlink. It does this in a \
  83 + transaction, so that if either `update_code' or `symlink' fail, all \
  84 + changes made to the remote servers will be rolled back, leaving your \
  85 + system in the same state it was in before `update' was invoked. Usually, \
  86 + you will want to call `deploy' instead of `update', but `update' can be \
  87 + handy if you want to deploy, but not immediately restart your application.
  88 + DESC
83 89 task :update do
84 90 transaction do
85 91 update_code
@@ -87,32 +93,37 @@
87 93 end
88 94 end
89 95
90   -desc "Copies your project to the remote servers. This is the first stage \
91   -of any deployment; moving your updated code and assets to the deployment \
92   -servers. You will rarely call this task directly, however; instead, you should \
93   -call the `deploy' task (to do a complete deploy) or the `update' task (if you \
94   -want to perform the `restart' task separately).
95   -
96   -You will need to make sure you set the :scm variable to the source control \
97   -software you are using (it defaults to :subversion), and the :deploy_via \
98   -variable to the strategy you want to use to deploy (it defaults to :checkout)."
  96 + desc <<-DESC
  97 + Copies your project to the remote servers. This is the first stage \
  98 + of any deployment; moving your updated code and assets to the deployment \
  99 + servers. You will rarely call this task directly, however; instead, you \
  100 + should call the `deploy' task (to do a complete deploy) or the `update' \
  101 + task (if you want to perform the `restart' task separately).
  102 +
  103 + You will need to make sure you set the :scm variable to the source \
  104 + control software you are using (it defaults to :subversion), and the \
  105 + :deploy_via variable to the strategy you want to use to deploy (it \
  106 + defaults to :checkout).
  107 + DESC
99 108 task :update_code, :except => { :no_release => true } do
100 109 on_rollback { run "rm -rf #{release_path}; true" }
101 110 strategy.deploy!
102 111 finalize_update
103 112 end
104 113
105   -desc "[internal] Touches up the released code. This is called by update_code \
106   -after the basic deploy finishes. It assumes a Rails project was deployed, so \
107   -if you are deploying something else, you may want to override this task with \
108   -your own environment's requirements.
109   -
110   -This task will make the release group-writable (if the :group_writable \
111   -variable is set to true, which is the default). It will then set up symlinks \
112   -to the shared directory for the log, system, and tmp/pids directories, and \
113   -will lastly touch all assets in public/images, public/stylesheets, and \
114   -public/javascripts so that the times are consistent (so that asset timestamping \
115   -works)."
  114 + desc <<-DESC
  115 + [internal] Touches up the released code. This is called by update_code \
  116 + after the basic deploy finishes. It assumes a Rails project was deployed, \
  117 + so if you are deploying something else, you may want to override this \
  118 + task with your own environment's requirements.
  119 +
  120 + This task will make the release group-writable (if the :group_writable \
  121 + variable is set to true, which is the default). It will then set up \
  122 + symlinks to the shared directory for the log, system, and tmp/pids \
  123 + directories, and will lastly touch all assets in public/images, \
  124 + public/stylesheets, and public/javascripts so that the times are \
  125 + consistent (so that asset timestamping works).
  126 + DESC
116 127 task :finalize_update, :except => { :no_release => true } do
117 128 run "chmod -R g+w #{release_path}" if fetch(:group_writable, true)
118 129
@@ -128,29 +139,35 @@
128 139 run "find #{asset_paths} -exec touch -t #{stamp} {} \\;; true", :env => { "TZ" => "UTC" }
129 140 end
130 141
131   -desc "Updates the symlink to the deployed version. Capistrano works by putting \
132   -each new release of your application in its own directory. When you deploy a \
133   -new version, this task's job is to update the `current' symlink to point at \
134   -the new version. You will rarely need to call this task directly; instead, use \
135   -the `deploy' task (which performs a complete deploy, including `restart') or \
136   -the 'update' task (which does everything except `restart')."
  142 + desc <<-DESC
  143 + Updates the symlink to the deployed version. Capistrano works by putting \
  144 + each new release of your application in its own directory. When you \
  145 + deploy a new version, this task's job is to update the `current' symlink \
  146 + to point at the new version. You will rarely need to call this task \
  147 + directly; instead, use the `deploy' task (which performs a complete \
  148 + deploy, including `restart') or the 'update' task (which does everything \
  149 + except `restart').
  150 + DESC
137 151 task :symlink, :except => { :no_release => true } do
138 152 on_rollback { run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" }
139 153 run "rm -f #{current_path} && ln -s #{release_path} #{current_path}"
140 154 end
141 155
142   -desc "Copy files to the currently deployed version. This is useful for updating \
143   -files piecemeal, such as when you need to quickly deploy only a single file. \
144   -Some files, such as updated templates, images, or stylesheets, might not require \
145   -a full deploy, and especially in emergency situations it can be handy to just \
146   -push the updates to production, quickly.
147   -
148   -To use this task, specify the files and directories you want to copy as a \
149   -comma-delimited list in the FILES environment variable. All directories will \
150   -be processed recursively, with all files being pushed to the deployment \
151   -servers. Any file or directory starting with a '.' character will be ignored.
152   -
153   - $ cap deploy:upload FILES=templates,controller.rb"
  156 + desc <<-DESC
  157 + Copy files to the currently deployed version. This is useful for updating \
  158 + files piecemeal, such as when you need to quickly deploy only a single \
  159 + file. Some files, such as updated templates, images, or stylesheets, \
  160 + might not require a full deploy, and especially in emergency situations \
  161 + it can be handy to just push the updates to production, quickly.
  162 +
  163 + To use this task, specify the files and directories you want to copy as a \
  164 + comma-delimited list in the FILES environment variable. All directories \
  165 + will be processed recursively, with all files being pushed to the \
  166 + deployment servers. Any file or directory starting with a '.' character \
  167 + will be ignored.
  168 +
  169 + $ cap deploy:upload FILES=templates,controller.rb
  170 + DESC
154 171 task :upload, :except => { :no_release => true } do
155 172 files = (ENV["FILES"] || "").
156 173 split(",").
@@ -165,21 +182,25 @@
165 182 end
166 183 end
167 184
168   -desc "Restarts your application. This works by calling the script/process/reaper \
169   -script under the current path. By default, this will be invoked via sudo, but \
170   -if you are in an environment where sudo is not an option, or is not allowed, \
171   -you can indicate that restarts should use `run' instead by setting the \
172   -`use_sudo' variable to false:
  185 + desc <<-DESC
  186 + Restarts your application. This works by calling the script/process/reaper \
  187 + script under the current path. By default, this will be invoked via sudo, \
  188 + but if you are in an environment where sudo is not an option, or is not \
  189 + allowed, you can indicate that restarts should use `run' instead by \
  190 + setting the `use_sudo' variable to false:
173 191
174   - set :use_sudo, false"
  192 + set :use_sudo, false
  193 + DESC
175 194 task :restart, :roles => :app, :except => { :no_release => true } do
176 195 invoke_command "#{current_path}/script/process/reaper", :via => run_method
177 196 end
178 197
179   -desc "Rolls back to the previously deployed version. The `current' symlink will \
180   -be updated to point at the previously deployed version, and then the current \
181   -release will be removed from the servers. You'll generally want to call \
182   -`rollback' instead, as it performs a `restart' as well."
  198 + desc <<-DESC
  199 + Rolls back to the previously deployed version. The `current' symlink will \
  200 + be updated to point at the previously deployed version, and then the \
  201 + current release will be removed from the servers. You'll generally want \
  202 + to call `rollback' instead, as it performs a `restart' as well.
  203 + DESC
183 204 task :rollback_code, :except => { :no_release => true } do
184 205 if releases.length < 2
185 206 abort "could not rollback the code because there is no prior release"
@@ -188,28 +209,32 @@
188 209 end
189 210 end
190 211
191   -desc "Rolls back to a previous version and restarts. This is handy if you ever \
192   -discover that you've deployed a lemon; `cap rollback' and you're right back \
193   -where you were, on the previously deployed version."
  212 + desc <<-DESC
  213 + Rolls back to a previous version and restarts. This is handy if you ever \
  214 + discover that you've deployed a lemon; `cap rollback' and you're right \
  215 + back where you were, on the previously deployed version.
  216 + DESC
194 217 task :rollback do
195 218 rollback_code
196 219 restart
197 220 end
198 221
199   -desc "Run the migrate rake task. By default, it runs this in most recently \
200   -deployed version of the app. However, you can specify a different release \
201   -via the migrate_target variable, which must be one of :latest (for the \
202   -default behavior), or :current (for the release indicated by the `current' \
203   -symlink). latest release to be deployed with the update_code task). Strings will work \
204   -for those values instead of symbols, too. You can also specify additional \
205   -environment variables to pass to rake via the migrate_env variable. Finally, \
206   -you can specify the full path to the rake executable by setting the rake \
207   -variable. The defaults are:
208   -
209   - set :rake, \"rake\"
210   - set :rails_env, \"production\"
211   - set :migrate_env, \"\"
212   - set :migrate_target, :latest"
  222 + desc <<-DESC
  223 + Run the migrate rake task. By default, it runs this in most recently \
  224 + deployed version of the app. However, you can specify a different release \
  225 + via the migrate_target variable, which must be one of :latest (for the \
  226 + default behavior), or :current (for the release indicated by the \
  227 + `current' symlink). latest release to be deployed with the update_code \
  228 + task). Strings will work for those values instead of symbols, too. You \
  229 + can also specify additional environment variables to pass to rake via the \
  230 + migrate_env variable. Finally, you can specify the full path to the rake \
  231 + executable by setting the rake variable. The defaults are:
  232 +
  233 + set :rake, "rake"
  234 + set :rails_env, "production"
  235 + set :migrate_env, ""
  236 + set :migrate_target, :latest
  237 + DESC
213 238 task :migrate, :roles => :db, :only => { :primary => true } do
214 239 rake = fetch(:rake, "rake")
215 240 rails_env = fetch(:rails_env, "production")
@@ -225,11 +250,13 @@
225 250 run "cd #{directory}; #{rake} RAILS_ENV=#{rails_env} #{migrate_env} db:migrate"
226 251 end
227 252
228   -desc "Deploy and run pending migrations. This will work similarly to the \
229   -`deploy' task, but will also run any pending migrations (via the `deploy:migrate' \
230   -task) prior to updating the symlink. Note that the update in this case it is \
231   -not atomic, and transactions are not used, because migrations are not \
232   -guaranteed to be reversible."
  253 + desc <<-DESC
  254 + Deploy and run pending migrations. This will work similarly to the \
  255 + `deploy' task, but will also run any pending migrations (via the \
  256 + `deploy:migrate' task) prior to updating the symlink. Note that the \
  257 + update in this case it is not atomic, and transactions are not used, \
  258 + because migrations are not guaranteed to be reversible.
  259 + DESC
233 260 task :migrations do
234 261 set :migrate_target, :latest
235 262 update_code
@@ -238,11 +265,13 @@
238 265 restart
239 266 end
240 267
241   -desc "Clean up old releases. By default, the last 5 releases are kept on each \
242   -server (though you can change this with the keep_releases variable). All other \
243   -deployed revisions are removed from the servers. By default, this will use \
244   -sudo to clean up the old releases, but if sudo is not available for your \
245   -environment, set the :use_sudo variable to false instead."
  268 + desc <<-DESC
  269 + Clean up old releases. By default, the last 5 releases are kept on each \
  270 + server (though you can change this with the keep_releases variable). All \
  271 + other deployed revisions are removed from the servers. By default, this \
  272 + will use sudo to clean up the old releases, but if sudo is not available \
  273 + for your environment, set the :use_sudo variable to false instead.
  274 + DESC
246 275 task :cleanup, :except => { :no_release => true } do
247 276 count = fetch(:keep_releases, 5).to_i
248 277 if count >= releases.length
@@ -257,10 +286,12 @@
257 286 end
258 287 end
259 288
260   -desc "Test deployment dependencies. Checks things like directory permissions, \
261   -necessary utilities, and so forth, reporting on the things that appear to be \
262   -incorrect or missing. This is good for making sure a deploy has a chance of \
263   -working before you actually run `cap deploy'!"
  289 + desc <<-DESC
  290 + Test deployment dependencies. Checks things like directory permissions, \
  291 + necessary utilities, and so forth, reporting on the things that appear to \
  292 + be incorrect or missing. This is good for making sure a deploy has a \
  293 + chance of working before you actually run `cap deploy'.
  294 + DESC
264 295 task :check, :except => { :no_release => true } do
265 296 dependencies = strategy.check!
266 297 if dependencies.pass?
@@ -273,41 +304,48 @@
273 304 end
274 305 end
275 306
276   -desc "Deploys and starts a `cold' application. This is useful if you have not \
277   -deployed your application before, or if your application is (for some other \
278   -reason) not currently running. It will deploy the code, and then instead of \
279   -invoking `deploy:restart', it will invoke `deploy:app:start' to fire up the \
280   -application servers."
  307 + desc <<-DESC
  308 + Deploys and starts a `cold' application. This is useful if you have not \
  309 + deployed your application before, or if your application is (for some \
  310 + other reason) not currently running. It will deploy the code, and then \
  311 + instead of invoking `deploy:restart', it will invoke `deploy:app:start' \
  312 + to fire up the application servers.
  313 + DESC
281 314 task :cold do
282 315 update
283 316 app.start
284 317 end
285 318
286 319 namespace :app do
287   -desc "Start the application servers. This will attempt to invoke a script \
288   -in your application called `script/spin', which must know how to start your \
289   -application listeners. For Rails applications, you might just have that script \
290   -invoke `script/process/spawner' with the appropriate arguments.
291   -
292   -By default, the script will be executed via sudo as the `app' user. If you \
293   -wish to run it as a different user, set the :runner variable to that user. \
294   -If you are in an environment where you can't use sudo, set the :use_sudo \
295   -variable to false."
  320 + desc <<-DESC
  321 + Start the application servers. This will attempt to invoke a script \
  322 + in your application called `script/spin', which must know how to start \
  323 + your application listeners. For Rails applications, you might just have \
  324 + that script invoke `script/process/spawner' with the appropriate \
  325 + arguments.
  326 +
  327 + By default, the script will be executed via sudo as the `app' user. If \
  328 + you wish to run it as a different user, set the :runner variable to \
  329 + that user. If you are in an environment where you can't use sudo, set \
  330 + the :use_sudo variable to false.
  331 + DESC
296 332 task :start, :roles => :app do
297 333 as = fetch(:runner, "app")
298 334 via = fetch(:run_method, :sudo)
299 335 invoke_command "sh -c 'cd #{current_path} && nohup script/spin'", :via => via, :as => as
300 336 end
301 337
302   -desc "Stop the application servers. This will call script/process/reaper for \
303   -both the spawner process, and all of the application processes it has spawned. \
304   -As such, it is fairly Rails specific and may need to be overridden for other \
305   -systems.
306   -
307   -By default, the script will be executed via sudo as the `app' user. If you \
308   -wish to run it as a different user, set the :runner variable to that user. \
309   -If you are in an environment where you can't use sudo, set the :use_sudo \
310   -variable to false."
  338 + desc <<-DESC
  339 + Stop the application servers. This will call script/process/reaper for \
  340 + both the spawner process, and all of the application processes it has \
  341 + spawned. As such, it is fairly Rails specific and may need to be \
  342 + overridden for other systems.
  343 +
  344 + By default, the script will be executed via sudo as the `app' user. If \
  345 + you wish to run it as a different user, set the :runner variable to \
  346 + that user. If you are in an environment where you can't use sudo, set \
  347 + the :use_sudo variable to false.
  348 + DESC
311 349 task :stop, :roles => :app do
312 350 as = fetch(:runner, "app")
313 351 via = fetch(:run_method, :sudo)
@@ -318,35 +356,42 @@
318 356 end
319 357
320 358 namespace :pending do
321   -desc "Displays the `diff' since your last deploy. This is useful if you want \
322   -to examine what changes are about to be deployed. Note that this might not be \
323   -supported on all SCM's."
  359 + desc <<-DESC
  360 + Displays the `diff' since your last deploy. This is useful if you want \
  361 + to examine what changes are about to be deployed. Note that this might \
  362 + not be supported on all SCM's.
  363 + DESC
324 364 task :diff, :except => { :no_release => true } do
325 365 system(source.diff(current_revision))
326 366 end
327 367
328   -desc "Displays the commits since your last deploy. This is good for a summary \
329   -of the changes that have occurred since the last deploy. Note that this might \
330   -not be supported on all SCM's."
  368 + desc <<-DESC
  369 + Displays the commits since your last deploy. This is good for a summary \
  370 + of the changes that have occurred since the last deploy. Note that this \
  371 + might not be supported on all SCM's.
  372 + DESC
331 373 task :default, :except => { :no_release => true } do
332 374 system(source.log(current_revision))
333 375 end
334 376 end
335 377
336 378 namespace :web do
337   -desc "Present a maintenance page to visitors. Disables your application's web \
338   -interface by writing a \"maintenance.html\" file to each web server. The \
339   -servers must be configured to detect the presence of this file, and if it is \
340   -present, always display it instead of performing the request.
341   -
342   -By default, the maintenance page will just say the site is down for \
343   -\"maintenance\", and will be back \"shortly\", but you can customize the page \
344   -by specifying the REASON and UNTIL environment variables:
345   -
346   - $ cap deploy:web:disable BECAUSE=\"hardware upgrade\" \\
347   - UNTIL=\"12pm Central Time\"
348   -
349   -Further customization will require that you write your own task."
  379 + desc <<-DESC
  380 + Present a maintenance page to visitors. Disables your application's web \
  381 + interface by writing a "maintenance.html" file to each web server. The \
  382 + servers must be configured to detect the presence of this file, and if \
  383 + it is present, always display it instead of performing the request.
  384 +
  385 + By default, the maintenance page will just say the site is down for \
  386 + "maintenance", and will be back "shortly", but you can customize the \
  387 + page by specifying the REASON and UNTIL environment variables:
  388 +
  389 + $ cap deploy:web:disable \\
  390 + BECAUSE="hardware upgrade" \\
  391 + UNTIL="12pm Central Time"
  392 +
  393 + Further customization will require that you write your own task.
  394 + DESC
350 395 task :disable, :roles => :web, :except => { :no_release => true } do
351 396 require 'erb'
352 397 on_rollback { run "rm #{shared_path}/system/maintenance.html" }
@@ -360,9 +405,12 @@
360 405 put result, "#{shared_path}/system/maintenance.html", :mode => 0644
361 406 end
362 407
363   -desc "Makes the application web-accessible again. Removes the \"maintenance.html\" \
364   -page generated by deploy:web:disable, which (if your web servers are \
365   -configured correclty) will make your application web-accessible again."
  408 + desc <<-DESC
  409 + Makes the application web-accessible again. Removes the \
  410 + "maintenance.html" page generated by deploy:web:disable, which (if your \
  411 + web servers are configured correctly) will make your application \
  412 + web-accessible again.
  413 + DESC
366 414 task :enable, :roles => :web, :except => { :no_release => true } do
367 415 run "rm #{shared_path}/system/maintenance.html"
368 416 end
36 lib/capistrano/recipes/standard.rb
... ... @@ -1,18 +1,18 @@
1 1 desc <<-DESC
2   -Invoke a single command on the remote servers. This is useful for performing \
3   -one-off commands that may not require a full task to be written for them. \
4   -Simply specify the command to execute via the COMMAND environment variable. \
5   -To execute the command only on certain roles, specify the ROLES environment \
6   -variable as a comma-delimited list of role names. Alternatively, you can \
7   -specify the HOSTS environment variable as a comma-delimited list of hostnames \
8   -to execute the task on those hosts, explicitly. Lastly, if you want to \
9   -execute the command via sudo, specify a non-empty value for the SUDO \
10   -environment variable.
  2 + Invoke a single command on the remote servers. This is useful for performing \
  3 + one-off commands that may not require a full task to be written for them. \
  4 + Simply specify the command to execute via the COMMAND environment variable. \
  5 + To execute the command only on certain roles, specify the ROLES environment \
  6 + variable as a comma-delimited list of role names. Alternatively, you can \
  7 + specify the HOSTS environment variable as a comma-delimited list of hostnames \
  8 + to execute the task on those hosts, explicitly. Lastly, if you want to \
  9 + execute the command via sudo, specify a non-empty value for the SUDO \
  10 + environment variable.
11 11
12   -Sample usage:
  12 + Sample usage:
13 13
14   - $ cap COMMAND=uptime HOSTS=foo.capistano.test invoke
15   - $ cap ROLES=app,web SUDO=1 COMMAND="tail -f /var/log/messages" invoke
  14 + $ cap COMMAND=uptime HOSTS=foo.capistano.test invoke
  15 + $ cap ROLES=app,web SUDO=1 COMMAND="tail -f /var/log/messages" invoke
16 16 DESC
17 17 task :invoke do
18 18 method = ENV["SUDO"] ? :sudo : :run
@@ -20,14 +20,14 @@
20 20 end
21 21
22 22 desc <<-DESC
23   -Begin an interactive Capistrano session. This gives you an interactive \
24   -terminal from which to execute tasks and commands on all of your servers. \
25   -(This is still an experimental feature, and is subject to change without \
26   -notice!)
  23 + Begin an interactive Capistrano session. This gives you an interactive \
  24 + terminal from which to execute tasks and commands on all of your servers. \
  25 + (This is still an experimental feature, and is subject to change without \
  26 + notice!)
27 27
28   -Sample usage:
  28 + Sample usage:
29 29
30   - $ cap shell
  30 + $ cap shell
31 31 DESC
32 32 task :shell do
33 33 require 'capistrano/shell'
14 lib/capistrano/recipes/upgrade.rb
@@ -2,12 +2,14 @@
2 2 # Capistrano 2.x.
3 3
4 4 namespace :upgrade do
5   -desc "Migrate from the revisions log to REVISION. Capistrano 1.x recorded each \
6   -deployment to a revisions.log file. Capistrano 2.x is cleaner, and just puts \
7   -a REVISION file in the root of the deployed revision. This task migrates \
8   -from the revisions.log used in Capistrano 1.x, to the REVISION tag file used \
9   -in Capistrano 2.x. It is non-destructive and may be safely run any number of \
10   -times."
  5 + desc <<-DESC
  6 + Migrate from the revisions log to REVISION. Capistrano 1.x recorded each \
  7 + deployment to a revisions.log file. Capistrano 2.x is cleaner, and just \
  8 + puts a REVISION file in the root of the deployed revision. This task \
  9 + migrates from the revisions.log used in Capistrano 1.x, to the REVISION \
  10 + tag file used in Capistrano 2.x. It is non-destructive and may be safely \
  11 + run any number of times.
  12 + DESC
11 13 task :revisions do
12 14 revisions = capture("cat #{deploy_to}/revisions.log")
13 15
16 lib/capistrano/task_definition.rb
@@ -41,9 +41,19 @@ def description(rebuild=false)
41 41 @description = nil if rebuild
42 42 @description ||= begin
43 43 description = options[:desc] || ""
44   - description.strip.
45   - gsub(/\r\n/, "\n").
46   - gsub(/\\\n/, " ")
  44 +
  45 + indentation = description[/\A\s+/]
  46 + if indentation
  47 + reformatted_description = ""
  48 + description.strip.each_line do |line|
  49 + line = line.chomp.sub(/^#{indentation}/, "")
  50 + line = line.gsub(/#{indentation}\s*/, " ") if line[/^\S/]
  51 + reformatted_description << line << "\n"
  52 + end
  53 + description = reformatted_description
  54 + end
  55 +
  56 + description.strip.gsub(/\r\n/, "\n")
47 57 end
48 58 end
49 59
28 test/task_definition_test.rb
@@ -108,6 +108,34 @@ def test_description_should_normalize_newlines
108 108 assert_equal "a\nb\nc", new_task(:testing, @namespace, :desc => "a\nb\r\nc").description
109 109 end
110 110
  111 + def test_description_should_detect_and_remove_indentation
  112 + desc = <<-DESC
  113 + Here is some indented text \
  114 + and I want all of this to \
  115 + run together on a single line, \
  116 + without any extraneous spaces.
  117 +
  118 + additional indentation will
  119 + be preserved.
  120 + DESC
  121 +
  122 + task = new_task(:testing, @namespace, :desc => desc)
  123 + assert_equal "Here is some indented text and I want all of this to run together on a single line, without any extraneous spaces.\n\n additional indentation will\n be preserved.", task.description
  124 + end
  125 +
  126 + def test_description_munging_should_be_sensitive_to_code_blocks
  127 + desc = <<-DESC
  128 + Here is a line \
  129 + wrapped with spacing in it.
  130 +
  131 + foo bar
  132 + baz bang
  133 + DESC
  134 +
  135 + task = new_task(:testing, @namespace, :desc => desc)
  136 + assert_equal "Here is a line wrapped with spacing in it.\n\n foo bar\n baz bang", task.description
  137 + end
  138 +
111 139 def test_task_brief_description_should_return_first_sentence_in_description
112 140 desc = "This is the task. It does all kinds of things."
113 141 task = new_task(:testing, @namespace, :desc => desc)

0 comments on commit 0e774ac

Please sign in to comment.
Something went wrong with that request. Please try again.