ci: Update 1% payload size test (#20524)

PR Close #20524
This commit is contained in:
tinayuangao
2017-11-18 12:26:33 -08:00
committed by Miško Hevery
parent e2b76bb386
commit ac93f1235e
8 changed files with 40 additions and 62 deletions

View File

@ -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;
}
}
}