Framework auto-updates

September 7, 2009

One of the more annoying things about web frameworks I’ve used is that if you started a project and you suddenly need a feature and need to update or slide back a version, it’s a pain in the posterior.

In ploof I’m trying to solve this problem with diffs and patches for the core files.

The ploof command, available on the command line, provides this functionality. Even though ploof doesn’t have any releases (proper), you can tell your ploof export to update to a particular revision:

./ploof update trunk

or

./ploof update 1.0

(note that as of this writing there is no 1.0 version, so trunk is all you get)

The essential strategy is to export another version in the resource subdirectory, run a diff against what you currently have installed, and patch it automatically.

Here’s the code:

function generate_patch($version= "trunk")
{
    if (opendir("resource/updates"))
        exec("rm -rf resource/updates");

    // export a copy of the code off the server:
    exec("mkdir resource/updates");
    if ($version != "trunk")
        $version= "branches/".$version;

    exec("svn export http://ploof.googlecode.com/svn/$version ./resource/updates/svn");

    // build patch files:
    exec("diff -rupN -x .svn ./core ./resource/updates/svn/core > ./resource/updates/core.patch");
    exec("diff -rupN -x .svn ./config/config.default.php ./resource/updates/svn/config/config.default.php > ./resource/updates/config.patch");
    exec("diff -rupN -x .svn ./ploof ./resource/updates/svn/ploof > ./resource/updates/ploof.patch");
}

function patch()
{
    // apply the patches:
    exec("patch -p1 < ./resource/updates/core.patch");
    exec("patch -p1 < ./resource/updates/config.patch");
    exec("patch -p1 < ./resource/updates/ploof.patch");
}
function update($version= "trunk")
{
    generate_patch($version);
    patch();
}

I separated the update() method into patch() and generate_patch() for testing purposes.

This isn’t perfect (it needs to address core CSS/HSS/JS merging, and needs to ignore other VCS’s), but it’s a start toward better framework integration into our normal development workflow.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.