Where do you store your Rails Application's version number?

前端 未结 8 1736
终归单人心
终归单人心 2021-01-30 05:41

We use the wonderful semantic versioning paradigm when versioning our rails app. One question I had was where is it best to store this number? I\'ve seen it stored in /l

8条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 06:20

    My strategy is to let your VCS tags do it for you (git shown here).

    Add this to your application.rb:

    # Only attempt update on local machine
    if Rails.env.development?
      # Update version file from latest git tag
      File.open('config/version', 'w') do |file|
        file.write `git describe --tags --always` # or equivalent
      end
    end
    
    config.version = File.read('config/version')
    

    You can then access the version anywhere in your app with Rails.configuration.version

提交回复
热议问题