views:

50

answers:

2

On my website, in the footer, i want to clearly show which version of the code is live. I am using git as version control. It would be great to get some visual feedback to know which version is actually live.

I want to show some readable number, like a gem version number. I could create a VERSION file, which i manage and increase every time it is needed.

I am curious if there are any existing solutions already out there? It would be preferable if it could e.g. use tag information from git.

+1  A: 

Jeweler has some rake tasks that handle versioning pretty well for you. I have only used it for gems, but you can probably drop in a VERSION file and use the same rake tasks in a rails app. I have actually been thinking about doing the same thing for my app.. I will update this answer with more details if I get to it soon. For my gems I added a few new rake tasks that combine some of the jeweler tasks. Every time I have a new version I run one of the tasks and it increments the version (major,minor or patch), pushes my code to github and tags it all in one operation:

namespace :version do
  desc "create a new version, create tag and push to github"
  task :github_and_tag do
    Rake::Task['github:release'].invoke
    Rake::Task['git:release'].invoke
  end

  desc "bump patch push to github"
  task :patch_release do
    Rake::Task['version:bump:patch'].invoke
    Rake::Task['version:github_and_tag'].invoke
  end

  desc "bump minor push to github"
  task :minor_release do
    Rake::Task['version:bump:minor'].invoke
    Rake::Task['version:github_and_tag'].invoke
  end

  desc "bump major push to github"
  task :major_release do
    Rake::Task['version:bump:major'].invoke
    Rake::Task['version:github_and_tag'].invoke
  end
end

get jeweler if you dont have it and create a fake gem, put it on github and play around with the tasks until you get a feel for them. I took me a few tries (and peeks at the source) to fully understand what it was doing.

If you run these tasks every time you have a new version, your VERSION file will be in sync with your github project. If it was me, I would just read in the version number from the file and use something like settingslogic to set up a constant.. or you can set it up in an initializer. That way, you know that every time you restart your app, it will read the correct version

cowboycoded
I am using jeweler for my gems, but somehow i didn't make that connection. That is a very good idea. Thank you. I am still interested to hear if there are other options ...
nathanvda
+2  A: 

I found a gem that actually does exactly what i need: version. It allows to manage the version dead-easy, with the needed rake-tasks without the coupling to jeweler, and also allows to tag github in the process.

When developing a gem, i keep using jeweler, but for my rails-projects this is just what i need.

For more info see the gem's documentation.

nathanvda
Very interesting, especially when working Agile... we create a new version each month!
huug