Reflecting Heroku push version within the app

后端 未结 9 628
故里飘歌
故里飘歌 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 10:04

    Following @jassa answer - but using the more recent PlatformAPI

    if (app_name = ENV["HEROKU_APP_NAME"]).present? and ENV['HEROKU_API_KEY'].present?
      require 'platform-api'
      heroku = PlatformAPI.connect(ENV['HEROKU_API_KEY'], default_headers: {'Range' => 'version ..; order=desc'})
      released_at_s = heroku.app.info(app_name)['released_at']
      released_at_d = Time.parse(released_at_s).strftime('%Y-%m-%d')
      release = heroku.release.list(app_name).first
      deploy_v = release['description']
      version = release['version']
      ENV['HEROKU_RELEASE_NAME'] = "#{version} (#{deploy_v}) #{released_at_d}"
    end
    
    0 讨论(0)
  • 2021-01-30 10:13

    I am using Codeship so I plan on just adding this to the push config:

    heroku config:add HEROKU_RELEASE_VERSION=$(heroku releases | head -2 | awk 'NR==2' | awk '{print $1}')

    Note that the other similar answer is invalid since it is grabbing some of the later versions (it uses tail instead of head) and it tries to set it to two versions instead of just one (ie: v100 \n v101).

    0 讨论(0)
  • 2021-01-30 10:14

    AFAIK you can only get the version via the CLI:

    heroku releases --app <YOUR_APP_NAME>
    

    You could do this via the Heroku gem from you app, but this is probably more trouble that it's worth.

    0 讨论(0)
提交回复
热议问题