CEO and founder of Lingohub. Envisioning a multilingual digital world. Email me if you have questions about how Lingohub can help you take your products global.

Helmut Development 0 Comments

SHARE

Use Git commit sha to keep track of running version in production

Git is the de facto standard version control system in software development. For organizing Git Logoour issues and keeping track of the status we use the Kanban view of Jira.

Our last two columns on our Kanban board are:

  • Awaiting deploy
  • Done

All issues in the column “Awaiting deploy” are fully implemented and tested. The code has been reviewed by a 2nd developer and as result of the review process merged from the feature branch into our master branch. They are ready to be released to production.

Releasing to production is merging master branch into production branch and push it to our git repository. After this step all issues are moved from the column “Awaiting deploy” to “Done“. Now this column holds all issues that are new in production.

Our deployment script on server side will now pull this branch and restart the servers with the new code. A common way how to deploy Ruby On Rails applications. That means that the full repository is available on our production servers. This comes in handy if we want to determine the actual HEAD commit of our production branch.

We do this by calling “git rev-parse HEAD“.

To have this information available in our application we use the following code in a Rails initializer:

if Rails.env.production?
   commit_hash = `git rev-parse HEAD 2>/dev/null`.to_s.strip
   APP_VERSION = Time.now.utc.strftime("%Y%m%d-%H%M-") + commit_hash[-8..-1]
else
   APP_VERSION = Time.now.utc.strftime("%Y%m%d-%H%M-development")
end

To have this information easily accessible we render this information as html meta tag into all our sites:

<meta name="lingohub-version" content="<%= APP_VERSION %>"/>

results in:

<meta name="lingohub-version" content="20130412-1646-0ab4b155"/%>

This version will be now assigned to all issues in the “Done” column. We now know the date and the last git commit sha that runs in production.

For other SCMs these CLI commands would do the trick:

  • SVN: svn log -r HEAD
  • Mercurial: hg id -i

links: