-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmpyl-reporter.py
103 lines (87 loc) · 3.38 KB
/
mpyl-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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import logging
import pickle
import sys
from logging import Logger
from pathlib import Path
from rich.console import Console
from rich.logging import RichHandler
from mpyl.constants import RUN_ARTIFACTS_FOLDER, RUN_RESULT_FILE_GLOB
from mpyl.reporting.targets import ReportAccumulator
from mpyl.reporting.targets.github import CommitCheck
from mpyl.reporting.targets.github import PullRequestReporter
from mpyl.reporting.targets.jira import JiraReporter
from mpyl.reporting.targets.jira import compose_build_status
from mpyl.reporting.targets.slack import SlackReporter
from mpyl.steps.run import RunResult
from mpyl.steps.run_properties import construct_run_properties
from mpyl.utilities.pyaml_env import parse_config
def main(logger: Logger):
run_result_files = list(Path(RUN_ARTIFACTS_FOLDER).glob(RUN_RESULT_FILE_GLOB))
if len(run_result_files) == 0:
logger.info(
f"Run result file(s) {RUN_RESULT_FILE_GLOB} not found. Nothing to report."
)
sys.exit()
config = parse_config("mpyl_config.yml")
properties = parse_config("run_properties.yml")
run_properties = construct_run_properties(config=config, properties=properties)
run_result: RunResult = RunResult(run_properties=run_properties)
for run_result_file in run_result_files:
with open(run_result_file, "rb") as file:
previous_result: RunResult = pickle.load(file)
run_result.update_run_plan(previous_result.run_plan)
run_result.extend(previous_result.results)
accumulator = ReportAccumulator()
commit_check = CommitCheck(config=config, logger=logger)
accumulator.add(commit_check.send_report(run_result))
slack_channel = SlackReporter(
config=config,
channel="#project-mpyl-notifications",
versioning_identifier=run_properties.versioning.identifier,
target=run_properties.target,
)
accumulator.add(slack_channel.send_report(run_result))
if run_properties.details.user_email:
slack_personal = SlackReporter(
config=config,
channel=None,
versioning_identifier=run_properties.versioning.identifier,
target=run_properties.target,
)
accumulator.add(slack_personal.send_report(run_result))
jira = JiraReporter(
config=config, branch=run_properties.versioning.branch, logger=logger
)
accumulator.add(jira.send_report(run_result))
github_comment = PullRequestReporter(
config=config,
compose_function=compose_build_status,
)
accumulator.add(github_comment.send_report(run_result))
if accumulator.failures:
logger.warning(
f'Failed to send the following report(s): {", ".join(accumulator.failures)}'
)
if __name__ == "__main__":
FORMAT = "%(name)s %(message)s"
console = Console(
markup=False,
width=200,
no_color=False,
log_path=False,
color_system="256",
)
logging.raiseExceptions = False
logging.basicConfig(
level="INFO",
format=FORMAT,
datefmt="[%X]",
handlers=[RichHandler(markup=False, console=console, show_path=False)],
)
mpyl_logger = logging.getLogger("mpyl")
mpyl_logger.info("Starting reporting...")
try:
main(mpyl_logger)
except Exception as e:
mpyl_logger.warning(f"Unexpected exception: {e}", exc_info=True)
sys.exit(1)