Stack Overflow-style Rails app versioning
Dec 23, 2016
techHours ago, I was searching for ways to put a version number to my Rails app. SemVer is good but I want other way of versioning the app so I found this tutorial.
However, it didn’t work at all so I fixed it. Here’s the code:
config/initializers/version.rb
class LemonadePubSys::Application
APP_VERSION = `git --work-tree="#{Rails.root}" log -1 --date=short --format="%ad-%h"`.gsub!(/-/,'.').strip
end
The difference between Khaja’s and mine is that I replaced shell command sed
with the Ruby’s gsub!
so that the command will work properly. I also added strip
to remove newlines and the code was put in an initializer file since putting it into application.rb
file won’t recognize it.
This is working for Rails 5 and above.