Skip to content

Commit 69fae23

Browse files
committed
[WIP] Get the before and after for the build results
1 parent eb6da4e commit 69fae23

File tree

7 files changed

+1271
-1150
lines changed

7 files changed

+1271
-1150
lines changed

dangerfile.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,38 @@
99

1010
'use strict';
1111

12-
const { danger, markdown, warn } = require('danger');
12+
const { danger, markdown, schedule } = require('danger');
1313

14-
// Tags big PRs
15-
var bigPRThreshold = 600;
16-
if (danger.git.modified_files + danger.git.added_files + danger.git.deleted_files > bigPRThreshold) {
17-
const title = ':exclamation: Big PR';
18-
const files = danger.git.modified_files + danger.git.added_files + danger.git.deleted_files;
19-
const idea = `This PR is extremely unlikely to get reviewed because it touches ${files} files.`;
20-
warn(`${title} - <i>${idea}</i>`);
14+
const { resultsHeaders, generateResultsArray, currentBuildResults } = require('./scripts/rollup/stats');
2115

22-
markdown('@facebook-github-bot large-pr');
16+
/**
17+
* Generates a Markdown table
18+
* @param {string[]} headers
19+
* @param {string[][]} body
20+
*/
21+
function generateMDTable(headers, body) {
22+
const tableHeaders = [
23+
headers.join(' | '),
24+
headers.map(() => ' --- ').join(' | '),
25+
];
26+
27+
const tablebody = body.map(r => r.join(' | '));
28+
return tableHeaders.join('\n') + '\n' + tablebody.join('\n');
2329
}
30+
31+
// Grab the results.json before we ran CI via the GH API
32+
const getJSON = danger.github.utils
33+
.fileContents('scripts/rollup/results.json');
34+
35+
// @bug See https://github.com/danger/danger-js/issues/443
36+
schedule(getJSON);
37+
getJSON.then(APIPreviousBuildResults => {
38+
const previousBuildResults = JSON.parse(APIPreviousBuildResults);
39+
const results = generateResultsArray(currentBuildResults, previousBuildResults);
40+
41+
markdown('### Bundle Changes:\n');
42+
// const percentToWarrentShowing = 0.1
43+
// const onlyResultsToShow = results.filter(f => Math.abs(f[3]) > percentToWarrentShowing);
44+
45+
markdown(generateMDTable(resultsHeaders, results));
46+
});

scripts/circleci/test_entry_point.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ if [ $((2 % CIRCLE_NODE_TOTAL)) -eq "$CIRCLE_NODE_INDEX" ]; then
2525
COMMANDS_TO_RUN+=('./scripts/circleci/build.sh')
2626
COMMANDS_TO_RUN+=('yarn test-build --runInBand')
2727
COMMANDS_TO_RUN+=('yarn test-build-prod --runInBand')
28+
COMMANDS_TO_RUN+=('node ./scripts/tasks/danger')
2829
COMMANDS_TO_RUN+=('./scripts/circleci/upload_build.sh')
2930
fi
3031

3132
if [ $((3 % CIRCLE_NODE_TOTAL)) -eq "$CIRCLE_NODE_INDEX" ]; then
32-
COMMANDS_TO_RUN+=('node ./scripts/tasks/danger')
3333
COMMANDS_TO_RUN+=('./scripts/circleci/test_coverage.sh')
3434
fi
3535

scripts/rollup/build.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ function getPlugins(
181181
externals,
182182
updateBabelOptions,
183183
filename,
184+
packageName,
184185
bundleType,
185186
globalName,
186187
moduleType,
@@ -265,6 +266,8 @@ function getPlugins(
265266
getSize: (size, gzip) => {
266267
const key = `${filename} (${bundleType})`;
267268
Stats.currentBuildResults.bundleSizes[key] = {
269+
bundleType,
270+
packageName,
268271
size,
269272
gzip,
270273
};
@@ -352,6 +355,7 @@ async function createBundle(bundle, bundleType) {
352355
externals,
353356
bundle.babel,
354357
filename,
358+
packageName,
355359
bundleType,
356360
bundle.global,
357361
bundle.moduleType,

0 commit comments

Comments
 (0)