-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.jl
208 lines (168 loc) · 6.33 KB
/
main.jl
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import TestItemRunner2, JSON, GitHubActions
using TestItemRunner2: URI, TestrunResult, TestrunResultDefinitionError, TestrunResultTestitem, TestrunResultTestitemProfile, TestrunResultMessage
using GitHubActions: add_to_file
using Query
results_path = ENV["RESULTS_PATH"]
json_files_content = [JSON.parsefile(joinpath(results_path, i)) for i in readdir(results_path)]
function convert_to_uri(s)
uri = URI(s)
regexes = [
r"\/Users\/runner\/work\/([^\/]*)\/\1\/(.*)",
r"\/home\/runner\/work\/([^\/]*)\/\1\/(.*)",
r"\/d\:\/a\/([^\/]*)\/\1\/(.*)"
]
for r in regexes
m = match(r, uri.path)
if m!==nothing
return URI("ourpackage", nothing, "$(m[2])", nothing, nothing)
end
end
return uri
end
function github_uri_from_uri(s, line)
converted_uri = convert_to_uri(s)
if converted_uri.scheme == "ourpackage"
return URI("https", "github.com", "/$(ENV["GITHUB_REPOSITORY"])/blob/$(ENV["GITHUB_SHA"])/$(converted_uri.path)", nothing, isnothing(line) ? nothing : "L$line")
else
return s
end
end
function agnostic_message(s)
s = chomp(s)
s = replace(s, "\r\n" => "\n")
parts = split(s, '\n', limit=2)
regexes = [
r"Test Failed at \/Users\/runner\/work\/([^\/]*)\/\1\/(.*)",
r"Test Failed at \/home\/runner\/work\/([^\/]*)\/\1\/(.*)",
r"Test Failed at d\:\\a\\([^\/]*)\\\1\\(.*)"
]
for r in regexes
m = match(r, parts[1])
if m!==nothing
return "Test Failed at $(m[1])/$(replace(m[2], '\\'=>'/'))\n$(parts[2])"
end
end
return s
end
function compress_profile_lists(profiles)
reg = r"Julia (\d*.\d*.\d*)\~(.*)\:(.*)"
asdf = profiles |>
@map(match(reg, _)) |>
@filter(!isnothing(_)) |>
@map({version=_[1], arch=_[2], os=_[3]}) |>
@groupby({_.os, _.version}) |>
@orderby(_.os) |>
@thenby(_.version) |>
@map({key(_).os, version=key(_).version * "~" * join(_.arch, "~")}) |>
@groupby({_.os}) |>
@orderby(_.os) |>
@map(key(_).os * " (" * join(_.version, ", ") * ")") |>
collect
return join(asdf, ", ")
end
# Completely wrong, but good enough for now!
function escape_markdown(s)
return replace(s, "-" => "\\-", "~" => "\\~")
end
# for i in json_files_content
# JSON.print(i)
# end
results = TestrunResult(
TestrunResultDefinitionError[],
[
(
[
TestrunResultTestitem(
j["name"],
URI(j["uri"]),
[
TestrunResultTestitemProfile(
l["profile_name"],
Symbol(l["status"]),
l["duration"],
l["messages"] !== nothing ?
[
TestrunResultMessage(
k["message"],
URI(k["uri"]),
k["line"],
k["column"]
) for k in l["messages"]
] :
missing
) for l in j["profiles"]
]
) for j in i["testitems"]
] for i in json_files_content
)...;
]
)
# println(results)
grouped_testitems = results.testitems |>
@groupby({_.name, uri=convert_to_uri(_.uri)}) |>
@map(TestrunResultTestitem(key(_).name, key(_).uri, [(_.profiles)...;])) |>
collect
# println(grouped_testitems)
fail_overall = false
o = IOBuffer()
lint_results = JSON.parse(ENV["LINT_RESULTS"])
println(lint_results)
println(o, "# Lint summary")
println(o, "$(length(lint_results)) lint messages were generated.")
for diag in lint_results
uri = URI(diag["uri"])
path = convert_to_uri(uri).path
github_uri = github_uri_from_uri(uri, diag["line"])
println(o, "## $(diag["severity"]) [$path:$(diag["line"])]($github_uri) from $(diag["source"])")
println(o, "$(diag["message"])")
if diag["severity"] == "error"
global fail_overall = true
end
end
println(o, "# Test summary")
println(o, "$(length(results.testitems)) testitems were run.")
println(o, "## Detailed testitem output")
for ti in grouped_testitems
println(o, "### `$(ti.name)` in $(ti.uri.path)")
if all(tp->tp.status==:passed, ti.profiles)
println(o, "Passed on all platforms $(escape_markdown(compress_profile_lists(map(j->j.profile_name, ti.profiles)))).")
else
grouped_by_status = ti.profiles |>
@groupby({_.status}) |>
@map({key(_).status, profiles=_}) |>
collect
for i in grouped_by_status
println(o, "#### $(i.status) on $(escape_markdown(compress_profile_lists(map(j->j.profile_name, i.profiles))))")
deduplicated_messages = i.profiles |>
@filter(_.messages!==missing) |>
@mapmany(_.messages, {_.profile_name, __.uri, __.line, __.message}) |>
@groupby({uri=convert_to_uri(_.uri), _.line, message=agnostic_message(_.message)}) |>
@map({key(_)..., profile_names=_.profile_name}) |>
collect
for msg in deduplicated_messages
github_uri = github_uri_from_uri(msg.uri, msg.line) # URI("https", "github.com", "/$(ENV["GITHUB_REPOSITORY"])/blob/$(ENV["GITHUB_SHA"])/$(msg.uri.path)", nothing, "L$(msg.line)")
println(github_uri)
println(o, "##### [$(msg.uri.path):$(msg.line)]($github_uri) on $(escape_markdown(compress_profile_lists(msg.profile_names)))")
println(o, "```")
println(o, msg.message)
println(o, "```")
end
end
# for tp in ti.profiles
# println(o, "#### Result on $(escape_markdown(tp.profile_name)) is $(tp.status)")
# if tp.messages!==missing
# for msg in tp.messages
# println(o, "##### $(msg.uri):$(msg.line)")
# println(o, "```")
# println(o, msg.message)
# println(o, "```")
# end
# end
# end
global fail_overall = true
end
end
add_to_file("GITHUB_STEP_SUMMARY", String(take!(o)))
if fail_overall
exit(1)
end