From 65bcca04bea0eb2ae85e9a4a3409baad3d504649 Mon Sep 17 00:00:00 2001
From: syuilo <4439005+syuilo@users.noreply.github.com>
Date: Fri, 17 Jul 2026 17:58:09 +0900
Subject: [PATCH] refactor(gh): tweak workflow
---
.../scripts/frontend-browser-diagnostics.render-md.mts | 8 ++------
.../scripts/frontend-bundle-diagnostics.render-md.mts | 10 +++-------
.github/scripts/utility.mts | 4 ++++
3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/.github/scripts/frontend-browser-diagnostics.render-md.mts b/.github/scripts/frontend-browser-diagnostics.render-md.mts
index c25f3b9a6e..9c3af1a79d 100644
--- a/.github/scripts/frontend-browser-diagnostics.render-md.mts
+++ b/.github/scripts/frontend-browser-diagnostics.render-md.mts
@@ -91,10 +91,6 @@ export type BrowserMetricsReport = {
samples: BrowserMeasurementSample[];
};
-function escapeCell(value: string) {
- return String(value).replaceAll('|', '\\|').replaceAll('\n', '
');
-}
-
function truncate(value: string, maxLength = 140) {
if (value.length <= maxLength) return value;
return `${value.slice(0, maxLength - 3)}...`;
@@ -278,7 +274,7 @@ function renderLargestRequests(report: BrowserMetricsReport, title: string) {
];
for (const request of report.summary.network.largestRequests.slice(0, 10)) {
- lines.push(`| \`${escapeCell(truncate(request.url))}\` | ${escapeCell(request.resourceType)} | ${request.status ?? '-'} | ${util.formatBytes(request.encodedBytes)} | ${util.formatBytes(request.decodedBodyBytes)} |`);
+ lines.push(`| \`${util.escapeMdTableCell(truncate(request.url))}\` | ${util.escapeMdTableCell(request.resourceType)} | ${request.status ?? '-'} | ${util.formatBytes(request.encodedBytes)} | ${util.formatBytes(request.decodedBodyBytes)} |`);
}
lines.push('', '');
@@ -296,7 +292,7 @@ function renderFailedRequests(report: BrowserMetricsReport, title: string) {
];
for (const request of report.summary.network.failedRequests.slice(0, 20)) {
- lines.push(`| \`${escapeCell(truncate(request.url))}\` | ${escapeCell(request.resourceType)} | ${request.status ?? '-'} | ${escapeCell(request.errorText ?? '')} |`);
+ lines.push(`| \`${util.escapeMdTableCell(truncate(request.url))}\` | ${util.escapeMdTableCell(request.resourceType)} | ${request.status ?? '-'} | ${util.escapeMdTableCell(request.errorText ?? '')} |`);
}
lines.push('', '');
diff --git a/.github/scripts/frontend-bundle-diagnostics.render-md.mts b/.github/scripts/frontend-bundle-diagnostics.render-md.mts
index a198b46b5c..e6932d450a 100644
--- a/.github/scripts/frontend-bundle-diagnostics.render-md.mts
+++ b/.github/scripts/frontend-bundle-diagnostics.render-md.mts
@@ -14,10 +14,6 @@ const locale = 'ja-JP';
// return Math.round((value / total) * 100) + '%';
//}
-function escapeCell(value: string) {
- return String(value).replaceAll('|', '\\|').replaceAll('\n', '
');
-}
-
//function tableCell(value) {
// return String(value).replaceAll('|', '\\|').replaceAll('\r', ' ').replaceAll('\n', ' ');
//}
@@ -460,11 +456,11 @@ function chunkMarkdownTable(
for (const row of rows) {
const chunkFile = chunkFileDisplay(row);
if (row.changeType === 'added') {
- lines.push(`| \`${escapeCell(row.name)}\`
\`${escapeCell(chunkFile)}\` | ${util.formatBytes(row.beforeSize)} | ${util.formatBytes(row.afterSize)} | ${util.calcAndFormatDeltaBytes(row.beforeSize, row.afterSize, 1000)} | $\\color{orange}{\\text{( + )}}$ |`);
+ lines.push(`| \`${util.escapeMdTableCell(row.name)}\`
\`${util.escapeMdTableCell(chunkFile)}\` | ${util.formatBytes(row.beforeSize)} | ${util.formatBytes(row.afterSize)} | ${util.calcAndFormatDeltaBytes(row.beforeSize, row.afterSize, 1000)} | $\\color{orange}{\\text{( + )}}$ |`);
} else if (row.changeType === 'removed') {
- lines.push(`| \`${escapeCell(row.name)}\`
\`${escapeCell(chunkFile)}\` | ${util.formatBytes(row.beforeSize)} | ${util.formatBytes(row.afterSize)} | ${util.calcAndFormatDeltaBytes(row.beforeSize, row.afterSize, 1000)} | $\\color{green}{\\text{( - )}}$ |`);
+ lines.push(`| \`${util.escapeMdTableCell(row.name)}\`
\`${util.escapeMdTableCell(chunkFile)}\` | ${util.formatBytes(row.beforeSize)} | ${util.formatBytes(row.afterSize)} | ${util.calcAndFormatDeltaBytes(row.beforeSize, row.afterSize, 1000)} | $\\color{green}{\\text{( - )}}$ |`);
} else {
- lines.push(`| \`${escapeCell(row.name)}\`
\`${escapeCell(chunkFile)}\` | ${util.formatBytes(row.beforeSize)} | ${util.formatBytes(row.afterSize)} | ${util.calcAndFormatDeltaBytes(row.beforeSize, row.afterSize, 1000)} | ${util.calcAndFormatDeltaPercent(row.beforeSize, row.afterSize, 0.1).replaceAll('\\%', '\\\\%')} |`);
+ lines.push(`| \`${util.escapeMdTableCell(row.name)}\`
\`${util.escapeMdTableCell(chunkFile)}\` | ${util.formatBytes(row.beforeSize)} | ${util.formatBytes(row.afterSize)} | ${util.calcAndFormatDeltaBytes(row.beforeSize, row.afterSize, 1000)} | ${util.calcAndFormatDeltaPercent(row.beforeSize, row.afterSize, 0.1).replaceAll('\\%', '\\\\%')} |`);
}
}
if (hasGenerated) {
diff --git a/.github/scripts/utility.mts b/.github/scripts/utility.mts
index caec5555ef..e5797d2522 100644
--- a/.github/scripts/utility.mts
+++ b/.github/scripts/utility.mts
@@ -98,6 +98,10 @@ export function escapeLatex(text: string) {
.replaceAll('%', '\\%');
}
+export function escapeMdTableCell(value: string) {
+ return String(value).replaceAll('|', '\\|').replaceAll('\n', '
');
+}
+
export function formatColoredDelta(delta: number, text: (value: number) => string, colorThreshold = 0) {
if (delta === 0) return text(0);
const sign = delta > 0 ? '+' : '-';