Tuesday, October 19, 2010

RSS Feed for SVN Changelog

I wanted to create an RSS feed for the SVN logs of a wallpaper site script lately. I've been keeping track of my progress on the feeds over at Ozzu in this thread.

So far I have the feed and an archive of the revisions being automatically generated and uploaded to the remote server daily.

Having an RSS feed for the SVN commit history presented an interesting problem where I couldn't really update the script_version field in the scripts schema.sql file without clogging up my revision history with worthless updates about the version number being updated.

So, I wrote a small script that exports a copy of the script, retrieves the SVN revision number from the repo, then updates schema.sql with the correct version number before finally packaging script for me.

In case anyone's curious, here's the code for that. This little script lives in my working copy on my workstation, not under version control.

#!/bin/bash

echo "Exporting HEAD revision..."
svn -q export http://192.168.1.102/svn/wallpaper-script

echo "Updating working copy..."
svn -q update

php -r '
$properties = `svn info -r HEAD`;
if(preg_match("#^revision:\s*(\d+)\s*$#im", $properties, $revision))
{
echo "Updating script version in schema.sql to 2.{$revision[1]}...", PHP_EOL;
$schema = file_get_contents("wallpaper-script/install/schema.sql");
$schema = str_replace("script_version'\'', '\''2.0'\'')", "script_version'\'', '\''2.{$revision[1]}'\'')", $schema);
file_put_contents("wallpaper-script/install/schema.sql", $schema);

echo "Compressing package...", PHP_EOL;
shell_exec("tar zcf wallpaper-site-script_2.{$revision[1]}.tar.gz wallpaper-script");
}
'

echo "Cleaning Up..."
rm -rf wallpaper-script

echo "Done."

No comments: