Setting Release & Build No.’s Automatically
So recently with my http://kinto.sh project I decided that I really wanted to start pulling in the version and build number into the project so that I can assist people easier when they have issues.
Also with the addition of a new full on GUI and system tray app it made sense to add an About window with this information in it for the user. After googling around for how to pull in the tags properly I pretty well knew how to go about it, sadly I initially made wrong assumptions on that the tags would always appear a particular way regardless of which branch you are on or commit, so I had to rewrite the command a few times.
I do cheat a little, because technically a person I believe can roll back their commits so far that the latest tag is no longer relevant to the commit they are on and it would be pulled into the About screen with the wrong release number. I am sure there may be ways to mitigate this issue if I cared to, but to be honest I am not too concerned of people doing that and the purpose is more for binary releases that I plan to make in the future for Debian, Ubuntu, Arch and others and my own PPA on launchpad.
With no further ado here is the command I settled on.
echo "$(git describe --tag --abbrev=0 | head -n 1)" "build" "$(git rev-parse --short HEAD)" > ~/.config/kinto/version
Essentially I use git describe to get the latest tag and I use head just to make sure I only deal with one line. I also run a 2nd git command that simply gives me the short hash commit so that the build number references the exact commit. In the future if anyone files a complaint I can always ask them for this information and be confident if they are using the latest and if it is something I need to work on.