Skip to content

Commit ea2df29

Browse files
committed
[Danger] Split the reports into sections based on their package
1 parent 457295a commit ea2df29

File tree

6 files changed

+1034
-988
lines changed

6 files changed

+1034
-988
lines changed

dangerfile.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
/**
22
* Copyright (c) 2013-present, Facebook, Inc.
3-
* All rights reserved.
43
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
86
*/
97

108
'use strict';
119

1210
const {markdown} = require('danger');
1311
const fetch = require('node-fetch');
1412

15-
const {
16-
resultsHeaders,
17-
generateResultsArray,
18-
} = require('./scripts/rollup/stats');
13+
const {generateResultsArray} = require('./scripts/rollup/stats');
1914
const currentBuildResults = require('./scripts/rollup/results.json');
2015

2116
/**
@@ -42,11 +37,44 @@ fetch('http://react.zpao.com/builds/master/latest/results.json').then(
4237
previousBuildResults
4338
);
4439

45-
markdown('### Bundle Changes:\n');
46-
const percentToWarrentShowing = 1
47-
const onlyResultsToShow = results.filter(f => Math.abs(f[3]) > percentToWarrentShowing || Math.abs(f[7]));
48-
const groupBy
40+
const percentToWarrentShowing = 1;
41+
const packagesToShow = results
42+
.filter(
43+
r =>
44+
Math.abs(r.prevFileSizeChange) > percentToWarrentShowing ||
45+
Math.abs(r.prevGzipSizeChange) > percentToWarrentShowing
46+
)
47+
.map(r => r.packageName);
4948

50-
markdown(generateMDTable(resultsHeaders, results));
49+
if (packagesToShow) {
50+
markdown('## Bundle Changes:\n');
51+
// eslint-disable-next-line no-var
52+
for (var name of new Set(packagesToShow)) {
53+
markdown(`## ${name}`);
54+
55+
const thisBundleResults = results.filter(r => r.packageName === name);
56+
const mdHeaders = [
57+
'Filesize Diff',
58+
'Gzip Diff',
59+
'File',
60+
'ENV',
61+
'Prev Size',
62+
'Current Size',
63+
'Prev Gzip',
64+
'Current Gzip',
65+
];
66+
const mdRows = thisBundleResults.map(r => [
67+
r.prevFileSizeChange,
68+
r.prevGzipSizeChange,
69+
r.filename,
70+
r.bundleType,
71+
r.prevSize,
72+
r.prevFileSize,
73+
r.prevGzip,
74+
r.prevGzipSize,
75+
]);
76+
markdown(generateMDTable(mdHeaders, mdRows));
77+
}
78+
}
5179
}
5280
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"coveralls": "^2.11.6",
4848
"create-react-class": "^15.6.2",
4949
"cross-env": "^5.1.1",
50-
"danger": "^3.0.0-beta.1",
50+
"danger": "^3.0.0-beta.2",
5151
"del": "^2.0.2",
5252
"derequire": "^2.0.3",
5353
"escape-string-regexp": "^1.0.5",

scripts/circleci/test_entry_point.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ fi
2424
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')
27-
COMMANDS_TO_RUN+=('node ./scripts/tasks/danger')
2827
COMMANDS_TO_RUN+=('yarn test-build-prod --runInBand')
2928
COMMANDS_TO_RUN+=('node ./scripts/tasks/danger')
3029
COMMANDS_TO_RUN+=('./scripts/circleci/upload_build.sh')

scripts/rollup/stats.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ function saveResults() {
2020
);
2121
}
2222

23-
2423
function percentChange(prev, current) {
2524
return Math.floor((current - prev) / prev * 100);
2625
}
@@ -44,49 +43,52 @@ const resultsHeaders = [
4443
];
4544

4645
function generateResultsArray(current, prevResults) {
47-
currentBuildResults.bundleSizes.forEach(index => {
48-
const result = currentBuildResults.bundleSizes[index];
49-
const prev = prevBuildResults.bundleSizes.filter(
50-
res => res.filename === result.filename
51-
)[0];
52-
if (result === prev) {
53-
// We didn't rebuild this bundle.
54-
return;
55-
}
46+
return current.bundleSizes
47+
.map(result => {
48+
const prev = prevResults.bundleSizes.filter(
49+
res => res.filename === result.filename
50+
)[0];
51+
if (result === prev) {
52+
// We didn't rebuild this bundle.
53+
return;
54+
}
5655

57-
const size = result.size;
58-
const gzip = result.gzip;
59-
let prevSize = prev ? prev.size : 0;
60-
let prevGzip = prev ? prev.gzip : 0;
56+
const size = result.size;
57+
const gzip = result.gzip;
58+
let prevSize = prev ? prev.size : 0;
59+
let prevGzip = prev ? prev.gzip : 0;
6160

62-
return [
63-
`${result.filename} (${result.bundleType}`,
64-
filesize(prevSize),
65-
filesize(size),
66-
percentChange(prevSize, size),
67-
filesize(prevGzip),
68-
filesize(gzip),
69-
percentChange(prevGzip, gzip),
70-
];
71-
// Strip any nulls
72-
}).filter(f => f);
61+
return {
62+
filename: result.filename,
63+
bundleType: result.bundleType,
64+
packageName: result.packageName,
65+
prevSize: filesize(prevSize),
66+
prevFileSize: filesize(size),
67+
prevFileSizeChange: percentChange(prevSize, size),
68+
prevGzip: filesize(prevGzip),
69+
prevGzipSize: filesize(gzip),
70+
prevGzipSizeChange: percentChange(prevGzip, gzip),
71+
};
72+
// Strip any nulls
73+
})
74+
.filter(f => f);
7375
}
7476

7577
function printResults() {
7678
const table = new Table({
7779
head: resultsHeaders.map(chalk.gray.yellow),
7880
});
7981

80-
const results = generateResultsArray(currentBuildResults, prevBuildResults)
81-
results.forEach(row => {
82+
const results = generateResultsArray(currentBuildResults, prevBuildResults);
83+
results.forEach(result => {
8284
table.push([
83-
chalk.white.bold(row[0]),
84-
chalk.gray.bold(row[1]),
85-
chalk.white.bold(row[2]),
86-
percentChangeString(row[3]),
87-
chalk.gray.bold(row[4]),
88-
chalk.white.bold(row[5]),
89-
percentChangeString(row[6]),
85+
chalk.white.bold(`${result.filename} (${result.bundleType})`),
86+
chalk.gray.bold(result.prevSize),
87+
chalk.white.bold(result.prevFileSize),
88+
percentChangeString(result.prevFileSizeChange),
89+
chalk.gray.bold(result.prevGzip),
90+
chalk.white.bold(result.prevGzipSize),
91+
percentChangeString(result.prevGzipSizeChange),
9092
]);
9193
});
9294

scripts/tasks/danger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const extension = process.platform === 'win32' ? '.cmd' : '';
1414

1515
// This came from React Native's circle.yml
1616
const token = 'e622517d9f1136ea8900' + '07c6373666312cdfaa69';
17-
spawn(path.join('node_modules', '.bin', 'danger' + extension), [], {
17+
spawn(path.join('node_modules', '.bin', 'danger-ci' + extension), [], {
1818
// Allow colors to pass through
1919
stdio: 'inherit',
2020
env: {

0 commit comments

Comments
 (0)