Skip to content

Commit

Permalink
Use -ldflags to set git commit version
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Aug 25, 2014
1 parent 0a06de6 commit 9336373
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 72 deletions.
6 changes: 3 additions & 3 deletions hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ hackdir=$(dirname "$0")
# Go to the top of the tree.
cd "${KUBE_REPO_ROOT}"

# Update the version.
"${hackdir}/version-gen.sh"
# Fetch the version.
version=$(gitcommit)

if [[ $# == 0 ]]; then
# Update $@ with the default list of targets to build.
Expand All @@ -41,4 +41,4 @@ for arg; do
binaries+=("${KUBE_GO_PACKAGE}/${arg}")
done

go install "${binaries[@]}"
go install -ldflags "-X github.com/GoogleCloudPlatform/kubernetes/pkg/version.commitFromGit '${version}'" "${binaries[@]}"
21 changes: 21 additions & 0 deletions hack/config-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@
# This script sets up a go workspace locally and builds all go components.
# You can 'source' this file if you want to set up GOPATH in your local shell.

# gitcommit prints the current Git commit information
function gitcommit() {
set -o errexit
set -o nounset
set -o pipefail

topdir=$(dirname "$0")/..
cd "${topdir}"

# TODO: when we start making tags, switch to git describe?
if git_commit=$(git rev-parse --short "HEAD^{commit}" 2>/dev/null); then
# Check if the tree is dirty.
if ! dirty_tree=$(git status --porcelain) || [[ -n "${dirty_tree}" ]]; then
echo "${git_commit}-dirty"
fi
else
echo "(none)"
fi
return 0
}

if [[ -z "$(which go)" ]]; then
echo "Can't find 'go' in PATH, please fix and retry." >&2
echo "See http://golang.org/doc/install for installation instructions." >&2
Expand Down
41 changes: 0 additions & 41 deletions hack/version-gen.sh

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/version/template.go.tmpl

This file was deleted.

10 changes: 9 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"fmt"
)

// commitFromGit is a constant representing the source version that
// generated this build. It should be set during build via -ldflags.
var commitFromGit string

// Info contains versioning information.
// TODO: Add []string of api versions supported? It's still unclear
// how we'll want to distribute that information.
Expand All @@ -41,5 +45,9 @@ func Get() Info {

// String returns info as a human-friendly version string.
func (info Info) String() string {
return fmt.Sprintf("version %s.%s, build %s", info.Major, info.Minor, info.GitCommit)
commit := info.GitCommit
if commit == "" {
commit = "(unknown)"
}
return fmt.Sprintf("version %s.%s, build %s", info.Major, info.Minor, commit)
}
4 changes: 0 additions & 4 deletions release/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ INSTANCE_PREFIX=$1

KUBE_DIR=$SCRIPT_DIR/..

# First ensure the version pkg is complete and is up to date
HACK_DIR=$KUBE_DIR/hack
$HACK_DIR/version-gen.sh

# Next build the release tar. This gets copied on to the master and installed
# from there. It includes the go source for the necessary servers along with
# the salt configs.
Expand Down

0 comments on commit 9336373

Please sign in to comment.