Automating SVN Tagging

I’ve been using the SVN version control system for a couple years now to maintain the code for the WordPress plugins I write. Using a version control system is a fantastic tool that allows me to write and release great code. However, this post is not about how SVN is spectacular and everyone should use it whenever they write code of any sort (although they should). This post is about automating SVN tagging.

But first, a quick overview of SVN and how things are done. There are three main directories for each plugin that I write: trunk, tag, branch.

‘Trunk’ is the main code area and is where all primary and active development of code occurs. The latest version of any plugin can be found in the Trunk folder.

‘Branch’ is similar to Trunk, however it’s mostly used for side development. It’s actually exactly the same as Tag, except that development continues in a Branch.

‘Tag’ is where copy of milestones are kept. For me, this means versions of plugins that I release. You can browse the tag folder and find all the versions of a plugin I’ve created and download them if you wanted. It’s similar to a Branch, but development is not continued.

I rarely create branches. I think this is mostly because I’m the only official contributor and there are not other developers working on them at the same time. So other then committing changes to the trunk, the only other operation I perform on a regular basis is tagging. The issue with tagging, though, is that it’s a tedious and repetitive process that should be automated in SVN for large sets of files, but isn’t.

This annoys me.

So I created a solution. I downloaded the SVN command line version and then wrote the following Batch file:

<br />
:input<br />
set TAG=<br />
set /P TAG=Version Tag: %=%<br />
if &quot;%TAG%&quot;==&quot;&quot; goto input<br />
echo Creating the version %TAG%<br />
set BASEURL=http://svn.wp-plugins.org/countdown-timer<br />
svn mkdir %BASEURL%/tags/%TAG%/ -m &quot;Version %TAG% tag&quot;<br />
set FILE=afdn_countdownTimer.php<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=afdn_countdownTimer.po<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=afdn_countdownTimer.po<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=afdn_countdownTimer-es_ES.mo<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=afdn_countdownTimer-es_ES.po<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=afdn_countdownTimer-sv_SE.mo<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=afdn_countdownTimer-sv_SE.po<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=fergcorp_countdownTimer_java.js<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=readme.txt<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=screenshot-1.png<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />
set FILE=screenshot-2.png<br />
svn copy %BASEURL%/trunk/%FILE% %BASEURL%/tags/%TAG%/%FILE% -m &quot;Version %TAG% tag&quot;<br />

It’s not terribly pretty, in fact I’d argue that it’s downright ugly. But. It does get the job done. One of the things that I want to do is figure out a better way to do the “svn copy” part of the operation since it’s repetitive. However, Batch files don’t appear to handle arrays at all. Although they do handle loops (I believe) and I could just pass the file names in as parameters. I may end up converting the thing to VBScript or write little C++, although it’s been ages since I’ve done either.