A couple weeks ago I posted about moving our SVN repositories to a hosted solution at
Just a quick note to say Merry Christmas and a very happy and prosperous new year to all my readers (all 2 or 3 of you that I know of). We’ve been having family Christmas celebrations for a little over a week now due to our extended family being spread over two states. Tomorrow morning my wife and I (like millions of other parents around the world) will get to watch our kids’ faces light up with the magic of Christmas morning. It’s been a wild and busy year that has gone by too quickly, but it’s really nice to slow down for a few days this week and spend time with family. Here’s hoping that each of you get a chance to have a special holiday with friends and family. Merry Christmas, Happy New Year and we’ll see you on the other side of the ball dropping in Times Square.
I recently decided to outsource my souce code management to CVSDude. I had been running SVN on my VPS that I have at Slicehost and that had been running okay. However, I’m only good enough at SVN administration to get the server up and running and create a few repositories and there were other things that I needed to do with SVN that I frankly didn’t have time to learn how to do.
One of the things that I’d heard talked about that made life much easier was using Subversion’s various hooks to automate some things around different SVN events. I emailed tech support asking how we could configure the “post-commit” hook to update the files on my VPS each time I made a commit into the SVN module. The tech told me that they do this by configuring an HTTP call to a page (or script etc) on your server. That page then triggers an SVN update of the specific module.
After hearing this, I began thinking about how to use CFEXECUTE to trigger the SVN update and was actually surprised how simple it was. My VPS runs on Fedora Core 6, so, like any *nix operating system, you need to make sure permissions on the files are set so that the user which runs ColdFusion can write to the directories. Once that was accomplished, all it took was a few lines of code and we’re ready to start receiving HTTP callbacks from CVSDude’s servers.
CVSDude structures their SVN URLs in the format http://username-svn.cvsdude.com/modulename (or https://). All my modules are named in reverse domain order for the web site that it is for (for example, this one is ws.skaggsfamily.dan). I had already checked out all my modules into a specific directory.
The HTTP callback from CFSDude’s server has 4 URL parameters that they send over: root (full path to module), author (user), revision and date. So all I really had to do was grab the URL.root value and extract the name of the module, pass that to the CFEXECUTE tag and, voila, automatic updating of the module immediately after the commit.
There were only 2 gotchas that I had to figure out:
- Put the full path to the svn executable
- Add in your username and password to the string in the arguments attribute of CFEXECUTE
The code that I used is below. I’m sure there’s more that I could have done with it, but this is a good start I think.
<cfif structKeyExists(URL, “date”) AND URL.date NEQ “” AND structKeyExists(URL,”author”) AND URL.author NEQ “” AND structKeyExists(URL, “revision”) AND URL.revision NEQ “” AND structKeyExists(URL, “root”) AND URL.root NEQ “”> <cfset module = replaceNoCase(URL.root, “http://username-svn.cvsdude.com/”, “”)> <cfexecute name=”/usr/bin/svn” arguments=”up /var/sites/#module# –username yourUserName –password yourPassword” timeout=”300″ variable=”result”> </cfexecute> <cflog log=”Application” type=”information” text=”#URL.author#:#URL.root#:#URL.revision# – #result#”> <cfmail to=”firstname.lastname@example.org” from=”email@example.com” subject=”Server updated successfully”> The server has been successfully updated with your lastest changes. Details of the update are below: Date: #URL.date# Module: #URL.root# Revision: #URL.revision# Results: #result# </cfmail> </cfif>