bazel: stamp version into build

This commit is contained in:
Justin Santa Barbara 2017-10-03 11:14:50 -04:00
parent 57ceb5dbab
commit 39d4f21954
3 changed files with 35 additions and 0 deletions

View File

@ -115,6 +115,10 @@ go_binary(
name = "kops",
library = ":go_default_library",
visibility = ["//visibility:public"],
x_defs = {
"k8s.io/kops.Version": "1.8.0-alpha.1", # keep
"k8s.io/kops.GitVersion": "{BUILD_SCM_REVISION}", # keep
},
)
go_test(

1
tools/bazel.rc Normal file
View File

@ -0,0 +1 @@
build --workspace_status_command=./tools/get_workspace_status

30
tools/get_workspace_status Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
# This script will be run bazel when building process starts to
# generate key-value information that represents the status of the
# workspace. The output should be like
#
# KEY1 VALUE1
# KEY2 VALUE2
#
# If the script exits with non-zero code, it's considered as a failure
# and the output will be discarded.
# The code below presents an implementation that works for git repository
git_rev=$(git rev-parse HEAD)
if [[ $? != 0 ]];
then
exit 1
fi
echo "BUILD_SCM_REVISION ${git_rev}"
# Check whether there are any uncommited changes
git diff-index --quiet HEAD --
if [[ $? == 0 ]];
then
tree_status="Clean"
else
tree_status="Modified"
fi
echo "BUILD_SCM_STATUS ${tree_status}"