Automation Manifesto

Automate as much as possible. 

Goals

Deploy: 1 command/click. 
Rollback: 1 command/click. 
Unit tests: 0 commands, should run every time you make a change to your code.

Errors occur: Email alerts are automatically sent to the dev team, no manual checking necessary.
Business metrics are off: Email alerts are automatically sent to the dev team and whoever is involved (finance, marketing)

Reasoning

At first it might seem like a waste of time to spend 1 hour automating something that only takes 5 minutes to do manually. But if it happens again and again, you would've been better off automating it in the first place. If you do something for the second time, think how you could automate it. If you do something by hand for the third time, automation time is finally here!

Another advantage is that other people can you your automated tools much easier. It is trivial to teach someone to click a button, but it's hard to tell him the exact workings and sequence of executing custom shell scripts and logging in to FTP accounts. It might take YOU 5 minutes to deploy by hand and restart the web server, but it might take someone else two hours.

Automation is abstraction. Abstraction decreases the need for attention and focus. Attention and focus can then be applied to other things.

How to automate?

How is not as important as doing it in the first place. You probably know either bash, Python, Ruby, PHP, Perl or something similar. Just make sure that using your automated script doesn't require too much knowledge of the specific language/tools you used.

Executing './deploy.sh', './deploy.py' or './deploy.rb' is just about the same thing. Just use a tool you're familiar with (or learn one). And don't require your user to give crazy, undocumented arguments. Showing a '--help' is probably a good idea if your tool has options and arguments, or putting comments in the script file itself.

Don't make me type './script.sh --action deploy --server ftp.appbackr.com --user appbackr --password mypw --port 21
I'd much rather type './deploy.sh'.

Start small. Increment. Observe which repetitive task takes the most time out of your day. Automate it a little. Start over. This could mean wrapping several shell scripts in one big shell script that executes all of them in the right order. This could mean removing arguments form a script and setting the values inside the script.

Several small tools are better than One Huge Tool to Bind Them All (tm). It's the UNIX way for a reason.

But I'm not a programmer!

If you're non-technical: Don't be afraid of programming! It's easy. If you identify some repetitive task that you think could be done automatically, the programming solution is usually just 30 minutes of googling and 10 lines of code away. Just start small and learn the tools (Ruby, Python, or similar).

 

The technical people are happy to help you out if you have any questions. Because you'll bug them less about boring, repetitive tasks in the future. And because technical people are nice people too.

When to stop automating

The perfect company just has a single man and a dog. The man's there to watch the dog. The dog's there to keep the man busy. Everything else is automated.

 

Automated PHP unit testing for lazy coders

(This concept was inspired by Autotest using Watchr getting notified via Growl).

Here at appbackr, we're all about connecting app developers with backrs, who fund the app development (and make a healthy profit). To achieve this goal, we need to oil the machinery from time to time. This is one of those times.

We've recently started migrating to Yii. Yii is a MVC-based PHP framework, similar to what Rails is on Ruby. It allows us to simplify the maintenance of the appbackr marketplace and fix bugs quickly and reliably. It also decreases development time for new features, when compared to our old non-MVC site.

We want to be able to react faster, iterate in shorter cycles and produce a more stable website for app developers and backrs. Yii is relatively light weight, but provides a lot of useful features (logins, user management, ActiveRecord), thereby taking a lot of work off our shoulders. It doesn't come with the bulk other frameworks (e.g. CakePHP, Zend) do, so the learning time for the framework itself is short - giving us more time for actual development.

Yii has built-in support for PHPUnit, allowing easy unit testing. This was one of the aspects when we looked at different frameworks. We’re planning to incorporate Test Driven Development into our development process in the near future. And of course we want to cover our existing codebase with tests, so we notice when we break stuff. This will allow us to refactor without fear of breaking something, as every bug will show up as a failed test.

Now you could run the tests manually after each change by typing 'phpunit <your test folder>', but we were looking for something a little more comfortable. We want to decrease the transactional cost of running the tests as much as possible to make the lives of our engineers more pleasant. Making testing easy is the only way the engineers will run the tests frequently.

The goal was to have a solution that you don’t have to care about at all and that gives you, as an engineer, instant feedback on your code changes.

Enter Watchr. Watchr is a ruby tool that monitors a specified list of files for change. It allows you to execute scripts on defined changes in files. In simple terms: As soon as you save changes to your code, Watchr will run your test suite and inform you if the tests ran through. Automatically, without you ever having to switch to the terminal, type anything or even click a button.

For better visibility and instant feedback, I looked for something simple that gives engineers instant feedback about the status of their tests. Scanning the terminal for F (Failure) takes too long and is tiring. We found Growl, the omnipresent Mac OS X notification tool. Dropbox and Adium are using Growl. Almost every app on OS X uses Growl for notifications. You know, these little boxes?

Test_succeeded

All tests succeeded. Good times.

 

By combining PHPUnit, Watchr and Growl, we get super slick auto testing for our local dev environments. It keeps us notified, while coding, if we break stuff.

As soon as we save any changes on the source, Watchr starts our PHPUnit test suite. About two seconds later, like magic, the little Growl notification in the upper right informs us if our tests succeeded. If they did, it's green. If they failed, it's red. 

Test_failed

Slartibartfas could not be found. Now we need to fix that.

 

Setting up all this is quite easy. Just download and install PHPUnit, Watchr and growlnotify. For simplicity's sake, I've put a copy of my watchr.rb script on github.

Here’s the gist of it:

 

I’m looking forward to hearing your feedback. There is a lot of room for improvements, so feel free to leave your thoughts. If you know similar notification tools for Ubuntu and Windows, please let us know in the comments.

 

Happy coding!