From f7c9b941cbfe8e9ff127977145a5b75538622093 Mon Sep 17 00:00:00 2001 From: tinayuangao Date: Fri, 3 Nov 2017 15:20:09 -0700 Subject: [PATCH] ci(aio): Add payload size percentage changes check to payload size task (#19908) --- scripts/ci/payload-size.js | 28 ++++++++++++++++++++++++++++ scripts/ci/payload-size.sh | 7 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 scripts/ci/payload-size.js diff --git a/scripts/ci/payload-size.js b/scripts/ci/payload-size.js new file mode 100644 index 0000000000..2cf85d7f54 --- /dev/null +++ b/scripts/ci/payload-size.js @@ -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`); +} diff --git a/scripts/ci/payload-size.sh b/scripts/ci/payload-size.sh index 8004267cac..208e4db9ba 100644 --- a/scripts/ci/payload-size.sh +++ b/scripts/ci/payload-size.sh @@ -81,15 +81,20 @@ uploadData() { echo The data for $name is: echo $payloadData + echo $payloadData > /tmp/current.log + + readonly safeBranchName=$(echo $TRAVIS_BRANCH | sed -e 's/\./_/g') if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then - readonly safeBranchName=$(echo $TRAVIS_BRANCH | sed -e 's/\./_/g') readonly dbPath=/payload/$name/$safeBranchName/$TRAVIS_COMMIT # WARNING: FIREBASE_TOKEN should NOT be printed. set +x $PROJECT_ROOT/node_modules/.bin/firebase database:update --data "$payloadData" --project $PROJECT_NAME --confirm --token "$ANGULAR_PAYLOAD_FIREBASE_TOKEN" $dbPath 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