2018-03-31 02:20:48 +02:00
|
|
|
#!/usr/bin/env node
|
2023-03-04 13:51:04 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { promises: fs } = require('fs');
|
|
|
|
const path = require('path');
|
2022-07-26 20:10:51 +02:00
|
|
|
// Fetch is part of node js in future versions, thus triggering no-shadow
|
|
|
|
// eslint-disable-next-line no-shadow
|
2021-02-04 19:15:23 +01:00
|
|
|
const fetch = require('node-fetch');
|
2021-07-15 19:59:34 +02:00
|
|
|
const glob = require('fast-glob');
|
2022-03-15 12:24:37 +01:00
|
|
|
const VERSION = require('../package.json').version;
|
2021-09-15 20:55:48 +02:00
|
|
|
const { getHighlights } = require('./highlights');
|
2018-03-31 02:20:48 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
start().catch(console.error);
|
2018-04-03 21:51:18 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function capitalizeFirstLetter(string) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async function start() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { GITHUB_COMMENT_TOKEN, CIRCLE_PULL_REQUEST } = process.env;
|
|
|
|
console.log('CIRCLE_PULL_REQUEST', CIRCLE_PULL_REQUEST);
|
|
|
|
const { CIRCLE_SHA1 } = process.env;
|
|
|
|
console.log('CIRCLE_SHA1', CIRCLE_SHA1);
|
|
|
|
const { CIRCLE_BUILD_NUM } = process.env;
|
|
|
|
console.log('CIRCLE_BUILD_NUM', CIRCLE_BUILD_NUM);
|
2022-04-01 04:11:59 +02:00
|
|
|
const { CIRCLE_WORKFLOW_JOB_ID } = process.env;
|
|
|
|
console.log('CIRCLE_WORKFLOW_JOB_ID', CIRCLE_WORKFLOW_JOB_ID);
|
2022-11-09 16:02:44 +01:00
|
|
|
const { PARENT_COMMIT } = process.env;
|
|
|
|
console.log('PARENT_COMMIT', PARENT_COMMIT);
|
2018-04-03 21:51:18 +02:00
|
|
|
|
|
|
|
if (!CIRCLE_PULL_REQUEST) {
|
2021-02-04 19:15:23 +01:00
|
|
|
console.warn(`No pull request detected for commit "${CIRCLE_SHA1}"`);
|
|
|
|
return;
|
2018-04-03 21:51:18 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const CIRCLE_PR_NUMBER = CIRCLE_PULL_REQUEST.split('/').pop();
|
|
|
|
const SHORT_SHA1 = CIRCLE_SHA1.slice(0, 7);
|
2022-04-01 04:11:59 +02:00
|
|
|
const BUILD_LINK_BASE = `https://output.circle-artifacts.com/output/job/${CIRCLE_WORKFLOW_JOB_ID}/artifacts/0`;
|
2019-09-11 17:35:30 +02:00
|
|
|
// build the github comment content
|
|
|
|
|
|
|
|
// links to extension builds
|
2022-11-09 16:57:35 +01:00
|
|
|
const platforms = ['chrome', 'firefox'];
|
2020-11-03 00:41:28 +01:00
|
|
|
const buildLinks = platforms
|
|
|
|
.map((platform) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const url = `${BUILD_LINK_BASE}/builds/metamask-${platform}-${VERSION}.zip`;
|
|
|
|
return `<a href="${url}">${platform}</a>`;
|
2020-11-03 00:41:28 +01:00
|
|
|
})
|
2021-02-04 19:15:23 +01:00
|
|
|
.join(', ');
|
2023-04-28 12:24:47 +02:00
|
|
|
const betaBuildLinks = `<a href="${BUILD_LINK_BASE}/builds-beta/metamask-beta-chrome-${VERSION}.zip">chrome</a>`;
|
2021-11-04 19:44:48 +01:00
|
|
|
const flaskBuildLinks = platforms
|
|
|
|
.map((platform) => {
|
2023-02-16 22:39:12 +01:00
|
|
|
const url = `${BUILD_LINK_BASE}/builds-flask/metamask-flask-${platform}-${VERSION}-flask.0.zip`;
|
2021-11-04 19:44:48 +01:00
|
|
|
return `<a href="${url}">${platform}</a>`;
|
|
|
|
})
|
|
|
|
.join(', ');
|
2019-09-11 17:35:30 +02:00
|
|
|
|
|
|
|
// links to bundle browser builds
|
2021-07-16 04:24:52 +02:00
|
|
|
const bundles = {};
|
2021-07-15 19:59:34 +02:00
|
|
|
const fileType = '.html';
|
|
|
|
const sourceMapRoot = '/build-artifacts/source-map-explorer/';
|
|
|
|
const bundleFiles = await glob(`.${sourceMapRoot}*${fileType}`);
|
2021-07-16 04:24:52 +02:00
|
|
|
|
|
|
|
bundleFiles.forEach((bundleFile) => {
|
|
|
|
const fileName = bundleFile.split(sourceMapRoot)[1];
|
|
|
|
const bundleName = fileName.split(fileType)[0];
|
|
|
|
const url = `${BUILD_LINK_BASE}${sourceMapRoot}${fileName}`;
|
|
|
|
let fileRoot = bundleName;
|
2021-07-16 20:23:31 +02:00
|
|
|
let fileIndex = bundleName.match(/-[0-9]{1,}$/u)?.index;
|
|
|
|
|
|
|
|
if (fileIndex) {
|
|
|
|
fileRoot = bundleName.slice(0, fileIndex);
|
|
|
|
fileIndex = bundleName.slice(fileIndex + 1, bundleName.length);
|
2021-07-16 04:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const link = `<a href="${url}">${fileIndex || fileRoot}</a>`;
|
|
|
|
|
|
|
|
if (fileRoot in bundles) {
|
|
|
|
bundles[fileRoot].push(link);
|
|
|
|
} else {
|
|
|
|
bundles[fileRoot] = [link];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const bundleMarkup = `<ul>${Object.keys(bundles)
|
|
|
|
.map((key) => `<li>${key}: ${bundles[key].join(', ')}</li>`)
|
|
|
|
.join('')}</ul>`;
|
2019-09-11 17:35:30 +02:00
|
|
|
|
2022-11-09 16:02:44 +01:00
|
|
|
const bundleSizeDataUrl =
|
|
|
|
'https://raw.githubusercontent.com/MetaMask/extension_bundlesize_stats/main/stats/bundle_size_data.json';
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const coverageUrl = `${BUILD_LINK_BASE}/coverage/index.html`;
|
|
|
|
const coverageLink = `<a href="${coverageUrl}">Report</a>`;
|
2020-12-11 20:51:00 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const storybookUrl = `${BUILD_LINK_BASE}/storybook/index.html`;
|
|
|
|
const storybookLink = `<a href="${storybookUrl}">Storybook</a>`;
|
2021-02-04 15:30:22 +01:00
|
|
|
|
Add TypeScript migration dashboard (#13820)
As we convert parts of the codebase to TypeScript, we will want a way to
track progress. This commit adds a dashboard which displays all of the
files that we wish to convert to TypeScript and which files we've
already converted.
The list of all possible files to convert is predetermined by walking
the dependency graph of each entrypoint the build system uses to compile
the extension (the files that the entrypoint imports, the files that the
imports import, etc). The list should not need to be regenerated, but
you can do it by running:
yarn ts-migration:enumerate
The dashboard is implemented as a separate React app. The CircleCI
configuration has been updated so that when a new commit is pushed, the
React app is built and stored in the CircleCI artifacts. When a PR is
merged, the built files will be pushed to a separate repo whose sole
purpose is to serve the dashboard via GitHub Pages (this is the same
way that the Storybook works). All of the app code and script to build
the app are self-contained under
`development/ts-migration-dashboard`. To build this app yourself, you
can run:
yarn ts-migration:dashboard:build
or if you want to build automatically as you change files, run:
yarn ts-migration:dashboard:watch
Then open the following file in your browser (there is no server
component):
development/ts-migration-dashboard/build/index.html
Finally, although you shouldn't have to do this, to manually deploy the
dashboard once built, you can run:
git remote add ts-migration-dashboard git@github.com:MetaMask/metamask-extension-ts-migration-dashboard.git
yarn ts-migration:dashboard:deploy
2022-08-09 22:16:08 +02:00
|
|
|
const tsMigrationDashboardUrl = `${BUILD_LINK_BASE}/ts-migration-dashboard/index.html`;
|
|
|
|
const tsMigrationDashboardLink = `<a href="${tsMigrationDashboardUrl}">Dashboard</a>`;
|
|
|
|
|
2021-02-22 15:43:29 +01:00
|
|
|
// links to bundle browser builds
|
|
|
|
const depVizUrl = `${BUILD_LINK_BASE}/build-artifacts/build-viz/index.html`;
|
|
|
|
const depVizLink = `<a href="${depVizUrl}">Build System</a>`;
|
2022-07-20 17:33:16 +02:00
|
|
|
const moduleInitStatsBackgroundUrl = `${BUILD_LINK_BASE}/test-artifacts/chrome/mv3/initialisation/background/index.html`;
|
2022-07-21 19:40:24 +02:00
|
|
|
const moduleInitStatsBackgroundLink = `<a href="${moduleInitStatsBackgroundUrl}">Background Module Init Stats</a>`;
|
2022-07-20 17:33:16 +02:00
|
|
|
const moduleInitStatsUIUrl = `${BUILD_LINK_BASE}/test-artifacts/chrome/mv3/initialisation/ui/index.html`;
|
2022-07-21 19:40:24 +02:00
|
|
|
const moduleInitStatsUILink = `<a href="${moduleInitStatsUIUrl}">UI Init Stats</a>`;
|
2022-07-20 17:33:16 +02:00
|
|
|
const moduleLoadStatsUrl = `${BUILD_LINK_BASE}/test-artifacts/chrome/mv3/load_time/index.html`;
|
|
|
|
const moduleLoadStatsLink = `<a href="${moduleLoadStatsUrl}">Module Load Stats</a>`;
|
2022-07-21 19:40:24 +02:00
|
|
|
const bundleSizeStatsUrl = `${BUILD_LINK_BASE}/test-artifacts/chrome/mv3/bundle_size.json`;
|
|
|
|
const bundleSizeStatsLink = `<a href="${bundleSizeStatsUrl}">Bundle Size Stats</a>`;
|
2022-08-12 19:41:20 +02:00
|
|
|
const userActionsStatsUrl = `${BUILD_LINK_BASE}/test-artifacts/chrome/benchmark/user_actions.json`;
|
|
|
|
const userActionsStatsLink = `<a href="${userActionsStatsUrl}">E2e Actions Stats</a>`;
|
2021-02-22 15:43:29 +01:00
|
|
|
|
2019-09-16 06:19:15 +02:00
|
|
|
// link to artifacts
|
2021-02-04 19:15:23 +01:00
|
|
|
const allArtifactsUrl = `https://circleci.com/gh/MetaMask/metamask-extension/${CIRCLE_BUILD_NUM}#artifacts/containers/0`;
|
2019-09-16 06:19:15 +02:00
|
|
|
|
|
|
|
const contentRows = [
|
|
|
|
`builds: ${buildLinks}`,
|
2021-11-04 19:44:48 +01:00
|
|
|
`builds (beta): ${betaBuildLinks}`,
|
|
|
|
`builds (flask): ${flaskBuildLinks}`,
|
2021-02-22 15:43:29 +01:00
|
|
|
`build viz: ${depVizLink}`,
|
2022-07-20 17:33:16 +02:00
|
|
|
`mv3: ${moduleInitStatsBackgroundLink}`,
|
|
|
|
`mv3: ${moduleInitStatsUILink}`,
|
|
|
|
`mv3: ${moduleLoadStatsLink}`,
|
2022-07-21 19:40:24 +02:00
|
|
|
`mv3: ${bundleSizeStatsLink}`,
|
2022-08-12 19:41:20 +02:00
|
|
|
`mv2: ${userActionsStatsLink}`,
|
2020-12-11 20:51:00 +01:00
|
|
|
`code coverage: ${coverageLink}`,
|
2021-02-04 15:30:22 +01:00
|
|
|
`storybook: ${storybookLink}`,
|
Add TypeScript migration dashboard (#13820)
As we convert parts of the codebase to TypeScript, we will want a way to
track progress. This commit adds a dashboard which displays all of the
files that we wish to convert to TypeScript and which files we've
already converted.
The list of all possible files to convert is predetermined by walking
the dependency graph of each entrypoint the build system uses to compile
the extension (the files that the entrypoint imports, the files that the
imports import, etc). The list should not need to be regenerated, but
you can do it by running:
yarn ts-migration:enumerate
The dashboard is implemented as a separate React app. The CircleCI
configuration has been updated so that when a new commit is pushed, the
React app is built and stored in the CircleCI artifacts. When a PR is
merged, the built files will be pushed to a separate repo whose sole
purpose is to serve the dashboard via GitHub Pages (this is the same
way that the Storybook works). All of the app code and script to build
the app are self-contained under
`development/ts-migration-dashboard`. To build this app yourself, you
can run:
yarn ts-migration:dashboard:build
or if you want to build automatically as you change files, run:
yarn ts-migration:dashboard:watch
Then open the following file in your browser (there is no server
component):
development/ts-migration-dashboard/build/index.html
Finally, although you shouldn't have to do this, to manually deploy the
dashboard once built, you can run:
git remote add ts-migration-dashboard git@github.com:MetaMask/metamask-extension-ts-migration-dashboard.git
yarn ts-migration:dashboard:deploy
2022-08-09 22:16:08 +02:00
|
|
|
`typescript migration: ${tsMigrationDashboardLink}`,
|
2019-09-16 06:19:15 +02:00
|
|
|
`<a href="${allArtifactsUrl}">all artifacts</a>`,
|
2021-07-16 20:23:31 +02:00
|
|
|
`<details>
|
|
|
|
<summary>bundle viz:</summary>
|
|
|
|
${bundleMarkup}
|
|
|
|
</details>`,
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-11-03 00:41:28 +01:00
|
|
|
const hiddenContent = `<ul>${contentRows
|
|
|
|
.map((row) => `<li>${row}</li>`)
|
2021-02-04 19:15:23 +01:00
|
|
|
.join('\n')}</ul>`;
|
|
|
|
const exposedContent = `Builds ready [${SHORT_SHA1}]`;
|
2021-09-15 20:55:48 +02:00
|
|
|
const artifactsBody = `<details><summary>${exposedContent}</summary>${hiddenContent}</details>\n\n`;
|
2020-01-23 21:55:17 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const benchmarkResults = {};
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const platform of platforms) {
|
2020-11-03 00:41:28 +01:00
|
|
|
const benchmarkPath = path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'..',
|
|
|
|
path.join('test-artifacts', platform, 'benchmark', 'pageload.json'),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-23 21:55:17 +01:00
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
const data = await fs.readFile(benchmarkPath, 'utf8');
|
|
|
|
const benchmark = JSON.parse(data);
|
|
|
|
benchmarkResults[platform] = benchmark;
|
2020-01-23 21:55:17 +01:00
|
|
|
} catch (error) {
|
|
|
|
if (error.code === 'ENOENT') {
|
2021-02-04 19:15:23 +01:00
|
|
|
console.log(`No benchmark data found for ${platform}; skipping`);
|
2020-01-23 21:55:17 +01:00
|
|
|
} else {
|
2020-11-03 00:41:28 +01:00
|
|
|
console.error(
|
|
|
|
`Error encountered processing benchmark data for '${platform}': '${error}'`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const summaryPlatform = 'chrome';
|
|
|
|
const summaryPage = 'home';
|
2021-09-15 20:55:48 +02:00
|
|
|
let commentBody = artifactsBody;
|
2020-08-14 13:47:43 +02:00
|
|
|
if (benchmarkResults[summaryPlatform]) {
|
2020-01-23 21:55:17 +01:00
|
|
|
try {
|
2020-11-03 00:41:28 +01:00
|
|
|
const summaryPageLoad = Math.round(
|
|
|
|
parseFloat(benchmarkResults[summaryPlatform][summaryPage].average.load),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const summaryPageLoadMarginOfError = Math.round(
|
|
|
|
parseFloat(
|
|
|
|
benchmarkResults[summaryPlatform][summaryPage].marginOfError.load,
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const benchmarkSummary = `Page Load Metrics (${summaryPageLoad} ± ${summaryPageLoadMarginOfError} ms)`;
|
2020-01-23 21:55:17 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const allPlatforms = new Set();
|
|
|
|
const allPages = new Set();
|
|
|
|
const allMetrics = new Set();
|
|
|
|
const allMeasures = new Set();
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const platform of Object.keys(benchmarkResults)) {
|
2021-02-04 19:15:23 +01:00
|
|
|
allPlatforms.add(platform);
|
|
|
|
const platformBenchmark = benchmarkResults[platform];
|
|
|
|
const pages = Object.keys(platformBenchmark);
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const page of pages) {
|
2021-02-04 19:15:23 +01:00
|
|
|
allPages.add(page);
|
|
|
|
const pageBenchmark = platformBenchmark[page];
|
|
|
|
const measures = Object.keys(pageBenchmark);
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const measure of measures) {
|
2021-02-04 19:15:23 +01:00
|
|
|
allMeasures.add(measure);
|
|
|
|
const measureBenchmark = pageBenchmark[measure];
|
|
|
|
const metrics = Object.keys(measureBenchmark);
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const metric of metrics) {
|
2021-02-04 19:15:23 +01:00
|
|
|
allMetrics.add(metric);
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const tableRows = [];
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const platform of allPlatforms) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const pageRows = [];
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const page of allPages) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const metricRows = [];
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const metric of allMetrics) {
|
2021-02-04 19:15:23 +01:00
|
|
|
let metricData = `<td>${metric}</td>`;
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const measure of allMeasures) {
|
2020-11-03 00:41:28 +01:00
|
|
|
metricData += `<td align="right">${Math.round(
|
|
|
|
parseFloat(benchmarkResults[platform][page][measure][metric]),
|
2021-02-04 19:15:23 +01:00
|
|
|
)}</td>`;
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
metricRows.push(metricData);
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
metricRows[0] = `<td rowspan="${
|
|
|
|
allMetrics.size
|
2021-02-04 19:15:23 +01:00
|
|
|
}">${capitalizeFirstLetter(page)}</td>${metricRows[0]}`;
|
|
|
|
pageRows.push(...metricRows);
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
pageRows[0] = `<td rowspan="${
|
|
|
|
allPages.size * allMetrics.size
|
2021-02-04 19:15:23 +01:00
|
|
|
}">${capitalizeFirstLetter(platform)}</td>${pageRows[0]}`;
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const row of pageRows) {
|
2021-02-04 19:15:23 +01:00
|
|
|
tableRows.push(`<tr>${row}</tr>`);
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const benchmarkTableHeaders = ['Platform', 'Page', 'Metric'];
|
2020-01-23 21:55:17 +01:00
|
|
|
for (const measure of allMeasures) {
|
2021-02-04 19:15:23 +01:00
|
|
|
benchmarkTableHeaders.push(`${capitalizeFirstLetter(measure)} (ms)`);
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
const benchmarkTableHeader = `<thead><tr>${benchmarkTableHeaders
|
|
|
|
.map((header) => `<th>${header}</th>`)
|
2021-02-04 19:15:23 +01:00
|
|
|
.join('')}</tr></thead>`;
|
|
|
|
const benchmarkTableBody = `<tbody>${tableRows.join('')}</tbody>`;
|
|
|
|
const benchmarkTable = `<table>${benchmarkTableHeader}${benchmarkTableBody}</table>`;
|
2021-09-15 20:55:48 +02:00
|
|
|
const benchmarkBody = `<details><summary>${benchmarkSummary}</summary>${benchmarkTable}</details>\n\n`;
|
|
|
|
commentBody += `${benchmarkBody}`;
|
2020-01-23 21:55:17 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
console.error(`Error constructing benchmark results: '${error}'`);
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
2020-08-14 13:47:43 +02:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
console.log(`No results for ${summaryPlatform} found; skipping benchmark`);
|
2021-09-15 20:55:48 +02:00
|
|
|
}
|
|
|
|
|
2022-11-09 16:02:44 +01:00
|
|
|
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}'`);
|
|
|
|
}
|
|
|
|
|
2021-09-15 20:55:48 +02:00
|
|
|
try {
|
|
|
|
const highlights = await getHighlights({ artifactBase: BUILD_LINK_BASE });
|
|
|
|
if (highlights) {
|
|
|
|
const highlightsBody = `### highlights:\n${highlights}\n`;
|
|
|
|
commentBody += highlightsBody;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Error constructing highlight results: '${error}'`);
|
2020-01-23 21:55:17 +01:00
|
|
|
}
|
2018-04-03 21:51:18 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const JSON_PAYLOAD = JSON.stringify({ body: commentBody });
|
|
|
|
const POST_COMMENT_URI = `https://api.github.com/repos/metamask/metamask-extension/issues/${CIRCLE_PR_NUMBER}/comments`;
|
|
|
|
console.log(`Announcement:\n${commentBody}`);
|
|
|
|
console.log(`Posting to: ${POST_COMMENT_URI}`);
|
2018-04-03 21:51:18 +02:00
|
|
|
|
2020-01-26 17:43:50 +01:00
|
|
|
const response = await fetch(POST_COMMENT_URI, {
|
2019-07-31 22:17:11 +02:00
|
|
|
method: 'POST',
|
|
|
|
body: JSON_PAYLOAD,
|
|
|
|
headers: {
|
|
|
|
'User-Agent': 'metamaskbot',
|
2021-12-09 20:06:24 +01:00
|
|
|
Authorization: `token ${GITHUB_COMMENT_TOKEN}`,
|
2019-07-31 22:17:11 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-26 17:43:50 +01:00
|
|
|
if (!response.ok) {
|
2021-02-04 19:15:23 +01:00
|
|
|
throw new Error(`Post comment failed with status '${response.statusText}'`);
|
2020-01-26 17:43:50 +01:00
|
|
|
}
|
2018-04-03 21:51:18 +02:00
|
|
|
}
|