Reflecting Heroku push version within the app

后端 未结 9 629
故里飘歌
故里飘歌 2021-01-30 09:17

Every time I push my app to heroku I see the line

-----> Launching... done, v43

Is there a way to make that version number apear within the

9条回答
  •  遥遥无期
    2021-01-30 09:54

    Why would you want to depend on running a command after every push? The accepted answer is worse than setting the config yourself.

    Instead add to your Gemfile:

    gem 'heroku-api'
    

    Add your App name and API key to the Heroku config:

    $ heroku config:add HEROKU_APP_NAME=myapp HEROKU_API_KEY=bp6ef3a9...
    

    Then put something like this in config/initializers/heroku.rb:

    unless (app_name = ENV["HEROKU_APP_NAME"]).nil?
      require 'heroku-api'
    
      heroku  = Heroku::API.new(:api_key => ENV["HEROKU_API_KEY"])
      release = heroku.get_releases(app_name).body.last
    
      ENV["HEROKU_RELEASE_NAME"] = release["name"]
    end
    

    Finally:

    puts ENV["HEROKU_RELEASE_NAME"]
    => v42
    

    Now it's fully automated. You can forget about it and continue to work on your app.

提交回复
热议问题