Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git commit hash to bazel builds #4035

Closed
devjgm opened this issue Aug 2, 2019 · 2 comments · Fixed by #7378
Closed

Add git commit hash to bazel builds #4035

devjgm opened this issue Aug 2, 2019 · 2 comments · Fixed by #7378
Labels
api: spanner Issues related to the Spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@devjgm
Copy link
Contributor

devjgm commented Aug 2, 2019

We try to stamp our builds with a "git commit hash". Here's how we get this info in our CMake builds. This info is exposed in C++ in the g::c::s::internal::BuildMetadata() function here.

The problem is that it's unclear how to get this info from bazel, so currently our bazel builds always report a git hash of "unknown".
https://github.com/googleapis/google-cloud-cpp-spanner/blob/master/google/cloud/spanner/BUILD#L26

This issue is to try to do the following:

Figure out how to get the git commit hash (i.e., git rev-parse --short HEAD) when running a bazel build. This should work when our library is built directly, AND when it's build as a dep of some other project.

Some notes:

  • Running the git command directly in a genrule doesn't work because it is executed in an environment without the .git/ directory structure. It might work to add .git/** to the srcs attribute of the genrule, but I haven't tried this.

  • Using bazel's --workspace_status_command= argument does work. Almost. It works when one specifies that flag. And we could add that flag to all of our bazel invocations by adding it to our .bazelrc file. However, this would not get picked up and used when our project is a dep of another, which is probably the common case.

Related to PR googleapis/google-cloud-cpp-spanner#278

@devjgm devjgm transferred this issue from googleapis/google-cloud-cpp-spanner May 7, 2020
@devjgm devjgm added api: spanner Issues related to the Spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels May 7, 2020
@coryan
Copy link
Contributor

coryan commented Jul 15, 2020

@ghost
Copy link

ghost commented Nov 6, 2020

This seems relevant: bazelbuild/bazel#4464

devbww added a commit to devbww/google-cloud-cpp that referenced this issue Sep 30, 2021
- Use bazel's `workspace_status_command` to report the git commit.
- Substitute it into `google::cloud::internal::build_metadata()`.
- Test that `build_metadata()` does not contain a "@" delimiter.

Fixes googleapis#4035.
devbww added a commit that referenced this issue Sep 30, 2021
- Use bazel's `workspace_status_command` to report the git commit.
- Substitute it into `google::cloud::internal::build_metadata()`.
- Test that `build_metadata()` does not contain a "@" delimiter.

Fixes #4035.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants