Treat Heroku just like any other remote Git repo - you can use git ls-remote
:
git ls-remote heroku
(heroku
here being the remote name)
UPDATE:
Since the OP is actually looking to acquire the SHA in the Ruby env, one possible way would be to use a custom buildpack.
To get started, head over to Heroku's Ruby Buildpack and fork it so you can make your own variations. Now clone your fork and take a look at lib/language_pack/ruby.rb
. Add a new method, something like:
def get_SHA
#get SHA
#save SHA to ENV, ala: ENV['SHA'] = retrieved_sha
end
How you go about getting the SHA is up to you. You could execute a git command and use what's returned:
git log -1 --format="%H"
Or you could use @avaynshtok's advice and use the Heroku gem to use the releases
method.
Then, once you have the SHA, set it as an ENV var.
Next, find the compile
method in ruby.rb
, and add the get_sha
method to 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
Push your changes back up to GitHub, and now head over to the command line. You'll need to add a new config var to your Heroku app:
heroku config:add BUILDPACK_URL=git@github.com:<your GitHub username>/heroku-buildpack-ruby.git
Note that you'll need to make sure you've replace <your GitHub username>
with...well, your GitHub username, so you are pointing at your forked repo.
Finally, execute one last command that enables a Heroku labs feature that allows the slug compiler access to user vars:
heroku labs:enable user_env_compile
Now you should be all set. So what exactly happens now? Well, when you push to Heroku, Heroku will receive the changes, and then see that you have a custom buildpack url set. So it'll fetch your custom buildpack from GitHub, and then use that to create the slug. That means that once it runs through all of the default compile commands, it'll end with your get_sha
method, which should set the ENV var SHA
to the appropriate SHA. Now you should have access to that ENV var from within Ruby, to do with what you will.