DEV Community

Kunal Parikh
Kunal Parikh

Posted on

Set Bazel BUILD_EMBED_LABEL to git commit SHA with state of uncommitted changes

The following git command:

git describe --always --dirty

produces this output:

a3da1ee # when working tree does not have uncommitted changed
a3da1ee-dirty # when working tree has uncommitted changed

Next, we plug the git describe command into --workspace_status_command flag

bazel build target --workspace_status_command='echo "BUILD_EMBED_LABEL `git describe --always --dirty`"'

For convenience of not having to repeat the flag, I've placed the following in .bazelrc

build --workspace_status_command='echo "BUILD_EMBED_LABEL `git describe --always --dirty`"'

Discussion (0)