You are here: Home » Ruby on rails » Add tags with application version into your git branch and show it in view

Add tags with application version into your git branch and show it in view

Featured Image

You can look at “A successful branching model” for very good reference about layout of branches and worfklow on application in git.

According to this you add tags to commits in master branch. How to add tag with version?

1
git tag -a v1.4 -m 'my version 1.4'

Or we can add tag to existing commit by using commit hash:

1
git tag -a v1.2 -m 'version 1.2' 9fceb02

How can I add automatic version number in appliaction footer?

You can read tag from GIT and create global variable in Rails. This way you can use version number in any place. For example in layout.

Following example from http://stackoverflow.com/questions/9073446/where-do-you-store-your-rails-applications-version-number

Edit your application.rb file and place:

 Rails |  copy code |? 
1
if Rails.env.development?
2
# Update version file from latest git tag
3
File.open('config/version', 'w') do |file|
4
file.write <code>git describe --tags --always
# or equivalent
end
end

config.version = File.read(‘config/version’)

Version file will be update every time you start your server – for example Unicorn. It will work only for development environment.

Now you can use this variable in your app view – it may by footer in app/views/layouts/application.html.haml (HAML in my example):

 Rails |  copy code |? 
1
%p.text-right #{MyAPP::Application::config.version}

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *

Możesz użyć następujących tagów oraz atrybutów HTML-a: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">