2017-05-23 20:20:56 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-07-14 01:50:05 -04:00
|
|
|
set -eu -o pipefail
|
2017-06-15 13:10:28 -04:00
|
|
|
|
2017-06-22 19:47:53 -04:00
|
|
|
readonly thisDir=$(cd $(dirname $0); pwd)
|
2017-06-30 13:08:33 -04:00
|
|
|
readonly parentDir=$(dirname $thisDir)
|
2017-05-23 20:20:56 -04:00
|
|
|
readonly PROJECT_NAME="angular-payload-size"
|
|
|
|
|
2017-06-30 13:08:33 -04:00
|
|
|
source ${thisDir}/_payload-limits.sh
|
2017-05-23 20:20:56 -04:00
|
|
|
|
|
|
|
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, "
|
|
|
|
|
|
|
|
|
2017-06-07 00:12:51 -04:00
|
|
|
gzip -7 $filename -c >> "${filename}7.gz"
|
|
|
|
size7=$(stat -c%s "${filename}7.gz")
|
2017-05-23 20:20:56 -04:00
|
|
|
payloadData="$payloadData\"gzip7/$label\": $size7, "
|
|
|
|
|
2017-06-07 00:12:51 -04:00
|
|
|
gzip -9 $filename -c >> "${filename}9.gz"
|
|
|
|
size9=$(stat -c%s "${filename}9.gz")
|
2017-05-23 20:20:56 -04:00
|
|
|
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, "
|
|
|
|
|
2017-06-15 13:10:28 -04:00
|
|
|
# Add change source: application, dependencies, or 'application+dependencies'
|
2017-06-30 13:08:33 -04:00
|
|
|
applicationChanged=false
|
|
|
|
dependenciesChanged=false
|
|
|
|
if [[ $(git diff --name-only $TRAVIS_COMMIT_RANGE $parentDir | grep -v aio/yarn.lock | grep -v content) ]]; then
|
|
|
|
applicationChanged=true
|
|
|
|
fi
|
|
|
|
if [[ $(git diff --name-only $TRAVIS_COMMIT_RANGE $parentDir/yarn.lock) ]]; then
|
|
|
|
dependenciesChanged=true
|
2017-07-14 17:54:31 -04:00
|
|
|
fi
|
|
|
|
|
2017-06-30 13:08:33 -04:00
|
|
|
if $dependenciesChanged && $applicationChanged; then
|
|
|
|
change='application+dependencies'
|
|
|
|
elif $dependenciesChanged; then
|
2017-06-16 21:21:45 -04:00
|
|
|
# only yarn.lock changed
|
2017-05-23 20:20:56 -04:00
|
|
|
change='dependencies'
|
2017-06-30 13:08:33 -04:00
|
|
|
elif $applicationChanged; then
|
2017-06-15 14:26:25 -04:00
|
|
|
change='application'
|
2017-05-23 20:20:56 -04:00
|
|
|
else
|
2017-06-22 13:14:09 -04:00
|
|
|
# Nothing changed in aio/
|
|
|
|
exit 0
|
2017-05-23 20:20:56 -04:00
|
|
|
fi
|
2017-08-02 18:59:20 -04:00
|
|
|
message=$(echo $TRAVIS_COMMIT_MESSAGE | sed 's/"/\\"/g' | sed 's/\\/\\\\/g')
|
|
|
|
payloadData="$payloadData\"change\": \"$change\", \"message\": \"$message\""
|
2017-05-23 20:20:56 -04:00
|
|
|
|
|
|
|
payloadData="{${payloadData}}"
|
|
|
|
|
|
|
|
echo $payloadData
|
|
|
|
|
2017-06-15 14:26:25 -04:00
|
|
|
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
|
2017-06-30 10:12:59 -04:00
|
|
|
readonly safeBranchName=$(echo $TRAVIS_BRANCH | sed -e 's/\./_/g')
|
|
|
|
readonly dbPath=/payload/aio/$safeBranchName/$TRAVIS_COMMIT
|
2017-07-14 01:50:05 -04:00
|
|
|
|
|
|
|
# WARNING: FIREBASE_TOKEN should NOT be printed.
|
|
|
|
set +x
|
2017-06-30 13:08:33 -04:00
|
|
|
firebase database:update --data "$payloadData" --project $PROJECT_NAME --confirm --token "$ANGULAR_PAYLOAD_FIREBASE_TOKEN" $dbPath
|
2017-05-23 20:20:56 -04:00
|
|
|
fi
|
|
|
|
|
2017-06-15 14:26:25 -04:00
|
|
|
if [[ $failed = true ]]; then
|
2017-05-23 20:20:56 -04:00
|
|
|
exit 1
|
|
|
|
fi
|