gogitversion
Go package to assist in embedding git tag based versioning into an application
Project Health Status
Quickstart
> go get https://github.com/prognoshealth/gogitversion
package main
import (
"fmt"
"github.com/prognoshealth/gogitversion"
)
func main() {
...
fmt.Printf("version: %s\n", gogitversion.Get())
...
}
> go build -ldflags "-X github.com/prognoshealth/gogitversion.version=0.0.1"
> ./myapp
version: 0.0.1
Git Describe Versioning
When no embedded version is provided gogitversion falls back upon a versioning
technique using git describe --tags --dirty
.
For more details on git describe
check out: https://git-scm.com/docs/git-describe
This versioning technique will reference the most recent tag set using git tag
.
For example:
# When the most recent tag matches the most recent commit with a clean working tree
> git describe --tags --dirty
v2018.07.03.115146
# When the most recent tag matches the most recent commit with a dirty working tree
> git describe --tags --dirty
v2018.07.03.115146-dirty
# When the most recent tag is 4 commits behind the most recent commit with a clean working tree
> git describe --tags --dirty
v2018.07.03.115146-4-gc3a421b
# When the most recent tag is 4 commits behind the most recent commit with a dirty working tree
> git describe --tags --dirty
v2018.07.03.115146-7-gc3a421b-dirty
This technique allows you to get very detailed information about the current code being executed within the application.
Expected Usage
During local development fall back upon git describe --tags --dirty
to provide
versioning information... by doing nothing except using git tag
's and go as you normally would.
> go build
When creating a release build embed the version as follows:
> go build -ldflags "-X github.com/prognoshealth/gogitversion.version=$(git describe --tags --dirty)"