From 0440251919402214f5c09e11af516e64b5b040b8 Mon Sep 17 00:00:00 2001 From: Yuan Gao Date: Tue, 23 May 2017 17:20:56 -0700 Subject: [PATCH] ci(aio): upload aio payload size to firebase ci(aio): Add timestamp and change data --- .travis.yml | 4 ++ aio/package.json | 2 +- aio/scripts/deploy-preview.sh | 1 + aio/scripts/deploy-to-firebase.sh | 3 ++ aio/scripts/payload.sh | 66 +++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100755 aio/scripts/payload.sh diff --git a/.travis.yml b/.travis.yml index 1268f56c84..ac22d5cda7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,10 @@ env: # This is needed for publishing builds to the "aio-staging" and "angular-io" firebase projects. # This token was generated using the aio-deploy@angular.io account using `firebase login:ci` and password from valentine - secure: "L5CyQmpwWtoR4Qi4xlWQh/cL1M6ZeJL4W4QAr4HdKFMgYt9h+Whqkymyh2NxwmCbPvWa7yUd+OiLQUDCY7L2VIg16hTwoe2CgYDyQA0BEwLzxtRrJXl93TfwMlrUx5JSIzAccD6D4sjtz8kSFMomK2Nls33xOXOukwyhVMjd0Cg=" + # ANGULAR_PAYLOAD_FIREBASE_TOKEN + # This is for payload size data + # TODO(i): the token was generated using the tinagao@google account, we should switch to a shared/role-base account. + - secure: "gx0VkaVIAgPt2YZIaNomVgBx8u/5lvVsLTZSkPu8AM0Wdpzy06yKhAO2x56oI51y3FFSLssVw1JEJ9BEL8osnATk0+e6ERL9OZl6fgbf/6WgBBz4wDzMaQ5+yYWGJfwY5AzZdbYUWfh3wVIhH+Q03WmnJgcnnLUaty+YeUFa2Os=" matrix: # Order: a slower build first, so that we don't occupy an idle travis worker waiting for others to complete. - CI_MODE=e2e diff --git a/aio/package.json b/aio/package.json index 9216688377..129ff20deb 100644 --- a/aio/package.json +++ b/aio/package.json @@ -21,10 +21,10 @@ "test-pwa-score": "node scripts/test-pwa-score", "example-e2e": "node ./tools/examples/run-example-e2e", "example-lint": "tslint -c \"content/examples/tslint.json\" \"content/examples/**/*.ts\" -e \"content/examples/styleguide/**/*.avoid.ts\"", - "deploy-preview": "scripts/deploy-preview.sh", "deploy-staging": "scripts/deploy-to-firebase.sh staging", "deploy-production": "scripts/deploy-to-firebase.sh production", "check-env": "node scripts/check-environment", + "payload-size": "scripts/payload.sh", "predocs": "rimraf src/generated/{docs,*.json}", "docs": "dgeni ./tools/transforms/angular.io-package", "docs-watch": "node tools/transforms/authors-package/watchr.js", diff --git a/aio/scripts/deploy-preview.sh b/aio/scripts/deploy-preview.sh index c5e6bb6478..a41ecaec72 100755 --- a/aio/scripts/deploy-preview.sh +++ b/aio/scripts/deploy-preview.sh @@ -28,6 +28,7 @@ readonly relevantChangedFilesCount=$(git diff --name-only $TRAVIS_COMMIT_RANGE | yarn build fi tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" . + yarn payload-size # Deploy to staging readonly httpCode=$( diff --git a/aio/scripts/deploy-to-firebase.sh b/aio/scripts/deploy-to-firebase.sh index 931ea29453..aa06907c83 100755 --- a/aio/scripts/deploy-to-firebase.sh +++ b/aio/scripts/deploy-to-firebase.sh @@ -35,6 +35,9 @@ esac firebase use "$projectId" --token "$firebaseToken" firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$firebaseToken" + # Check payload size + yarn payload-size + # Run PWA-score tests yarn test-pwa-score -- "$deployedUrl" "$MIN_PWA_SCORE" "$PWA_RESULTS_LOG" ) diff --git a/aio/scripts/payload.sh b/aio/scripts/payload.sh new file mode 100755 index 0000000000..d384de826b --- /dev/null +++ b/aio/scripts/payload.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +readonly TOKEN=$ANGULAR_PAYLOAD_FIREBASE_TOKEN +readonly PROJECT_NAME="angular-payload-size" +readonly OUTPUT_FILE=/tmp/snapshot.tar.gz + +source scripts/payload-limit.sh + +failed=false +payloadData="" +for filename in dist/*.bundle.js; do + size=$(stat -c%s "$filename") + label=$(echo "$filename" | sed "s/.*\///" | sed "s/\..*//") + payloadData="$payloadData\"uncompressed/$label\": $size, " + + + gzip -7 --keep -f $filename + size7=$(stat -c%s "$filename.gz") + payloadData="$payloadData\"gzip7/$label\": $size7, " + + gzip -9 --keep -f $filename + size9=$(stat -c%s "$filename.gz") + payloadData="$payloadData\"gzip9/$label\": $size9, " + + if [[ $size -gt ${limitUncompressed[$label]} ]]; then + failed=true + echo "Uncompressed $label size is $size which is greater than ${limitUncompressed[$label]}" + elif [[ $size7 -gt ${limitGzip7[$label]} ]]; then + failed=true + echo "Gzip7 $label size is $size7 which is greater than ${limitGzip7[$label]}" + elif [[ $size9 -gt ${limitGzip9[$label]} ]]; then + failed=true + echo "Gzip9 $label size is $size9 which is greater than ${limitGzip9[$label]}" + fi +done + +# Add Timestamp +timestamp=$(date +%s) +payloadData="$payloadData\"timestamp\": $timestamp, " + +# Add change source: local, dependencies, or 'local+dependencies' +allChangedFiles=$(git diff --name-only $TRAVIS_COMMIT_RANGE) +yarnChangedFiles=$(git diff --name-only $TRAVIS_COMMIT_RANGE | grep yarn.lock) + +if [ $allChangedFiles ] && [ $yarnChangedFiles ] && [ "$allChangedFiles" -ne "$yarnChangedFiles" ]; then + change='local+dependencies' +elif [[ ! -z $yarnChangedFiles ]]; then + change='dependencies' +elif [[ ! -z $allChangedFiles ]]; then + change='local' +else + change='' +fi +payloadData="$payloadData\"change\": \"$change\"" + +payloadData="{${payloadData}}" + +echo $payloadData + +if [[ $TRAVIS_PULL_REQUEST == "false" ]]; then + firebase database:update --data "$payloadData" --project $PROJECT_NAME --confirm --token "$TOKEN" /payload/aio/$TRAVIS_COMMIT +fi + +if [ $failed = true ]; then + exit 1 +fi