forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlint.py
51 lines (40 loc) · 1.33 KB
/
lint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Helm linter.
import logging
import re
from typing import Tuple
from pathlib import Path
import click
from forge import LocalShell
from test_framework.logging import init_logging, log
@click.group()
@click.option(
"--log-metadata/--no-log-metadata",
default=True,
)
def main(log_metadata: bool) -> None:
init_logging(logger=log, level=logging.DEBUG, print_metadata=log_metadata)
@main.command()
@click.argument("paths", nargs=-1)
def helm(paths: Tuple[str]) -> None:
shell = LocalShell()
error = False
for path in paths:
result = shell.run(["helm", "lint", path])
for line in result.output.decode().splitlines():
if line.startswith("[ERROR]"):
match = re.match(
r".ERROR. (?P<section>[^:]+?): (?P<error_type>.*) at [(](?P<filename>.*):(?P<line>\d+)[)]: (?P<message>.*)",
line,
)
if match:
fullpath = Path(path).parent / match.group("filename")
log.error(
"::error file={fullpath},line={line},col=1::{message}".format(
fullpath=fullpath, **match.groupdict()
)
)
error = True
if error:
raise SystemExit(1)
if __name__ == "__main__":
main()