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
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.
- 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)
deploy my app to the server through Capistrano, making it run within a
bundle execcontext 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.