Skip to content

Commit

Permalink
Validate MODULE.bazel version equals module directory version (#3059)
Browse files Browse the repository at this point in the history
@meteorcloudy / @Wyverald this adds a check to avoid what happened in
#3025 and which was resolved in #3047.

The `module#version` within the `MODULE.bazel` is validated to be what
the module directory has.
  • Loading branch information
mattyclarkson authored Oct 30, 2024
1 parent 01aca64 commit f42a93d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/bcr_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"""

import argparse
import ast
import json
import subprocess
from pathlib import Path
Expand Down Expand Up @@ -337,6 +338,17 @@ def verify_module_dot_bazel(self, module_name, version):
else:
self.report(BcrValidationResult.GOOD, "Checked in MODULE.bazel matches the sources.")

tree = ast.parse("".join(bcr_module_dot_bazel_content), filename=source_root)
for node in tree.body:
if isinstance(node, ast.Expr):
if isinstance(node.value, ast.Call) and node.value.func.id == "module":
keywords = {k.arg: k.value.value for k in node.value.keywords if isinstance(k.value, ast.Constant)}
if keywords.get("version", version) != version:
self.report(
BcrValidationResult.FAILED,
"Checked in MODULE.bazel version does not match the version of the module directory added.",
)

shutil.rmtree(tmp_dir)

def check_if_bazel_version_is_set(self, tasks):
Expand Down

0 comments on commit f42a93d

Please sign in to comment.