Ruby & Rails

Hendrik Mans - January 19, 2013


3# A "cheap man's CI" shortcut. Runs your project's tests,
4# pushes your changes and finally deploys your application.
5# If any of the steps fail, execution is cancelled.
8rake && git push && bundle exec cap deploy

This is probably my favorite little helper script right now (and yes, I know it could just as well be an alias.) After making a change to one of my Rails projects and creating the commit, I just run deployerize, which will

  1. run my app’s test suite by way of rake, which will invoke the project’s default rake task. In a typical Rails app, this will be either your Test::Unit or RSpec suite.
  2. push my new commits to the remote repository, as long as there are no commits waiting for me on the other side (in which case git will cancel the operation)
  3. deploy my app to the server through Capistrano, making it run within a bundle exec context so it picks up the correct gems.

Through the magic of &&, if any of these steps fail, the following steps will not be executed.

For example, my specs may fail, in which case I obviously don’t even want to push my changes to the repository. (Well, this shouldn’t really happen, since ideally I run the tests before creating the commit.)

If there are new commits waiting for me on the repository, git push will (of course) abort and fail, allowing me to first git pull --rebase the new commits and then repeat the entire procedure.

I’m running this little script after most little (or even large) changes I make, trusting it to only deploy the new stuff once I’ve made sure it all works nicely. Of course this also means that tests are really important, since they’re my primary safeguard against catastrophic failure; and since I know this, I’m taking extra care with my tests, which is a nice side-effect.


Developer dude from Hamburg, Germany. Among other things, runs Not good with descriptions. Don’t follow me on Twitter. ★

Loading comments...

Please sign in to post a comment.