Versioning Utilities
Understand how to implement automatic versioning for Go command-line utilities by leveraging Git commit hashes and Go linker flags. This lesson guides you through setting version variables at build time, integrating Git data dynamically, and applying these techniques in CI/CD environments to ensure unique and consistent version tracking.
We'll cover the following...
One of the most difficult tasks is to automatically and uniquely version command-line utilities, especially when using a CI/CD system. This lesson presents a technique that uses a GitHub value to version a command-line utility on the local machine.
Note: We can apply the same technique to GitLab—we need to search for the available GitLab variables and values and choose one that fits our needs.
This technique is used by both the docker and kubectl utilities, among others:
# docker versionClient: Docker Engine - CommunityCloud integration: 1.0.4Version: 20.10.0API version: 1.41Go version: go1.13.15Git commit: 7287ab3Built: Tue Dec 8 18:55:43 2020OS/Arch: darwin/amd64...
The output above shows that docker uses the Git commit value for versioning—we are going to use a slightly different value that is longer than the one ...