ci(aio): upload aio payload size to firebase

ci(aio): Add timestamp and change data
This commit is contained in:
Yuan Gao 2017-05-23 17:20:56 -07:00 committed by Matias Niemelä
parent 08ecfd891d
commit 0440251919
5 changed files with 75 additions and 1 deletions

View File

@ -37,6 +37,10 @@ env:
# This is needed for publishing builds to the "aio-staging" and "angular-io" firebase projects. # 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 # This token was generated using the aio-deploy@angular.io account using `firebase login:ci` and password from valentine
- secure: "L5CyQmpwWtoR4Qi4xlWQh/cL1M6ZeJL4W4QAr4HdKFMgYt9h+Whqkymyh2NxwmCbPvWa7yUd+OiLQUDCY7L2VIg16hTwoe2CgYDyQA0BEwLzxtRrJXl93TfwMlrUx5JSIzAccD6D4sjtz8kSFMomK2Nls33xOXOukwyhVMjd0Cg=" - 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: matrix:
# Order: a slower build first, so that we don't occupy an idle travis worker waiting for others to complete. # Order: a slower build first, so that we don't occupy an idle travis worker waiting for others to complete.
- CI_MODE=e2e - CI_MODE=e2e

View File

@ -21,10 +21,10 @@
"test-pwa-score": "node scripts/test-pwa-score", "test-pwa-score": "node scripts/test-pwa-score",
"example-e2e": "node ./tools/examples/run-example-e2e", "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\"", "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-staging": "scripts/deploy-to-firebase.sh staging",
"deploy-production": "scripts/deploy-to-firebase.sh production", "deploy-production": "scripts/deploy-to-firebase.sh production",
"check-env": "node scripts/check-environment", "check-env": "node scripts/check-environment",
"payload-size": "scripts/payload.sh",
"predocs": "rimraf src/generated/{docs,*.json}", "predocs": "rimraf src/generated/{docs,*.json}",
"docs": "dgeni ./tools/transforms/angular.io-package", "docs": "dgeni ./tools/transforms/angular.io-package",
"docs-watch": "node tools/transforms/authors-package/watchr.js", "docs-watch": "node tools/transforms/authors-package/watchr.js",

View File

@ -28,6 +28,7 @@ readonly relevantChangedFilesCount=$(git diff --name-only $TRAVIS_COMMIT_RANGE |
yarn build yarn build
fi fi
tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" . tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" .
yarn payload-size
# Deploy to staging # Deploy to staging
readonly httpCode=$( readonly httpCode=$(

View File

@ -35,6 +35,9 @@ esac
firebase use "$projectId" --token "$firebaseToken" firebase use "$projectId" --token "$firebaseToken"
firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$firebaseToken" firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$firebaseToken"
# Check payload size
yarn payload-size
# Run PWA-score tests # Run PWA-score tests
yarn test-pwa-score -- "$deployedUrl" "$MIN_PWA_SCORE" "$PWA_RESULTS_LOG" yarn test-pwa-score -- "$deployedUrl" "$MIN_PWA_SCORE" "$PWA_RESULTS_LOG"
) )

66
aio/scripts/payload.sh Executable file
View File

@ -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