Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Update 1% payload size test #20524

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions aio/scripts/_payload-limits.json
Original file line number Diff line number Diff line change
@@ -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}}}
}
14 changes: 0 additions & 14 deletions aio/scripts/_payload-limits.sh

This file was deleted.

3 changes: 1 addition & 2 deletions aio/scripts/payload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ readonly parentDir=$(dirname $thisDir)

# Track payload size functions
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"

4 changes: 4 additions & 0 deletions integration/_payload-limits.json
Original file line number Diff line number Diff line change
@@ -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}}}
}
19 changes: 0 additions & 19 deletions integration/_payload-limits.sh

This file was deleted.

5 changes: 3 additions & 2 deletions integration/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ set -e -o pipefail

cd `dirname $0`

readonly thisDir=$(cd $(dirname $0); pwd)

# Track payload size functions
source ../scripts/ci/payload-size.sh
source ./_payload-limits.sh

# Workaround https://github.com/yarnpkg/yarn/issues/2165
# Yarn will cache file://dist URIs and not update Angular code
Expand Down Expand Up @@ -48,7 +49,7 @@ for testDir in $(ls | grep -v node_modules) ; do
if [[ $testDir == cli-hello-world ]]; then
yarn build
fi
trackPayloadSize "$testDir" "dist/*.js" true false
trackPayloadSize "$testDir" "dist/*.js" true false "${thisDir}/_payload-limits.json"
fi
)
done
Expand Down
35 changes: 22 additions & 13 deletions scripts/ci/payload-size.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Expand Down
19 changes: 7 additions & 12 deletions scripts/ci/payload-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ calculateSize() {
# Write to global variable $failed
# Read from global variables $size, $size7, $size9, $label, $limitUncompressed
checkSize() {
for fileType in "uncompressed" "gzip7" "gzip9"; do
if [[ ${size[$fileType]} -gt ${payloadLimits[$name, $fileType, $label]} ]]; then
failed=true
echo "$fileType $label size is ${size[$fileType]} which is greater than ${payloadLimits[$name, $fileType, $label]}"
fi
done
name="$1"
limitFile="$2"
node ${PROJECT_ROOT}/scripts/ci/payload-size.js $limitFile $name $TRAVIS_BRANCH
}

# Write timestamp to global variable $payloadData
Expand Down Expand Up @@ -92,14 +89,12 @@ uploadData() {
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
# $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
# $5 is the payload size limit file
trackPayloadSize() {
name="$1"
path="$2"
Expand All @@ -111,16 +106,16 @@ trackPayloadSize() {
for filename in $path; do
declare -A size
calculateSize
if [[ $checkSize = true ]]; then
checkSize
fi
done
addTimestamp
if [[ $trackChange = true ]]; then
addChange
fi
addMessage
uploadData $name
if [[ $checkSize = true ]]; then
checkSize $name "$5"
fi
if [[ $failed = true ]]; then
echo exit 1
exit 1
Expand Down