-
Notifications
You must be signed in to change notification settings - Fork 6
/
reporter.py
80 lines (71 loc) · 2.89 KB
/
reporter.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import json
import os
import sys
import tabulate
class BCOLORS:
HEADER = "\033[95m"
OKBLUE = "\033[94m"
OKCYAN = "\033[96m"
OKGREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
BOLD = "\033[1m"
def format_result(result):
restructured_result = [
"success",
"manual_check",
"not_applicable",
"skipped",
"warning",
"error",
"failure",
]
row = [[result[x] for x in restructured_result]]
print(tabulate.tabulate(row, restructured_result))
def main(args):
try:
with open(args[0]) as f:
result = json.load(f)
if "summary" in result and "failure" in result["summary"]:
failures = result["summary"]["failure"]
if failures == 0:
print(f"{BCOLORS.BOLD}{BCOLORS.OKGREEN}App Inspect Passed!")
if "warning" in result["summary"] and result["summary"]["warning"]:
print(f"{BCOLORS.OKBLUE}Warning List:")
for group in result["reports"][0]["groups"]:
for check in group["checks"]:
if check["result"] == "warning":
print(f'{BCOLORS.WARNING} {check["name"]}')
for msg in check["messages"]:
print(msg["message"])
print(f"{BCOLORS.OKBLUE}{BCOLORS.BOLD} SUMMARY")
format_result(result["summary"])
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print("status=pass", file=fh)
else:
print(
f"{BCOLORS.BOLD}{BCOLORS.FAIL}App Inspect returned {failures} failures."
)
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print("status=fail", file=fh)
print(f"{BCOLORS.OKBLUE}{BCOLORS.BOLD} SUMMARY")
format_result(result["summary"])
print(f"{BCOLORS.OKBLUE}{BCOLORS.BOLD} Failure List:")
for group in result["reports"][0]["groups"]:
for check in group["checks"]:
if check["result"] == "failure":
print(f'{BCOLORS.FAIL} {check["name"]}')
for msg in check["messages"]:
print(msg["message"])
sys.exit(1)
else:
print("Unexpected JSON format")
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print("status=fail", file=fh)
sys.exit(1)
except Exception as e:
print(f"An error occurred {str(e)}")
sys.exit(1)
if __name__ == "__main__":
print(sys.argv[1:])
main(sys.argv[1:])