2017-11-29 05:47:04 -05:00
|
|
|
'use strict';
|
2017-11-03 18:20:09 -04:00
|
|
|
|
2017-11-29 05:47:04 -05:00
|
|
|
// Imports
|
2017-11-03 18:20:09 -04:00
|
|
|
const fs = require('fs');
|
2017-11-18 15:26:33 -05:00
|
|
|
|
2017-11-29 05:47:04 -05:00
|
|
|
// Get branch and project name from command line arguments.
|
|
|
|
const [, , limitFile, project, branch, commit] = process.argv;
|
2017-11-03 18:20:09 -04:00
|
|
|
|
2017-11-29 05:47:04 -05:00
|
|
|
// Load sizes.
|
|
|
|
const currentSizes = JSON.parse(fs.readFileSync('/tmp/current.log', 'utf8'));
|
|
|
|
const allLimitSizes = JSON.parse(fs.readFileSync(limitFile, 'utf8'));
|
|
|
|
const limitSizes = allLimitSizes[project][branch] || allLimitSizes[project]['master'];
|
2017-11-18 15:26:33 -05:00
|
|
|
|
2017-11-29 05:47:04 -05:00
|
|
|
// Check current sizes against limits.
|
2017-11-03 18:20:09 -04:00
|
|
|
let failed = false;
|
2017-11-29 05:47:04 -05:00
|
|
|
for (const compressionType in limitSizes) {
|
|
|
|
if (typeof limitSizes[compressionType] === 'object') {
|
|
|
|
const limitPerFile = limitSizes[compressionType];
|
|
|
|
|
|
|
|
for (const filename in limitPerFile) {
|
|
|
|
const expectedSize = limitPerFile[filename];
|
|
|
|
const actualSize = currentSizes[`${compressionType}/${filename}`];
|
|
|
|
|
|
|
|
if (Math.abs(actualSize - expectedSize) > expectedSize / 100) {
|
2017-11-18 15:26:33 -05:00
|
|
|
failed = true;
|
2017-11-29 05:47:04 -05:00
|
|
|
console.log(
|
|
|
|
`Commit ${commit} ${compressionType} ${filename} exceeded expected size by >1% ` +
|
2017-12-04 19:28:06 -05:00
|
|
|
`(expected: ${expectedSize}, actual: ${actualSize}).`);
|
2017-11-03 18:20:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
2017-12-04 19:28:06 -05:00
|
|
|
console.log(`If this is a desired change, please update the size limits in file '${limitFile}'.`);
|
2017-11-03 18:20:09 -04:00
|
|
|
process.exit(1);
|
|
|
|
} else {
|
2017-11-29 05:47:04 -05:00
|
|
|
console.log('Payload size <1% change check passed.');
|
2017-11-03 18:20:09 -04:00
|
|
|
}
|