Ming Zhao | 1314570 | 2015-07-07 16:30:59 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This script will be run bazel when building process starts to |
| 4 | # generate key-value information that represents the status of the |
| 5 | # workspace. The output should be like |
| 6 | # |
| 7 | # KEY1 VALUE1 |
| 8 | # KEY2 VALUE2 |
| 9 | # |
| 10 | # If the script exits with non-zero code, it's considered as a failure |
| 11 | # and the output will be discarded. |
| 12 | |
| 13 | # The code below presents an implementation that works for git repository |
| 14 | git_rev=$(git rev-parse HEAD) |
| 15 | if [[ $? != 0 ]]; |
| 16 | then |
| 17 | exit 1 |
| 18 | fi |
| 19 | echo "BUILD_SCM_REVISION ${git_rev}" |
| 20 | |
| 21 | # Check whether there are any uncommited changes |
| 22 | git diff-index --quiet HEAD -- |
| 23 | if [[ $? == 0 ]]; |
| 24 | then |
| 25 | tree_status="Clean" |
| 26 | else |
| 27 | tree_status="Modified" |
| 28 | fi |
| 29 | echo "BUILD_SCM_STATUS ${tree_status}" |