2019-07-25 WG follow-up: injecting versioning information at build time

Jacob Blain Christen (Intel)

As discussed in this morning’s call, there are extant examples of injecting versioning information into your binaries at build time, most of which leverage `git describe`. I mentioned Consul and jq and have since poked around for some pointers to share.


Consul is built with gox which is a go toolchain wrapper that Mitchell Hashimoto wrote to deal with various shortcomings of early 1.x go. Don’t let that get in the way of understanding that gox does to pass through many command-line switches to `go build` and specifically to our interest -ldflags. All of this is to say, focus on the ldflags callout and realize that the Consul GNUMakefile is eventually invoking the go toolchain.


This link shows how Consul is invoking `git describe`:



and this link shows how the Consul build script makes use of the exported GOLDFLAGS envvar:




Another good example is jq which is written in C. This link shows a utility script that invokes `git describe`:



and this link shows how that information is used to generate a version.h header:




These represent common patterns in my experience. We would probably want to lift from the Consul project how it invokes `git describe`, e.g. `git describe --tags --always --match "v*"` because this makes it more explicit that we only care about our semver information embedded in tags. The `--always` tells git describe to fallback to a 7 character sha prefix (instead of exiting with an error) if there are no matching tags which enough information for automation to assume and inject a default initial value for the version (if so desired).


I am happy to discuss this further and/or develop a plan forward via working session(s) but I hope this is at least a decent primer on what other projects our in the world are doing to inject version at build time.

Join EdgeX-TSC-DevOps@lists.edgexfoundry.org to automatically receive all group messages.