From c7e8e05706b774a28c697b8c9adad8dfd9b3f14f Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Fri, 5 Sep 2014 11:42:51 -0400 Subject: [PATCH 1/2] Capitalize bash variable and prefix with KUBE_ We intend to make these setable by the environment. This just does the renaming. --- hack/config-go.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hack/config-go.sh b/hack/config-go.sh index faed51ca266..eb65fed9ef5 100644 --- a/hack/config-go.sh +++ b/hack/config-go.sh @@ -34,31 +34,31 @@ kube::version_ldflags() { cd "${KUBE_REPO_ROOT}" declare -a ldflags=() - if git_commit=$(git rev-parse "HEAD^{commit}" 2>/dev/null); then - ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitCommit" "${git_commit}") + if KUBE_GIT_COMMIT=$(git rev-parse "HEAD^{commit}" 2>/dev/null); then + ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitCommit" "${KUBE_GIT_COMMIT}") # Check if the tree is dirty. if git_status=$(git status --porcelain) && [[ -z "${git_status}" ]]; then - git_tree_state="clean" + KUBE_GIT_TREE_STATE="clean" else - git_tree_state="dirty" + KUBE_GIT_TREE_STATE="dirty" fi - ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitTreeState" "${git_tree_state}") + ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitTreeState" "${KUBE_GIT_TREE_STATE}") # Use git describe to find the version based on annotated tags. - if git_version=$(git describe --abbrev=14 "${git_commit}^{commit}" 2>/dev/null); then - if [[ "${git_tree_state}" == "dirty" ]]; then + if KUBE_GIT_VERSION=$(git describe --abbrev=14 "${KUBE_GIT_COMMIT}^{commit}" 2>/dev/null); then + if [[ "${KUBE_GIT_TREE_STATE}" == "dirty" ]]; then # git describe --dirty only considers changes to existing files, but # that is problematic since new untracked .go files affect the build, # so use our idea of "dirty" from git status instead. - git_version+="-dirty" + KUBE_GIT_VERSION+="-dirty" fi - ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitVersion" "${git_version}") + ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitVersion" "${KUBE_GIT_VERSION}") # Try to match the "git describe" output to a regex to try to extract # the "major" and "minor" versions and whether this is the exact tagged # version or whether the tree is between two tagged versions. - if [[ "${git_version}" =~ ^v([0-9]+)\.([0-9]+)([.-].*)?$ ]]; then + if [[ "${KUBE_GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)([.-].*)?$ ]]; then git_major=${BASH_REMATCH[1]} git_minor=${BASH_REMATCH[2]} if [[ -n "${BASH_REMATCH[3]}" ]]; then From 428e0aaff0379dadbda9d3fc096370d99fc15a9c Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 4 Sep 2014 10:25:50 -0400 Subject: [PATCH 2/2] Allow setting of git_commit, version, and dirty via shell varables This is particularly useful if building from a tarball instead of from a checked out git repo (as all Linux distributions do) --- hack/config-go.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hack/config-go.sh b/hack/config-go.sh index eb65fed9ef5..e37c91bc90e 100644 --- a/hack/config-go.sh +++ b/hack/config-go.sh @@ -34,19 +34,21 @@ kube::version_ldflags() { cd "${KUBE_REPO_ROOT}" declare -a ldflags=() - if KUBE_GIT_COMMIT=$(git rev-parse "HEAD^{commit}" 2>/dev/null); then + if [[ -n ${KUBE_GIT_COMMIT-} ]] || KUBE_GIT_COMMIT=$(git rev-parse "HEAD^{commit}" 2>/dev/null); then ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitCommit" "${KUBE_GIT_COMMIT}") - # Check if the tree is dirty. - if git_status=$(git status --porcelain) && [[ -z "${git_status}" ]]; then - KUBE_GIT_TREE_STATE="clean" - else - KUBE_GIT_TREE_STATE="dirty" + if [[ -z ${KUBE_GIT_TREE_STATE-} ]]; then + # Check if the tree is dirty. default to dirty + if git_status=$(git status --porcelain 2>/dev/null) && [[ -z ${git_status} ]]; then + KUBE_GIT_TREE_STATE="clean" + else + KUBE_GIT_TREE_STATE="dirty" + fi fi ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitTreeState" "${KUBE_GIT_TREE_STATE}") # Use git describe to find the version based on annotated tags. - if KUBE_GIT_VERSION=$(git describe --abbrev=14 "${KUBE_GIT_COMMIT}^{commit}" 2>/dev/null); then + if [[ -n ${KUBE_GIT_VERSION-} ]] || KUBE_GIT_VERSION=$(git describe --abbrev=14 "${KUBE_GIT_COMMIT}^{commit}" 2>/dev/null); then if [[ "${KUBE_GIT_TREE_STATE}" == "dirty" ]]; then # git describe --dirty only considers changes to existing files, but # that is problematic since new untracked .go files affect the build,