views:

191

answers:

4

What would be the best way to version a rails application? We want to start to get into more structured testing cycles and having a set version per build is a part of that. We use subversion but I would like to avoid using revision numbers for versions. Is there an easy way to do this automatically? Or should I just define a app_version method in the application helper?

(We are using subversion for source control)

A: 

The app-version plugin (http://github.com/toland/app_version/tree/master) allows you to specify various components of an application version. You could then include the subversion revision as a component of the build without it being the dominant part.

You could also, as part of your build/test workflow, increment another component of the version.

Shadwell
+1  A: 

Ithink this should be the responsibility of your source control system. I'd use a tag for each version, then you can create a helper method that just writes the tag out in your app (say, in the footer):

def put_version
  "<p id='version'>#{$$TAG_NAME}</p>"
end

Can't remember the syntax for inserting the tag name.

Mr. Matt
+3  A: 

You can use subversion keywords:

Essentially, you could have a helper method...

def app_version
    "$Id$"
end

$Id$ is a keyword which svn will expand (the link above has others you could use). Now, we set the keywords property on that file to let svn know that it should be replacing keywords (let's assume application_helper.rb):

svn propset svn:keywords "Id" application_helper.rb
svn ci application_helper.rb

Now if you look at application_helper.rb it'll read (something like this, with the version, date, user name changed)

def app_version
    "$Id: application_helper.rb 282 2009-06-26 10:34:17Z root $"
end

Obviously, you could assign this to a variable and parse it to the required format, included it in your view templates etc. Or do the same thing but instead of application_helper.rb, just use a file called VERSION in your root dir.

hopeless
Upvoted. I came here to say precisely this.
$1 if "$Revision$".match(/Revision: (\d+) /) ... If you add "Revision" to the svn:keywords, then this will get updated with every SVN revision (not just when the current file is updated) and it will parse out only the revision.
nertzy
+1  A: 

You could either version by labelling your git / svn branch ... or, best way, a constant in the environment file, just like Rails does:

MY_APP_VER = 0.1

Why would you use the application helper? You can always get at that variable from your application helper should you need to display it onscreen. But, that seems silly to have logic belonging to the configuration of your entire application inside a helper method.

Omar Qureshi