mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
ci: write human readable bundle sizes and specify delta (#20092)
* ci: write human readable sizes and specify delta * fix: getHumanReadableSize negative values support * refactor: change formula
This commit is contained in:
parent
56481dd875
commit
61e88f4bdf
@ -15,6 +15,29 @@ function capitalizeFirstLetter(string) {
|
|||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHumanReadableSize(bytes) {
|
||||||
|
if (!bytes) {
|
||||||
|
return '0 Bytes';
|
||||||
|
}
|
||||||
|
|
||||||
|
const absBytes = Math.abs(bytes);
|
||||||
|
const kibibyteSize = 1024;
|
||||||
|
const magnitudes = ['Bytes', 'KiB', 'MiB'];
|
||||||
|
let magnitudeIndex = 0;
|
||||||
|
if (absBytes > Math.pow(kibibyteSize, 2)) {
|
||||||
|
magnitudeIndex = 2;
|
||||||
|
} else if (absBytes > kibibyteSize) {
|
||||||
|
magnitudeIndex = 1;
|
||||||
|
}
|
||||||
|
return `${parseFloat(
|
||||||
|
(bytes / Math.pow(kibibyteSize, magnitudeIndex)).toFixed(2),
|
||||||
|
)} ${magnitudes[magnitudeIndex]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPercentageChange(from, to) {
|
||||||
|
return parseFloat(((to - from) / Math.abs(from)) * 100).toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
const { GITHUB_COMMENT_TOKEN, CIRCLE_PULL_REQUEST } = process.env;
|
const { GITHUB_COMMENT_TOKEN, CIRCLE_PULL_REQUEST } = process.env;
|
||||||
console.log('CIRCLE_PULL_REQUEST', CIRCLE_PULL_REQUEST);
|
console.log('CIRCLE_PULL_REQUEST', CIRCLE_PULL_REQUEST);
|
||||||
@ -278,7 +301,11 @@ async function start() {
|
|||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const sizeDiffRows = Object.keys(diffs).map(
|
const sizeDiffRows = Object.keys(diffs).map(
|
||||||
(part) => `${part}: ${diffs[part]} bytes`,
|
(part) =>
|
||||||
|
`${part}: ${getHumanReadableSize(diffs[part])} (${getPercentageChange(
|
||||||
|
devSizes[part],
|
||||||
|
prSizes[part],
|
||||||
|
)}%)`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const sizeDiffHiddenContent = `<ul>${sizeDiffRows
|
const sizeDiffHiddenContent = `<ul>${sizeDiffRows
|
||||||
|
Loading…
Reference in New Issue
Block a user