Three different options, best ...
SOURCE_VERSION environment variable (build time)
Starting April 1, 2015, the SOURCE_VERSION environment variable is available for assembly on Heroku. For git-push builds, this is the git commit SHA-1 of the source, which is being built:
https://devcenter.heroku.com/changelog-items/630
(thanks @srtech for pointing out that !)
/etc/heroku/dyno metadata file (runtime)
Heroku has beta functionality for writing the /etc/heroku/dyno metadata file to your dyno executable. If you support email support, you can probably add to the beta. Here is the place where Geroku uses it:
https://github.com/heroku/fix/blob/6c8ab7a/lib/heroku_dyno_metadata.rb
The content is as follows:
{ "dyno":{ "physical_id":"161bfad9-9e83-40b7-b385-78305db2f168", "size":1, "name":"run.7145" }, "app":{ "id":null }, "release":{ "id":50, "commit":"2c3a0b24069af49b3de35b8e8c26765c1dba9ff0", "description":null } }
.. therefore release.commit is the field you are in.
SBT specification: use sbt-heroku to create slug locally
My initial solution was to use the sbt-heroku published by Heroku themselves. This means that deployment is no longer performed using git push (with a pool compiled on Heroku's own infrastructure), but instead compiles slug locally and loading it directly into Heroku. Since slug is compiled locally, there is git information in my working repo, and the build process can easily identify the commit id and paste it into the application code.
The cork is significantly larger than git diff (90 MB vs 0.5 KB), but in addition, the solution works quite well. I actually use Travis for continuous deployment, and so Travis did sbt stage deployHeroku for me (the git commit identifier available in this environment when building), that is, I could git-push from my laptop on the go, and Travis will do a lot of slug loading in Heroku