All in the <head> – Ponderings and code by Drew McLellan –

PHP Build Systems

Increasingly, I’m finding that the applications I build are becoming more complex with more component parts, often spread across frontend and backend. Particularly with user interfaces becoming more advanced, the number of CSS and JavaScript files that need to be wrangled seems to be increasing, and with it I’m becoming more and more paranoid about frontend performance. This typically involves doing stuff like concatenating a bunch of small files into one, minifying JavaScript and so forth.

Up until now I’ve been doing this by hand. As with anything of this nature you have to do by hand, it’s far too easy to forget steps, to deviate from a standard process, and really it’s just plain boring and takes more time than it should. In short, I need a proper build system.

I could, of course, just write myself a command line PHP script to do what I need, but as I figure that this is not only a common problem but also one at which others have more experience, it’d be worth looking at existing build systems and seeing what I can learn from them.

The basic things I need to do can probably be boiled down to two or three main features. Firstly, I need to be able to export a version of the code from SVN (ideally by tag) to somewhere on the file system. Secondly I need to make some config changes (like switching dev/prod environment flags). Lastly, I need to be able run scripts across the build to do things like minify JavaScript, concatenate CSS, and perhaps run things like r3 to translate the site into multiple languages.

If it were to go a step further and offer the ability to scp the build up to a staging server, that would also be worth looking at. Another nice-to-have would be the ability to take a mysqldump of the structure of a number of databases and flag if there have been any schema changes since the last build that need to be manually addressed.

All this sounds fairly easily scriptable, but as I say, using an established build system might bring me advantages I’d never even think of myself, but that could save me time. I’ve had exposure to Ant before now but don’t really know it, and I’m aware of the Capistrano project from the Rails crowd (which I understand works well for more than just Rails apps).

What I’m really looking for is recommendations and war stories. What have you used? Would you recommend it? Do build systems require so much configuration that I might as well just script this (probably fairly simple) task myself? My projects are in PHP, but the build system could be anything, so I’d value any input.