Repository navigation
Expand file tree
/
Copy pathprocessResults.py
More file actions
162 lines (127 loc) · 4.77 KB
/
Copy pathprocessResults.py
File metadata and controls
162 lines (127 loc) · 4.77 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import json
import datetime
import os
import requests
from toolkit import run, loadIncluded
commit = True
report_discord = True
MATRIX_SIZE = 8
webhook_url = os.environ.get('DISCORD_WEBHOOK_URL')
print("Processing the results...")
#retreive last log
wpt_repository = "https://github.com/vaev-org/wpt.git"
def processWPTdata(whitelist, data):
current_date = datetime.date.today().strftime("%d-%m-%Y")
structured = {'summary':{'date': current_date,'passing':0, 'failing':0}}
passing = {'summary':[]}
for test in data['results']:
current_suite = None
for suite in whitelist:
if test['test'].strip('/').startswith(suite):
current_suite = suite
break
if current_suite is None:
print(f"Test {test['test']} not in whitelist {whitelist}")
current_suite = 'other'
if not current_suite in structured:
structured[current_suite] = {'date': current_date,'passing':0, 'failing':0}
if not current_suite in passing:
passing[current_suite] = []
if test['status'] == 'PASS':
passing['summary'].append(test['test'])
passing[current_suite].append(test['test'])
structured['summary']['passing'] += 1
structured[current_suite]['passing'] += 1
else:
structured['summary']['failing'] += 1
structured[current_suite]['failing'] += 1
return structured, passing
def saveResults(structured):
for suite in structured:
if suite == 'summary':
fileName = "wpt"
else:
fileName = suite.replace('/', '_')
if os.path.exists(f"./logs/{fileName}.json"):
fd = open(f"./logs/{fileName}.json", "r")
content = json.load(fd)
fd.close()
else:
content = []
content.append(structured[suite])
fd = open(f"./logs/{fileName}.json", "w+")
fd.write(json.dumps(content))
fd.close()
def paoulogs(passing):
for suite in passing:
if suite == 'summary':
fileName = "wpt"
else:
fileName = suite.replace('/', '_')
fd = open(f"./logs/passing/{fileName}.json", "w+")
fd.write(json.dumps(passing[suite]))
fd.close()
def saveIncludeList(structured):
content = []
for suite in structured:
content.append({"name":suite, "compliance":structured[suite]['passing']/(structured[suite]['passing'] + structured[suite]['failing'])*100})
fd = open("./logs/includedlist", "w+")
fd.write(json.dumps(content))
fd.close()
run(f"git clone {wpt_repository} wpt --depth 1")
results = []
for i in range(0, MATRIX_SIZE):
f = open(f"./wpt-log-{i+1}/wpt_report_{i+1}.json", "r")
results.append(json.loads(f.readline()))
f.close()
# merging the results
flattened = {"results":[]}
for res in results:
flattened["results"] = flattened["results"] + res['results']
included = loadIncluded()
structured, passing = processWPTdata(included, flattened)
#append it to ours
saveResults(structured)
paoulogs(passing)
saveIncludeList(structured)
if commit:
print("Commiting the results")
run("git config --global user.name 'Zima b-lou'")
run("git config --global user.email 'zima@carbonlab.dev'")
run("git add -A --force logs")
run("git commit -am '🤖 [Automated] Update WPT compliance Check'")
run("git push")
def sign(number):
if number >= 0:
return "+"
elif number < 0:
return "-"
def reportDiscord(structured):
diff = []
for structured_info in structured:
if os.path.exists(f"./logs/{structured_info.replace('/', '_')}.json"):
fd = open(f"./logs/{structured_info.replace('/', '_')}.json", "r")
content = json.load(fd)
fd.close()
if len(content) > 1:
if content[-1]['passing'] != content[-2]['passing']:
diff.append({"name":structured_info ,"diff":content[-1]['passing'] - content[-2]['passing']})
elif len(content) == 1:
diff.append({"name":structured_info ,"diff":content[-1]['passing']})
if not diff:
print("No diff to report")
return
print("Reporting to Discord")
message = {
'content': '```diff\nDiff between the last two runs :\n',
}
for i in range(len(diff)):
message['content'] += f"{sign(diff[i]['diff'])} {diff[i]['name']}: {diff[i]['diff']}\n"
message['content'] += '```'
response = requests.post(webhook_url, data=json.dumps(message), headers={'Content-Type': 'application/json'})
if response.status_code == 204:
print('Message envoyé avec succès !')
else:
print(f'Erreur lors de l\'envoi du message : {response.status_code}')
if report_discord:
reportDiscord(structured)