Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / tools / lint / updatebot / validate_yaml.py
blob802a9033fa345aa0c0cf9bec69c763e29c28888a
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from mozbuild.vendor.moz_yaml import load_moz_yaml
6 from mozlint import result
7 from mozlint.pathutils import expand_exclusions
10 class UpdatebotValidator:
11 def lint_file(self, path, **kwargs):
12 if not kwargs.get("testing", False) and not path.endswith("moz.yaml"):
13 # When testing, process all files provided
14 return None
15 if not kwargs.get("testing", False) and "test/files/updatebot" in path:
16 # When not testing, ignore the test files
17 return None
19 try:
20 yaml = load_moz_yaml(path)
22 if "vendoring" in yaml and yaml["vendoring"].get("flavor", None) == "rust":
23 yaml_revision = yaml["origin"]["revision"]
25 with open("Cargo.lock", "r") as f:
26 for line in f:
27 if yaml_revision in line:
28 return None
30 return f"Revision {yaml_revision} specified in {path} wasn't found in Cargo.lock"
32 return None
33 except Exception as e:
34 return f"Could not load {path} according to schema in moz_yaml.py: {e}"
37 def lint(paths, config, **lintargs):
38 # expand_exclusions expects a list, and will convert a string
39 # into it if it doesn't receive one
40 if not isinstance(paths, list):
41 paths = [paths]
43 errors = []
44 files = list(expand_exclusions(paths, config, lintargs["root"]))
46 m = UpdatebotValidator()
47 for f in files:
48 message = m.lint_file(f, **lintargs)
49 if message:
50 errors.append(result.from_config(config, path=f, message=message))
52 return errors