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

@ -0,0 +1,3 @@
{
"aio":{"master":{"change":"application","gzip7":{"inline":925,"main":119519,"polyfills":11863},"gzip9":{"inline":925,"main":119301,"polyfills":11861},"uncompressed":{"inline":1533,"main":486493,"polyfills":37068}}}
}

View File

@ -1,14 +0,0 @@
#!/bin/bash
set -u -e -o pipefail
declare -A payloadLimits
payloadLimits["aio", "uncompressed", "inline"]=1600
payloadLimits["aio", "uncompressed", "main"]=487000
payloadLimits["aio", "uncompressed", "polyfills"]=38000
payloadLimits["aio", "gzip7", "inline"]=1000
payloadLimits["aio", "gzip7", "main"]=120000
payloadLimits["aio", "gzip7", "polyfills"]=11900
payloadLimits["aio", "gzip9", "inline"]=1000
payloadLimits["aio", "gzip9", "main"]=120000
payloadLimits["aio", "gzip9", "polyfills"]=11900

View File

@ -7,7 +7,6 @@ readonly parentDir=$(dirname $thisDir)
# Track payload size functions # Track payload size functions
source ../scripts/ci/payload-size.sh source ../scripts/ci/payload-size.sh
source ${thisDir}/_payload-limits.sh
trackPayloadSize "aio" "dist/*.bundle.js" true true trackPayloadSize "aio" "dist/*.bundle.js" true true "${thisDir}/_payload-limits.json"

View File

@ -0,0 +1,4 @@
{
"cli-hello-world":{"master":{"gzip7":{"inline":847,"main":42533,"polyfills":20207},"gzip9":{"inline":847,"main":42483,"polyfills":20204},"uncompressed":{"inline":1447,"main":154295,"polyfills":61254}}},
"hello_world__closure":{"master":{"gzip7":{"bundle":32793},"gzip9":{"bundle":32758},"uncompressed":{"bundle":100661}}}
}

View File

@ -1,19 +0,0 @@
#!/bin/bash
set -u -e -o pipefail
declare -A payloadLimits
payloadLimits["hello_world__closure", "uncompressed", "bundle"]=106000
payloadLimits["hello_world__closure", "gzip7", "bundle"]=35000
payloadLimits["hello_world__closure", "gzip9", "bundle"]=35000
payloadLimits["cli-hello-world", "uncompressed", "inline"]=1500
payloadLimits["cli-hello-world", "uncompressed", "main"]=160000
payloadLimits["cli-hello-world", "uncompressed", "polyfills"]=66000
payloadLimits["cli-hello-world", "gzip7", "inline"]=900
payloadLimits["cli-hello-world", "gzip7", "main"]=45000
payloadLimits["cli-hello-world", "gzip7", "polyfills"]=22000
payloadLimits["cli-hello-world", "gzip9", "inline"]=900
payloadLimits["cli-hello-world", "gzip9", "main"]=45000
payloadLimits["cli-hello-world", "gzip9", "polyfills"]=22000

View File

@ -4,9 +4,10 @@ set -e -o pipefail
cd `dirname $0` cd `dirname $0`
readonly thisDir=$(cd $(dirname $0); pwd)
# Track payload size functions # Track payload size functions
source ../scripts/ci/payload-size.sh source ../scripts/ci/payload-size.sh
source ./_payload-limits.sh
# Workaround https://github.com/yarnpkg/yarn/issues/2165 # Workaround https://github.com/yarnpkg/yarn/issues/2165
# Yarn will cache file://dist URIs and not update Angular code # Yarn will cache file://dist URIs and not update Angular code
@ -48,7 +49,7 @@ for testDir in $(ls | grep -v node_modules) ; do
if [[ $testDir == cli-hello-world ]]; then if [[ $testDir == cli-hello-world ]]; then
yarn build yarn build
fi fi
trackPayloadSize "$testDir" "dist/*.js" true false trackPayloadSize "$testDir" "dist/*.js" true false "${thisDir}/_payload-limits.json"
fi fi
) )
done done

View File

@ -1,21 +1,30 @@
const fs = require('fs'); 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 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; let failed = false;
for (let commit in latest) { for (let compressionType in limitData) {
if (typeof latest[commit] === 'object') { if (typeof limitData[compressionType] === 'object') {
for (let compressionType in latest[commit]) { for (let file in limitData[compressionType]) {
if (typeof latest[commit][compressionType] === 'object') { const name = `${compressionType}/${file}`;
for (let file in latest[commit][compressionType]) { const number = limitData[compressionType][file];
const name = `${compressionType}/${file}`; if (Math.abs(current[name] - number) > number / 100) {
const number = latest[commit][compressionType][file]; console.log(`Commit ${commit} ${compressionType} ${file} changed from ${number} to ${current[name]}.
if (current[name] - number > number / 100) { If this is a desired change, please update the payload size limits in file ${limitFile}`);
console.log(`Commit ${commit} ${compressionType} ${file} increase from ${number} to ${current[name]}`); failed = true;
failed = true;
}
}
} }
} }
} }

View File

@ -22,12 +22,9 @@ calculateSize() {
# Write to global variable $failed # Write to global variable $failed
# Read from global variables $size, $size7, $size9, $label, $limitUncompressed # Read from global variables $size, $size7, $size9, $label, $limitUncompressed
checkSize() { checkSize() {
for fileType in "uncompressed" "gzip7" "gzip9"; do name="$1"
if [[ ${size[$fileType]} -gt ${payloadLimits[$name, $fileType, $label]} ]]; then limitFile="$2"
failed=true node ${PROJECT_ROOT}/scripts/ci/payload-size.js $limitFile $name $TRAVIS_BRANCH
echo "$fileType $label size is ${size[$fileType]} which is greater than ${payloadLimits[$name, $fileType, $label]}"
fi
done
} }
# Write timestamp to global variable $payloadData # Write timestamp to global variable $payloadData
@ -92,14 +89,12 @@ uploadData() {
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
# $3 is whether we check the payload size and fail the test if the size exceeds # $3 is whether we check the payload size and fail the test if the size exceeds
# limit, $4 is whether record the type of changes: true | false # limit, $4 is whether record the type of changes: true | false
# $5 is the payload size limit file
trackPayloadSize() { trackPayloadSize() {
name="$1" name="$1"
path="$2" path="$2"
@ -111,9 +106,6 @@ trackPayloadSize() {
for filename in $path; do for filename in $path; do
declare -A size declare -A size
calculateSize calculateSize
if [[ $checkSize = true ]]; then
checkSize
fi
done done
addTimestamp addTimestamp
if [[ $trackChange = true ]]; then if [[ $trackChange = true ]]; then
@ -121,6 +113,9 @@ trackPayloadSize() {
fi fi
addMessage addMessage
uploadData $name uploadData $name
if [[ $checkSize = true ]]; then
checkSize $name "$5"
fi
if [[ $failed = true ]]; then if [[ $failed = true ]]; then
echo exit 1 echo exit 1
exit 1 exit 1