-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpublish-reports.py
More file actions
executable file
·80 lines (68 loc) · 2.75 KB
/
Copy pathpublish-reports.py
File metadata and controls
executable file
·80 lines (68 loc) · 2.75 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Record the reports all-reports.py generated, and announce them.
Run this after the upload, never before: a report the [history] table knows
about is never generated again, so a row written before the files are up turns
any later failure in the stage into a report that is lost for good. The emails
link to those files, so they are sent from here too - after the rows, since the
other order would mail the same regressions again on every rerun.
"""
import argparse, os, sys
import simplejson as json
import resultsdb
parser = argparse.ArgumentParser(description='Record and announce published library testing reports')
parser.add_argument('--pending', default="pending-reports.json",
help="The reports all-reports.py generated")
parser.add_argument('--keep', default=False, action='store_true',
help="Do not delete the pending file, so the run can be repeated")
resultsdb.addArgument(parser)
args = parser.parse_args()
if not os.path.exists(args.pending):
print("%s does not exist; all-reports.py generated nothing to publish" % args.pending)
sys.exit(0)
with open(args.pending) as fin:
pending = json.load(fin)
entries = pending.get("entries", {})
emails = pending.get("emails", {})
db = resultsdb.connect(args.db)
db.createHistoryTable()
for branch in sorted(entries.keys()):
print("Recording %d reports of %s" % (len(entries[branch]), branch))
db.insertHistory(branch, entries[branch])
db.close()
if emails:
import smtplib
from email.message import EmailMessage
from email.headerregistry import Address
missing_plain = ""
missing_html = ""
if pending.get("missing_branches"):
missing_plain = "Report asks for missing branches which we ignored: %s\n" % ", ".join(pending["missing_branches"])
missing_html = ("%s %s %s" % ("<p style=\"color:red;\">", missing_plain, "</p"))
for email in sorted(emails.keys()):
msg = EmailMessage()
msg['Subject'] = 'OpenModelica Library Testing Regressions'
msg['From'] = Address("OM Hudson", "openmodelicabuilds", "ida.liu.se")
msg['To'] = email
msg.set_content("""\
%s
The following reports contain regressions your account was involved with:
""" % missing_plain + "\n".join(reversed(emails[email]["plain"])))
msg.add_alternative("""\
<html lang="en">
<head></head>
<body>
%s
<p>The following reports contain regressions your account was involved with:</p>
%s
</body>
</html>
""" % (missing_html, "\n".join(reversed(emails[email]["html"]))), subtype='html')
with smtplib.SMTP('smtp.office365.com') as s:
s.starttls()
s.ehlo()
s.login(os.environ["IDA_EMAIL_USR"],os.environ["IDA_EMAIL_PSW"])
s.send_message(msg)
print("Sent %d emails" % len(emails))
if not args.keep:
os.remove(args.pending)