Skip to content

Commit f346cfc

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

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

dangerfile.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,35 @@
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, generateResultArray, 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 = generateResultArray(currentBuildResults, previousBuildResults);
40+
41+
markdown('### Bundle Changes:\n');
42+
markdown(generateMDTable(resultsHeaders, results));
43+
});

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/stats.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ module.exports = {
7070
printResults,
7171
saveResults,
7272
currentBuildResults,
73+
prevBuildResults,
7374
};

scripts/tasks/danger.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
'use strict';
99

10-
var path = require('path');
11-
var spawn = require('child_process').spawn;
10+
const path = require('path');
11+
const spawn = require('child_process').spawn;
1212

13-
var extension = process.platform === 'win32' ? '.cmd' : '';
13+
const extension = process.platform === 'win32' ? '.cmd' : '';
1414

15-
// This came from React Native's circle.yaml
15+
// This came from React Native's circle.yml
1616
const token = 'e622517d9f1136ea8900' + '07c6373666312cdfaa69';
1717
spawn(path.join('node_modules', '.bin', 'danger' + extension), [], {
1818
// Allow colors to pass through
1919
stdio: 'inherit',
2020
env: {
21-
...process.env,
21+
...process.env,
2222
DANGER_GITHUB_API_TOKEN: token,
2323
},
2424
}).on('close', function(code) {

0 commit comments

Comments
 (0)