问题
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)
回答1:
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.
回答2:
If you use git
, you can create a static variable in your environment.rb
file that pulls the current tag name from git. If you're using something like git flow, this works great.
Add to environment.rb
:
APP_VERSION = `git describe --always` unless defined? APP_VERSION
Now you can <%= APP_VERSION %>
in your views. N.B. that this doesn't work on Heroku.
Source: http://blog.danielpietzsch.com/post/1209091430/show-the-version-number-of-your-rails-app-using-git
回答3:
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.
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/1047943/best-way-to-version-a-rails-app