Heroku: Display Git Revision Hash and Timestamp in Views?

前端 未结 5 1796
盖世英雄少女心
盖世英雄少女心 2021-02-15 15:22

Let\'s say I have a Rails application deployed on Heroku. How can I display these pieces of information in my views?

  • The Git hash for the last revision
  • Th
5条回答
  •  孤街浪徒
    2021-02-15 15:59

    Another way to do it is to deploy with a rake task that gets the version info you want from the local repo and updates an environment variable on the Heroku side. Then you can use a tag, or a commit hash, or anything else, without having to rely on behaviors on the Heroku side.

    For example, if you wanted to use the latest tag, in your rake task:

    def app_version
      %x[git describe --tags --abbrev=0].strip
    end
    

    Then in the body of your task:

    run "git push blah:blah blah"
    run "heroku config:add APP_VERSION=#{app_version}"
    

    I would like to be able to get that info straight from git on Heroku, rather than sneaking it in indirectly, but I've never been able to figure out how to do that.

提交回复
热议问题