So, thanks to Redditor vruin, I learned that there’s an easier way to add a version number than what I was doing:

https://www.atatus.com/blog/golang-auto-build-versioning/

The way described in the blog post uses the -ldflags go build parameter instead of my relatively convoluted approach of using go generate to create a version.go file. I just needed to make a couple of changes to the version scheme to make it work for me:

GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=`git describe --tags --long`" -o release/terminator

The next thing I needed to do was to package up those builds and push them back out to Github. I followed some excellent instructions, just making a few changes to take out the need for a make file:

https://loads.pickle.me.uk/2015/08/22/easy-peasy-github-releases-for-go-projects-using-travis/

I’ve put this into practice on my “Terminator” application at https://github.com/a-h/terminator and I’m now confident I can deploy new distributions of my applications automatically.

Advertisements