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

fix: assert expected bazel version #847

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -76,3 +78,29 @@ gazelle(
],
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"],
)
1 change: 0 additions & 1 deletion version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down