Heroku console shows latest shy hash from git deployment

I have a development branch hosted on Heroku, and we have a couple of people using this branch to search for errors, it would be nice to show the SHA-1 Hash from the commit, that the latter is deployed to Heroku, so that we know which errors belong to someone .

But I can not find a way to find this information. nothing in the env variable in the heroku launch console. Although the β€œreleases little hero” shows a list of deployment information, including the first few characters of the SHA-1 hash, it makes me think Heroku should store it, but I just can't find it. Somebody knows?

I understand that I did not actually pose the question as clearly as I should: I wanted to find the SHA-1 hash inside Rails on Heroku. How can I do something like this:

<h1><%= ENV['REV']</h1> 

Thanks!

+7
source share
3 answers

Treat Heroku just like any remote Git repository, you can use git ls-remote :

git ls-remote heroku

( heroku here is the remote name)

UPDATE:

Since the OP actually wants to get SHA in Ruby env, one possible way would be to use custom buildpack .

To get started, go to Heroku Ruby Buildpack and unlock it so you can create your own options. Now clone the fork and take a look at lib/language_pack/ruby.rb Add a new method, for example:

 def get_SHA #get SHA #save SHA to ENV, ala: ENV['SHA'] = retrieved_sha end 

How you are going to receive SHA is up to you. You can execute the git command and use the return value:

git log -1 --format="%H"

Or you can use the @avaynshtok tip and use Heroku pearls to use the releases method.

Then, as soon as you have a SHA, install it as ENV var.

Then find the compile method in ruby.rb and add the get_sha method at the end of it:

 def compile Dir.chdir(build_path) install_ruby setup_language_pack_environment allow_git do install_language_pack_gems build_bundler create_database_yml install_binaries run_assets_precompile_rake_task get_sha #your additional method end end 

Revert your changes back to GitHub and now go to the command line. You need to add a new var configuration to your Heroku application:

heroku config:add BUILDPACK_URL= git@github.com :<your GitHub username>/heroku-buildpack-ruby.git

Note that you need to make sure that you replace <your GitHub username> with ... well, <your GitHub username> , so you point to a forked repo.

Finally, run one last command that allows the Heroku labs function , which allows the slug compiler to access custom vars:

heroku labs:enable user_env_compile

You should now be tuned. So what is happening now? Well, when you click on Heroku, Heroku will get the changes, and then you will see that you have your own set of url buildpack. This way it will retrieve your own buildpack from GitHub and then use it to create the bullet. This means that after all default compilation commands have been executed, this will end with the get_sha method, which should set ENV var SHA to the corresponding SHA. You should now have access to this ENV var from Ruby to do what you will.

+10
source

You can get the release information using the Heroku gem: https://github.com/heroku/heroku

 c = Heroku::Client.new <LOGIN>, <PASSWORD> c.releases(<APPNAME>).last['commit'] 

Alternatively, you can authenticate using the API key:

 c = Heroku::Client.new '', <API_KEY> 

The downside is that you will need to store the login / password combination (or API key) somewhere (either in your application or in enoku Heroku).

You can also use the expanding hooks to get this information: https://devcenter.heroku.com/articles/deploy-hooks

+3
source

As a result, I used the Heroku Platform Hero API . This is a big long rewinder, but it is remembered, so you will only need to do this once for deployment, and also keep the mess with custom packages (uncomfortable) and deploy hooks (unsafe):

 def current_sha @current_sha ||= begin heroku = PlatformAPI.connect_oauth(ENV['HEROKU_TOKEN']) slug_id = heroku.release.list(ENV['HEROKU_APP']).last["slug"]["id"] heroku.slug.info(ENV['HEROKU_APP'], slug_id)["commit"] end end 
+1
source

All Articles