Rails 3 app, How to get GIT version and update website?

前端 未结 4 1979
别那么骄傲
别那么骄傲 2021-02-08 17:59

I am deploying my rails 3 app using capistrano, and I want to get the git version (and date information) and update my website\'s footer with this.

How can I do this?

4条回答
  •  时光取名叫无心
    2021-02-08 18:50

    Often one does not deploy into a git repository, but into a release which does not contain any repository information:

    Capistrano stores a revision file with each successful deployment which is the git commit sha. This file is called REVISION and can be found in the root of the deployment directory.

    In config/initializers of your Rails app, create a file: deploy_version.rb with something like:

    if File.exists?('REVISION')
      APP_REVISION = `cat REVISION`
    else
      APP_REVISION = 'unknown'
    end
    

    Or if sure that outside of deployment there is always a git repository one can replace the last assignment with

    if File.exists?('REVISION')
      APP_REVISION = `cat REVISION`
    else
      APP_REVISION = `git describe --abbrev=6 --always --tags.`
    end
    

提交回复
热议问题