Skip to content

Commit

Permalink
Add git hash as version information via Bazel stamp. (#46)
Browse files Browse the repository at this point in the history
ansible-puller used to include its git sha as version
https://github.com/teslamotors/ansible_puller/blob/e93c507dae6f92fc4ed2ec205a86cf6603ed7467/build-release.sh.
This logic was missed out during the migration to Bazel. This PR adds it
back to be consistent so that the Prometheus metric can show the current
git build hash.
  • Loading branch information
shk3 committed Mar 8, 2024
1 parent 0192871 commit ba175e9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Bazel stamp variable generations
build --workspace_status_command=$(pwd)/ws_status.sh

# For release
# To use it: bazel COMMAND --config=release
build:release --compilation_mode=opt
build:release --stamp
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ go_library(
"@com_github_spf13_pflag//:pflag",
"@com_github_spf13_viper//:viper",
],
x_defs = {"main.Version": "{STABLE_GIT_COMMIT}"}
)

#
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ or, without bazel

#### Building a Production Release

`bazelisk build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //...`
`bazelisk build --config=release --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //...`

#### Building Production Packages

* `bazelisk build //:ansible_puller_deb`
* `bazelisk build //:ansible_puller_rpm`
* `bazelisk build --config=release //:ansible_puller_deb`
* `bazelisk build --config=release //:ansible_puller_rpm`


#### Debugging an Ansible Run
Expand Down
4 changes: 4 additions & 0 deletions ws_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Generates the data used by the stamping feature in bazel.

echo STABLE_GIT_COMMIT "$(git rev-parse HEAD)"

0 comments on commit ba175e9

Please sign in to comment.