ci(aio): Add payload size percentage changes check to payload size task (#19908)

This commit is contained in:
tinayuangao 2017-11-03 15:20:09 -07:00 committed by Victor Berchet
parent f0764016f9
commit f7c9b941cb
2 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,28 @@
const fs = require('fs');
const latest = JSON.parse(fs.readFileSync('/tmp/latest.log', 'utf8'));
const current = JSON.parse(fs.readFileSync('/tmp/current.log', 'utf8'));
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;
}
}
}
}
}
}
if (failed) {
process.exit(1);
} else {
console.log(`Payload size 1% check okay`);
}

View File

@ -81,15 +81,20 @@ uploadData() {
echo The data for $name is: echo The data for $name is:
echo $payloadData echo $payloadData
echo $payloadData > /tmp/current.log
readonly safeBranchName=$(echo $TRAVIS_BRANCH | sed -e 's/\./_/g')
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
readonly safeBranchName=$(echo $TRAVIS_BRANCH | sed -e 's/\./_/g')
readonly dbPath=/payload/$name/$safeBranchName/$TRAVIS_COMMIT readonly dbPath=/payload/$name/$safeBranchName/$TRAVIS_COMMIT
# WARNING: FIREBASE_TOKEN should NOT be printed. # WARNING: FIREBASE_TOKEN should NOT be printed.
set +x set +x
$PROJECT_ROOT/node_modules/.bin/firebase database:update --data "$payloadData" --project $PROJECT_NAME --confirm --token "$ANGULAR_PAYLOAD_FIREBASE_TOKEN" $dbPath $PROJECT_ROOT/node_modules/.bin/firebase database:update --data "$payloadData" --project $PROJECT_NAME --confirm --token "$ANGULAR_PAYLOAD_FIREBASE_TOKEN" $dbPath
fi fi
curl "https://angular-payload-size.firebaseio.com/payload/${name}/${safeBranchName}.json?orderBy=\"timestamp\"&limitToLast=1" > /tmp/latest.log
node ${PROJECT_ROOT}/scripts/ci/payload-size.js
} }
# Track payload size, $1 is the name in database, $2 is the file path # Track payload size, $1 is the name in database, $2 is the file path