Linkify URLs in Actions workflow logs (#36986)

Detect URLs in Actions log output and render them as clickable links,
similar to how GitHub Actions handles this. Pre-existing links from
ansi_up's OSC 8 parsing are also kept intact.

---------

Signed-off-by: silverwind <me@silverwind.io>
Co-authored-by: Claude (claude-opus-4-6) <noreply@anthropic.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-03-26 10:48:09 +01:00
committed by GitHub
parent ffa626b585
commit 9583e1a65c
7 changed files with 84 additions and 14 deletions
+16 -13
View File
@@ -1,4 +1,5 @@
import {AnsiUp} from 'ansi_up';
import {linkifyURLs} from '../utils/url.ts';
const replacements: Array<[RegExp, string]> = [
[/\x1b\[\d+[A-H]/g, ''], // Move cursor, treat them as no-op
@@ -25,21 +26,23 @@ export function renderAnsi(line: string): string {
}
}
let result: string;
if (!line.includes('\r')) {
return ansi_up.ansi_to_html(line);
}
// handle "\rReading...1%\rReading...5%\rReading...100%",
// convert it into a multiple-line string: "Reading...1%\nReading...5%\nReading...100%"
const lines: Array<string> = [];
for (const part of line.split('\r')) {
if (part === '') continue;
const partHtml = ansi_up.ansi_to_html(part);
if (partHtml !== '') {
lines.push(partHtml);
result = ansi_up.ansi_to_html(line);
} else {
// handle "\rReading...1%\rReading...5%\rReading...100%",
// convert it into a multiple-line string: "Reading...1%\nReading...5%\nReading...100%"
const lines: Array<string> = [];
for (const part of line.split('\r')) {
if (part === '') continue;
const partHtml = ansi_up.ansi_to_html(part);
if (partHtml !== '') {
lines.push(partHtml);
}
}
// the log message element is with "white-space: break-spaces;", so use "\n" to break lines
result = lines.join('\n');
}
// the log message element is with "white-space: break-spaces;", so use "\n" to break lines
return lines.join('\n');
return linkifyURLs(result);
}