Improve generation of version information from the git tree

Detect whether the tree is dirty and append a "-dirty" indication to the
git commit (common practice with other repos, e.g. kernel, docker.)

Properly handle the case where a git tree is not found (e.g. building
from archive.)

In the sed expression, look for the variable to be updated
(commitFromGit) instead of hardcoding a line number.

Tested:

- Built from a dirty tree:
    $ output/go/bin/kubelet -version
    Kubernetes version 0.1, build 2d784c684c75-dirty

- Built from a clean tree:
    $ output/go/bin/kubelet -version
    Kubernetes version 0.1, build 505f23a31172

- Built from an archive:
    $ hack/build-go.sh
    WARNING: unable to find git commit, falling back to commitFromGit = `(none)`
    $ output/go/bin/kubelet -version
    Kubernetes version 0.1, build (none)

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
This commit is contained in:
Filipe Brandenburger
2014-07-30 16:01:15 -07:00
parent 7e56609139
commit de405ac126
2 changed files with 25 additions and 7 deletions

View File

@@ -19,5 +19,5 @@ package version
// This file is the template for the machine-edited autogenerated.go.
// Do not modify this file without also modifying hack/version-gen.sh.
var (
placeholder interface{}
commitFromGit = `@@GIT_COMMIT@@`
)