Skip to content

Commit 820288b

Browse files
authored
Merge pull request #2200 from Urgau/gha-logs-fix-perf
Prefer using an HTML table with `user-select: none` in GHA logs
2 parents b6ec119 + c5b3e75 commit 820288b

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/gha_logs.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -211,30 +211,20 @@ pub async fn gha_logs(
211211
<title>{job_name} - {owner}/{repo}@{short_sha}</title>
212212
{icon_status}
213213
<style>
214-
:root {{
215-
--timestamp-length: 28ch;
216-
}}
217214
body {{
218215
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
219216
background: #0C0C0C;
220217
color: #CCC;
221218
white-space: pre;
222-
padding-left: calc(var(--timestamp-length) + 1ch);
223-
margin: 0;
224219
}}
225220
.timestamp {{
226221
color: #848484;
222+
user-select: none;
227223
text-decoration: none;
228-
position: absolute;
229-
left: 0;
230-
width: var(--timestamp-length);
231224
}}
232225
.timestamp:hover {{
233226
text-decoration: underline;
234227
}}
235-
.timestamp::before {{
236-
content: attr(data-timestamp);
237-
}}
238228
.error-marker {{
239229
scroll-margin-bottom: 15vh;
240230
color: #e5534b;
@@ -281,14 +271,19 @@ body {{
281271
var html = ansi_up.ansi_to_html(logs);
282272
283273
// 2. Remove UTF-8 useless BOM
284-
if (html.charCodeAt(0) === 0xFEFF) {{
285-
html = html.substr(1);
286-
}}
287-
288-
// 3. Add a self-referencial anchor to all timestamps at the start of the lines
289-
const dateRegex = /^(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z) /gm;
290-
html = html.replace(dateRegex, (match, ts) =>
291-
`<a id="${{ts}}" href="#${{ts}}" class="timestamp" data-timestamp="${{ts}}"></a>`
274+
html = html.replace(/^\uFEFF/gm, "");
275+
276+
// 3. Transform each log lines that doesn't start with a timestamp into a row where everything is in the second column
277+
const untsRegex = /^(?!\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z)(.*)$/gm;
278+
html = html.replace(untsRegex, (match, log) =>
279+
`<tr><td></td><td>${{log}}</td></tr>`
280+
);
281+
282+
// 3.b Transform each log lines that start with a timestamp in a row with two columns and make the timestamp be a
283+
// self-referencial anchor.
284+
const tsRegex = /^(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z) (.*)$/gm;
285+
html = html.replace(tsRegex, (match, ts, log) =>
286+
`<tr><td><a id="${{ts}}" href="#${{ts}}" class="timestamp">${{ts}}</a></td><td>${{log}}</td></tr>`
292287
);
293288
294289
// 4. Add a anchor around every "##[error]" string
@@ -335,8 +330,8 @@ body {{
335330
return `${{boundary_start}}<a href="https://github.com/{owner}/{repo}/blob/{sha}/${{path}}${{pos}}" class="path-marker">${{inner}}</a>${{boundary_end}}`;
336331
}});
337332
338-
// 6. Add the html to the DOM
339-
document.body.innerHTML = html;
333+
// 6. Add the html to the table
334+
document.getElementById("logs").innerHTML = html;
340335
341336
// 7. If no anchor is given, scroll to the last error
342337
if (location.hash === "" && errorCounter >= 0) {{
@@ -362,6 +357,14 @@ body {{
362357
</script>
363358
</head>
364359
<body>
360+
<table style="table-layout: fixed; width: 100%">
361+
<colgroup>
362+
<col style="width: 29ch">
363+
<col style="width: 100%">
364+
</colgroup>
365+
<tbody id="logs">
366+
</tbody>
367+
</table>
365368
</body>
366369
</html>"###,
367370
);

0 commit comments

Comments
 (0)