fix: assert expected bazel version (#847)
Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
diff --git a/BUILD b/BUILD
index 7ea2aa4..3385ee4 100644
--- a/BUILD
+++ b/BUILD
@@ -11,7 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
load("@bazel_gazelle//:def.bzl", "gazelle")
+load(":version.bzl", "BAZEL_VERSION")
package(default_visibility = ["//visibility:public"])
@@ -76,3 +78,29 @@
],
command = "update-repos",
)
+
+genrule(
+ name = "assert_bazelversion",
+ srcs = [".bazelversion"],
+ outs = ["assert_bazelversion_test.sh"],
+ cmd = """\
+set -o errexit -o nounset -o pipefail
+current=$$(cat "$(execpath .bazelversion)")
+cat > "$@" <<EOF
+#!/usr/bin/env bash
+set -o errexit -o nounset -o pipefail
+if [[ \"$${{current}}\" != \"{expected}\" ]]; then
+ >&2 echo "ERROR: current bazel version '$${{current}}' is not the expected '{expected}'"
+ exit 1
+fi
+EOF
+""".format(
+ expected = BAZEL_VERSION,
+ ),
+ executable = True,
+)
+
+sh_test(
+ name = "assert_bazelversion_test",
+ srcs = [":assert_bazelversion_test.sh"],
+)
diff --git a/version.bzl b/version.bzl
index ac1dabb..829762a 100644
--- a/version.bzl
+++ b/version.bzl
@@ -17,7 +17,6 @@
# against.
# This version should be updated together with the version of Bazel
# in .bazelversion.
-# TODO(alexeagle): assert this is the case in a test
BAZEL_VERSION = "5.2.0"
# Versions of Bazel which users should be able to use.