
committed by
Miško Hevery

parent
e2b76bb386
commit
ac93f1235e
@ -1,21 +1,30 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const latest = JSON.parse(fs.readFileSync('/tmp/latest.log', 'utf8'));
|
||||
// Get branch and project name from command line arguments
|
||||
const [, , limitFile, project, branch] = process.argv;
|
||||
|
||||
const limit = JSON.parse(fs.readFileSync(limitFile, 'utf8'));
|
||||
const current = JSON.parse(fs.readFileSync('/tmp/current.log', 'utf8'));
|
||||
|
||||
|
||||
const limitData = limit[project][branch] || limit[project]["master"];
|
||||
|
||||
if (!limitData) {
|
||||
console.error(`No limit data found.`);
|
||||
// If no payload limit file found, we don't need to check the size
|
||||
exit(0);
|
||||
}
|
||||
|
||||
let failed = false;
|
||||
for (let commit in latest) {
|
||||
if (typeof latest[commit] === 'object') {
|
||||
for (let compressionType in latest[commit]) {
|
||||
if (typeof latest[commit][compressionType] === 'object') {
|
||||
for (let file in latest[commit][compressionType]) {
|
||||
const name = `${compressionType}/${file}`;
|
||||
const number = latest[commit][compressionType][file];
|
||||
if (current[name] - number > number / 100) {
|
||||
console.log(`Commit ${commit} ${compressionType} ${file} increase from ${number} to ${current[name]}`);
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
for (let compressionType in limitData) {
|
||||
if (typeof limitData[compressionType] === 'object') {
|
||||
for (let file in limitData[compressionType]) {
|
||||
const name = `${compressionType}/${file}`;
|
||||
const number = limitData[compressionType][file];
|
||||
if (Math.abs(current[name] - number) > number / 100) {
|
||||
console.log(`Commit ${commit} ${compressionType} ${file} changed from ${number} to ${current[name]}.
|
||||
If this is a desired change, please update the payload size limits in file ${limitFile}`);
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user