From ba175e960b0fa53aec5c7449aaf766c0ba9a2071 Mon Sep 17 00:00:00 2001 From: "George H. Sun" Date: Fri, 8 Mar 2024 18:29:09 +0800 Subject: [PATCH] Add git hash as version information via Bazel stamp. (#46) 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. --- .bazelrc | 7 +++++++ BUILD | 1 + README.md | 6 +++--- ws_status.sh | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .bazelrc create mode 100755 ws_status.sh diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..137db77 --- /dev/null +++ b/.bazelrc @@ -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 diff --git a/BUILD b/BUILD index 832e4ba..06df003 100644 --- a/BUILD +++ b/BUILD @@ -58,6 +58,7 @@ go_library( "@com_github_spf13_pflag//:pflag", "@com_github_spf13_viper//:viper", ], + x_defs = {"main.Version": "{STABLE_GIT_COMMIT}"} ) # diff --git a/README.md b/README.md index ff157ff..ee09338 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ws_status.sh b/ws_status.sh new file mode 100755 index 0000000..f13ebc0 --- /dev/null +++ b/ws_status.sh @@ -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)"