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

前端 未结 4 2029
别那么骄傲
别那么骄傲 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:55

    Long time ago I did this for subversion:
    in an initializer I put a global

    SVN_REVISION = `svn info | ruby -ne 'puts $1 if $_ =~ /^Revision: ([0-9]*)/'`
    

    and in the application layout:

    
    

    with git you could change the global to something like:

    git log -1 | ruby -ne 'puts $1 if $_ =~ %r{^Date:   (.+) \+\d+$}'
    

    Now thinking about it, it may be better to:

    • capistrano creates a configuration file (config/git_status.yml)
    • the initializers parses the configuration and sets variables

    I'm not sure, it's just an idea.

提交回复
热议问题