mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
chore: add bundle size diff to metamaskbot (#16098)
This commit is contained in:
parent
d154cc78e4
commit
522eb72e49
@ -541,7 +541,7 @@ jobs:
|
||||
- store_artifacts:
|
||||
path: test-artifacts
|
||||
destination: test-artifacts
|
||||
|
||||
|
||||
test-e2e-chrome-mv3:
|
||||
executor: node-browsers
|
||||
parallelism: 8
|
||||
@ -797,6 +797,11 @@ jobs:
|
||||
- store_artifacts:
|
||||
path: development/ts-migration-dashboard/build
|
||||
destination: ts-migration-dashboard
|
||||
- run:
|
||||
name: Set branch parent commit env var
|
||||
command: |
|
||||
echo "export PARENT_COMMIT=$(git rev-parse "$(git rev-list --topo-order --reverse HEAD ^origin/develop | head -1)"^)" >> $BASH_ENV
|
||||
source $BASH_ENV
|
||||
- run:
|
||||
name: build:announce
|
||||
command: ./development/metamaskbot-build-announce.js
|
||||
|
@ -23,6 +23,8 @@ async function start() {
|
||||
console.log('CIRCLE_BUILD_NUM', CIRCLE_BUILD_NUM);
|
||||
const { CIRCLE_WORKFLOW_JOB_ID } = process.env;
|
||||
console.log('CIRCLE_WORKFLOW_JOB_ID', CIRCLE_WORKFLOW_JOB_ID);
|
||||
const { PARENT_COMMIT } = process.env;
|
||||
console.log('PARENT_COMMIT', PARENT_COMMIT);
|
||||
|
||||
if (!CIRCLE_PULL_REQUEST) {
|
||||
console.warn(`No pull request detected for commit "${CIRCLE_SHA1}"`);
|
||||
@ -87,6 +89,9 @@ async function start() {
|
||||
.map((key) => `<li>${key}: ${bundles[key].join(', ')}</li>`)
|
||||
.join('')}</ul>`;
|
||||
|
||||
const bundleSizeDataUrl =
|
||||
'https://raw.githubusercontent.com/MetaMask/extension_bundlesize_stats/main/stats/bundle_size_data.json';
|
||||
|
||||
const coverageUrl = `${BUILD_LINK_BASE}/coverage/index.html`;
|
||||
const coverageLink = `<a href="${coverageUrl}">Report</a>`;
|
||||
|
||||
@ -243,6 +248,67 @@ async function start() {
|
||||
console.log(`No results for ${summaryPlatform} found; skipping benchmark`);
|
||||
}
|
||||
|
||||
try {
|
||||
const prBundleSizeStats = JSON.parse(
|
||||
await fs.readFile(
|
||||
path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
path.join('test-artifacts', 'chrome', 'mv3', 'bundle_size.json'),
|
||||
),
|
||||
'utf-8',
|
||||
),
|
||||
);
|
||||
|
||||
const devBundleSizeStats = await (
|
||||
await fetch(bundleSizeDataUrl, {
|
||||
method: 'GET',
|
||||
})
|
||||
).json();
|
||||
|
||||
const prSizes = {
|
||||
background: prBundleSizeStats.background.size,
|
||||
ui: prBundleSizeStats.ui.size,
|
||||
common: prBundleSizeStats.common.size,
|
||||
};
|
||||
|
||||
const devSizes = Object.keys(prSizes).reduce((sizes, part) => {
|
||||
sizes[part] = devBundleSizeStats[PARENT_COMMIT][part] || 0;
|
||||
return sizes;
|
||||
}, {});
|
||||
|
||||
const diffs = Object.keys(prSizes).reduce((output, part) => {
|
||||
output[part] = prSizes[part] - devSizes[part];
|
||||
return output;
|
||||
}, {});
|
||||
|
||||
const sizeDiffRows = Object.keys(diffs).map(
|
||||
(part) => `${part}: ${diffs[part]} bytes`,
|
||||
);
|
||||
|
||||
const sizeDiffHiddenContent = `<ul>${sizeDiffRows
|
||||
.map((row) => `<li>${row}</li>`)
|
||||
.join('\n')}</ul>`;
|
||||
|
||||
const sizeDiff = diffs.background + diffs.common;
|
||||
|
||||
const sizeDiffWarning =
|
||||
sizeDiff > 0
|
||||
? `🚨 Warning! Bundle size has increased!`
|
||||
: `🚀 Bundle size reduced!`;
|
||||
|
||||
const sizeDiffExposedContent =
|
||||
sizeDiff === 0
|
||||
? `Bundle size diffs`
|
||||
: `Bundle size diffs [${sizeDiffWarning}]`;
|
||||
|
||||
const sizeDiffBody = `<details><summary>${sizeDiffExposedContent}</summary>${sizeDiffHiddenContent}</details>\n\n`;
|
||||
|
||||
commentBody += sizeDiffBody;
|
||||
} catch (error) {
|
||||
console.error(`Error constructing bundle size diffs results: '${error}'`);
|
||||
}
|
||||
|
||||
try {
|
||||
const highlights = await getHighlights({ artifactBase: BUILD_LINK_BASE });
|
||||
if (highlights) {
|
||||
|
Loading…
Reference in New Issue
Block a user