Search code examples
rubygitherokusinatrabuildpack

Access current git commit number from within Heroku app


I know the slug compiler removes the .git directory when creating a heroku slug, but is there any way to configure Heroku so that I can access the currently running git commit number from within my scripts?

I'd like to be able to have a small link on my sinatra app (run within Heroku) which says "running version e72fb274a0" (or something similar). How can I retrieve this, or force the slug compiler to add it to an environment variable?

PROGRESS:

I reckon the best way to do this is to make a custom buildpack which writes the git commit version number to the heroku slug before the .git directory is deleted.

I've tried to do this (see my fork of the ruby buildpack) but the line I've added – line 23 – doesn't seem to be doing the job. Heroku sees & uses the new buildpack, but doesn't seem to write the file to the slug.

Anyone have any idea why my custom buildpack isn't working as expected?

Thanks,

JP


Solution

  • You can run a script before deploy that store this information (maybe on a YAML)

    using these a = `ls` (note that is not ' "apostrophe" sign is ` "inverse accute" sign)
    the a variable will have the result of this bash command,
    so you can do git = `git log` and then find the information you want it and store it. So you will be able to retrieve it later.

    Did this helped ?