Skip to content

Commit 0001db0

Browse files
committed
[Danger] Split the reports into sections based on their package
1 parent 6ed6149 commit 0001db0

File tree

6 files changed

+1112
-999
lines changed

6 files changed

+1112
-999
lines changed

dangerfile.js

Lines changed: 119 additions & 24 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

12-
const {markdown} = require('danger');
10+
const {markdown, danger} = 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
/**
@@ -33,20 +28,120 @@ function generateMDTable(headers, body) {
3328
return tableHeaders.join('\n') + '\n' + tablebody.join('\n');
3429
}
3530

31+
/**
32+
* Generates a user-readable string from a percentage change
33+
* @param {string[]} headers
34+
*/
35+
function emojiPercent(change) {
36+
if (change > 0) {
37+
return `:small_red_triangle:+${change}%`;
38+
} else if (change <= 0) {
39+
return `${change}%`;
40+
}
41+
}
42+
3643
// Grab the results.json before we ran CI via the GH API
37-
fetch('http://react.zpao.com/builds/master/latest/results.json').then(
38-
async response => {
39-
const previousBuildResults = await response.json();
40-
const results = generateResultsArray(
41-
currentBuildResults,
42-
previousBuildResults
43-
);
44-
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
49-
50-
markdown(generateMDTable(resultsHeaders, results));
44+
// const baseMerge = danger.github.pr.base.sha
45+
const parentOfOldestCommit = danger.git.commits[0].parents[0];
46+
const commitURL = sha =>
47+
`http://react.zpao.com/builds/master/_commits/${sha}/results.json`;
48+
49+
fetch(commitURL(parentOfOldestCommit)).then(async response => {
50+
const previousBuildResults = await response.json();
51+
const results = generateResultsArray(
52+
currentBuildResults,
53+
previousBuildResults
54+
);
55+
56+
const percentToWarrentShowing = 1;
57+
const packagesToShow = results
58+
.filter(
59+
r =>
60+
Math.abs(r.prevFileSizeChange) > percentToWarrentShowing ||
61+
Math.abs(r.prevGzipSizeChange) > percentToWarrentShowing
62+
)
63+
.map(r => r.packageName);
64+
65+
if (packagesToShow.length) {
66+
let allTables = [];
67+
68+
// Highlight React and React DOM changes inline
69+
// e.g. react: `react.production.min.js`: -3%, `react.development.js`: +4%
70+
71+
if (packagesToShow.includes('react')) {
72+
const reactProd = results.find(
73+
r => r.bundleType === 'UMD_PROD' && r.packageName === 'react'
74+
);
75+
if (
76+
reactProd.prevFileSizeChange !== 0 ||
77+
reactProd.prevGzipSizeChange !== 0
78+
) {
79+
const changeSize = emojiPercent(reactProd.prevFileSizeChange);
80+
const changeGzip = emojiPercent(reactProd.prevGzipSizeChange);
81+
markdown(`React: size: ${changeSize}, gzip: ${changeGzip}`);
82+
}
83+
}
84+
85+
if (packagesToShow.includes('react-dom')) {
86+
const reactDOMProd = results.find(
87+
r => r.bundleType === 'UMD_PROD' && r.packageName === 'react-dom'
88+
);
89+
if (
90+
reactDOMProd.prevFileSizeChange !== 0 ||
91+
reactDOMProd.prevGzipSizeChange !== 0
92+
) {
93+
const changeSize = emojiPercent(reactDOMProd.prevFileSizeChange);
94+
const changeGzip = emojiPercent(reactDOMProd.prevGzipSizeChange);
95+
markdown(`ReactDOM: size: ${changeSize}, gzip: ${changeGzip}`);
96+
}
97+
}
98+
99+
// Show a hidden summary table for all diffs
100+
101+
// eslint-disable-next-line no-var
102+
for (var name of new Set(packagesToShow)) {
103+
const thisBundleResults = results.filter(r => r.packageName === name);
104+
const changedFiles = thisBundleResults.filter(
105+
r => r.prevGzipSizeChange !== 0 || r.prevGzipSizeChange !== 0
106+
);
107+
108+
const mdHeaders = [
109+
'File',
110+
'Filesize Diff',
111+
'Gzip Diff',
112+
'Prev Size',
113+
'Current Size',
114+
'Prev Gzip',
115+
'Current Gzip',
116+
'ENV',
117+
];
118+
119+
const mdRows = changedFiles.map(r => [
120+
r.filename,
121+
emojiPercent(r.prevFileSizeChange),
122+
emojiPercent(r.prevGzipSizeChange),
123+
r.prevSize,
124+
r.prevFileSize,
125+
r.prevGzip,
126+
r.prevGzipSize,
127+
r.bundleType,
128+
]);
129+
130+
allTables.push(`\n## ${name}`);
131+
allTables.push(generateMDTable(mdHeaders, mdRows));
132+
}
133+
134+
const summary = `
135+
<details>
136+
<summary>Details of bundled changes.</summary>
137+
138+
<p>Comparing: ${danger.github.pr.base.sha}...${danger.github.pr.head.sha}</p>
139+
140+
141+
${allTables.join('\n')}
142+
143+
</details>
144+
`;
145+
markdown(summary);
51146
}
52-
);
147+
});

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.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)