Ensure sizebot doesn't swallow large diffs (#28845)
Sebastian Silbermann committed
Apr 16, 2024 at 09:56 UTC
8f212cc7893e1bd7cb92aac0cfa715dadea626c2
2 files changed
+17
-2
.circleci/config.yml
+2
@@ -211,6 +211,8 @@ jobs:
211
- setup_node_modules
212
- run:
213
command: node ./scripts/tasks/danger
214
+ - store_artifacts:
215
+ path: sizebot-message.md
216
217
build_devtools_and_process_artifacts:
218
docker: *docker
dangerfile.js
+15
-2
@@ -31,6 +31,7 @@ const {markdown, danger, warn} = require('danger');
31
const {promisify} = require('util');
32
const glob = promisify(require('glob'));
33
const gzipSize = require('gzip-size');
34
+const {writeFileSync} = require('fs');
35
36
const {readFileSync, statSync} = require('fs');
37
@@ -236,7 +237,7 @@ function row(result, baseSha, headSha) {
237
}
238
}
239
239
- markdown(`
240
+ const message = `
241
Comparing: ${baseSha}...${headSha}
242
243
## Critical size changes
@@ -263,5 +264,17 @@ ${significantResults.join('\n')}
264
`
265
: '(No significant changes)'
266
}
266
-`);
267
+`;
268
+
269
+ // GitHub comments are limited to 65536 characters.
270
+ if (message.length > 65536) {
271
+ // Make message available as an artifact
272
+ writeFileSync('sizebot-message.md', message);
273
+ markdown(
274
+ 'The size diff is too large to display in a single comment. ' +
275
+ `The [CircleCI job](${process.env.CIRCLE_BUILD_URL}) contains an artifact called 'sizebot-message.md' with the full message.`
276
+ );
277
+ } else {
278
+ markdown(message);
279
+ }
280
})();