1

We are looking for a way to inject the current commit hash and message into a site. It is not possible to do that using a Git hook, because writing to a file would change the commit hash.

So, is it possible to write the commit hash and message to the file system when it is deployed to Heroku? This could work similarly to the assets compilation process.

I think there are 2 parts to the problem:

  1. Writing to the file system during the deploy.
  2. Getting the hash and message of the deploy.
B Seven
  • 44,484
  • 66
  • 240
  • 385
  • 1
    Looks like you have to customize the `git push heroku master` step with a custom script, as explained here: http://stackoverflow.com/a/14924922/4625365 – Matt Brictson Mar 06 '15 at 01:56
  • There are some good ideas there, but I can see how the commit hash ENV and the commit hash can get out of sync. It would be cleaner to inject a unique ID into the code. It seems that it is not possible to use the commit hash, but an incremented commit number might work. – B Seven Mar 06 '15 at 02:42

2 Answers2

1

I think a better way to go about this is to use the Heroku Platform API. Not sure if you're familiar with this, but Heroku maintains a list of every single release you've ever done, and you can pragmatically access this information (Git hash included), for whatever purposes you want.

If you'd like to see this from the command line, try this:

$ heroku releases
== postgression-api Releases
v173  Deploy 3f25d04                 r@rdegges.com  2014/07/13 17:55:46
v172  Deploy 5bae169                 r@rdegges.com  2014/07/13 17:49:02
v171  Deploy 0a71096                 r@rdegges.com  2014/07/13 17:42:11
v170  Deploy a25b1b1                 r@rdegges.com  2014/07/13 17:16:48
v169  Deploy 800b0a7                 r@rdegges.com  2014/07/13 17:12:43
v168  Deploy 60dab8d                 r@rdegges.com  2014/07/13 17:07:48
v167  Add-on provider config update  pgbackups      2014/04/19 04:36:32
v166  Deploy bfddd2f                 r@rdegges.com  2014/01/12 22:54:34
v165  Deploy 360c437                 r@rdegges.com  2014/01/12 22:51:00
v164  Deploy daf2346                 r@rdegges.com  2014/01/12 22:39:19
v163  Deploy b90f1d6                 r@rdegges.com  2014/01/12 21:19:33
v162  Deploy 64ea061                 r@rdegges.com  2014/01/12 20:32:29
v161  Deploy caa1298                 r@rdegges.com  2014/01/12 20:28:01
v160  Deploy 85b7250                 r@rdegges.com  2014/01/12 20:25:04
v159  Deploy a59a9d7                 r@rdegges.com  2014/01/12 20:19:36

Here's a link to the specific API docs you need: https://devcenter.heroku.com/articles/platform-api-reference#release

Hope that helps!

rdegges
  • 32,786
  • 20
  • 85
  • 109
  • Yes, that's a good idea. But how to inject it into an HTML page? – B Seven Mar 06 '15 at 19:23
  • Basically you write a server-side view that makes the API call to Heroku to get the hash, then returns that when it renders the HTML. This is the only way to make it happen. – rdegges Mar 06 '15 at 21:47
0

Use a deploy hook to post to your database and just store the hash in the database.

jBeas
  • 926
  • 7
  • 20
  • Yes, I thought of this but I don't think it is a good solution because: 1. There would be an API call that has nothing to do with the app. 2. It would be easy to get out of sync if the hook or API call fails. 3. I already have a deploy hook. – B Seven Mar 06 '15 at 01:41