David Ostrovsky | b513ac4 | 2019-11-03 09:36:24 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # This script will be run by bazel when the build 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 | from __future__ import print_function |
| 14 | import subprocess |
| 15 | import sys |
| 16 | |
| 17 | CMD = ['git', 'describe', '--always', '--match', 'v[0-9].*', '--dirty'] |
| 18 | |
| 19 | |
| 20 | def revision(): |
| 21 | try: |
| 22 | return subprocess.check_output(CMD).strip().decode("utf-8") |
| 23 | except OSError as err: |
| 24 | print('could not invoke git: %s' % err, file=sys.stderr) |
| 25 | sys.exit(1) |
| 26 | except subprocess.CalledProcessError as err: |
| 27 | print('error using git: %s' % err, file=sys.stderr) |
| 28 | sys.exit(1) |
| 29 | |
| 30 | |
| 31 | print("STABLE_BUILD_SERVICEUSER_LABEL %s" % revision()) |