Build numbers
If I want to track down build artifacts, the conventional approach is a monotonically increasing integer. Every time I make a build, this integer gets bumped and baked into the artifact. Then a commit is created, and optionally a git tag too. Later, if I need to trace the artifact back, I find the commit that contains that integer.
But do I really need to maintain this separate state? Is there some other way to reference the exact place in git history?
Well, of course, the commit SHA is right there.
All I need is:
$ git rev-parse --short HEAD
and I'll get back a unique string of 7 (or more) characters that points to my latest commit:
12790c3
For the browser extension that I've been working on for the past couple
of months, the artifact I'm shipping is, in essence, a sensible-named
.zip file that contains all the resources.
Until recently, I had no build numbers attached to the artifacts. Small
changelogs + semantic versioning were good enough. The
.zip looked like this:
$ENV-$NAME-$VERSION.zip
And now, I'll append the commit SHA as the build identifier:
$ENV-$NAME-$VERSION-$COMMIT_SHA.zip
For example:
alpha-foobar-1.2.0-12790c3.zip
No extra state to maintain, no separate counter. The identifier I needed was already there, all I had to do was use it.