ci: restore bundle size badges (#1805)
This commit is contained in:
84
.github/scripts/render-bundle-size-comment.js
vendored
84
.github/scripts/render-bundle-size-comment.js
vendored
@@ -49,11 +49,79 @@ function formatDiff(diff, baseValue) {
|
|||||||
return `${formatSignedSize(diff)}${percentage}`;
|
return `${formatSignedSize(diff)}${percentage}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BUNDLE_SIZE_BADGES = {
|
||||||
|
deleted: ' 🗑️',
|
||||||
|
new: ' 🆕',
|
||||||
|
improved: ' 🎉',
|
||||||
|
investigate: ' 🔍',
|
||||||
|
};
|
||||||
|
|
||||||
|
function getChangeBadge(prValue, baseValue) {
|
||||||
|
if (prValue == null) {
|
||||||
|
return BUNDLE_SIZE_BADGES.deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (baseValue == null) {
|
||||||
|
return BUNDLE_SIZE_BADGES.new;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (baseValue <= 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const percentage = ((prValue - baseValue) / baseValue) * 100;
|
||||||
|
|
||||||
|
if (percentage <= -10) {
|
||||||
|
return BUNDLE_SIZE_BADGES.improved;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (percentage >= 5) {
|
||||||
|
return BUNDLE_SIZE_BADGES.investigate;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPackageBadge(prTotal, baseTotal) {
|
||||||
|
if (baseTotal === 0 && prTotal > 0) {
|
||||||
|
return BUNDLE_SIZE_BADGES.new;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (baseTotal <= 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const percentage = ((prTotal - baseTotal) / baseTotal) * 100;
|
||||||
|
|
||||||
|
if (percentage <= -10) {
|
||||||
|
return BUNDLE_SIZE_BADGES.improved;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (percentage >= 5) {
|
||||||
|
return BUNDLE_SIZE_BADGES.investigate;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
function getPackageName(filePath) {
|
function getPackageName(filePath) {
|
||||||
const match = filePath.match(/^packages\/([^/]+)\//);
|
const match = filePath.match(/^packages\/([^/]+)\//);
|
||||||
return match ? match[1] : '(root)';
|
return match ? match[1] : '(root)';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeHtml(value) {
|
||||||
|
return value
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/\|/g, '|')
|
||||||
|
.replace(/\r?\n/g, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatCode(value) {
|
||||||
|
return `<code>${escapeHtml(String(value))}</code>`;
|
||||||
|
}
|
||||||
|
|
||||||
function getFileLabel(filePath, packageName) {
|
function getFileLabel(filePath, packageName) {
|
||||||
const packagePrefix = `packages/${packageName}/dist/`;
|
const packagePrefix = `packages/${packageName}/dist/`;
|
||||||
|
|
||||||
@@ -110,22 +178,26 @@ const sections = [...filesByPackage.entries()]
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
const packageDiff = packagePrSize - packageBaseSize;
|
const packageDiff = packagePrSize - packageBaseSize;
|
||||||
|
const packageBadge = getPackageBadge(packagePrSize, packageBaseSize);
|
||||||
|
|
||||||
const rows = files
|
const rows = files
|
||||||
.map((filePath) => {
|
.map((filePath) => {
|
||||||
|
const prSize = prSizes[filePath];
|
||||||
|
const baseSize = baseSizes[filePath];
|
||||||
const fileDiff = (prSizes[filePath] ?? 0) - (baseSizes[filePath] ?? 0);
|
const fileDiff = (prSizes[filePath] ?? 0) - (baseSizes[filePath] ?? 0);
|
||||||
return `| \`${getFileLabel(filePath, packageName)}\` | ${formatSize(
|
|
||||||
baseSizes[filePath],
|
return `| ${formatCode(
|
||||||
)} | ${formatSize(prSizes[filePath])} | ${formatDiff(
|
getFileLabel(filePath, packageName),
|
||||||
|
)} | ${formatSize(baseSize)} | ${formatSize(prSize)} | ${formatDiff(
|
||||||
fileDiff,
|
fileDiff,
|
||||||
baseSizes[filePath] ?? 0,
|
baseSize ?? 0,
|
||||||
)} |`;
|
)}${getChangeBadge(prSize, baseSize)} |`;
|
||||||
})
|
})
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'<details>',
|
'<details>',
|
||||||
`<summary>\`${packageName}\` - ${formatSize(
|
`<summary>${formatCode(packageName)}${packageBadge} - ${formatSize(
|
||||||
packageBaseSize,
|
packageBaseSize,
|
||||||
)} -> ${formatSize(packagePrSize)} (${formatDiff(
|
)} -> ${formatSize(packagePrSize)} (${formatDiff(
|
||||||
packageDiff,
|
packageDiff,
|
||||||
|
|||||||
Reference in New Issue
Block a user