From 5e2ce9b2a66a7295fb70907166eda76b7f17deb7 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 25 Oct 2018 13:50:32 +0300 Subject: [PATCH] build: clean up `*.gz` files created by `payload-size.sh` (#26746) These files are not needed once the size has been calculated and there is no point in keeping them around. Deleting them prevents, for example, uploading unnecessary files from `aio/dist/` to Firebase (because `deploy-to-firebase.sh` runs the payload size checks right before deploying). PR Close #26746 --- scripts/ci/payload-size.sh | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/scripts/ci/payload-size.sh b/scripts/ci/payload-size.sh index e7de0e8a75..350407533b 100644 --- a/scripts/ci/payload-size.sh +++ b/scripts/ci/payload-size.sh @@ -5,20 +5,30 @@ set -eu -o pipefail readonly PROJECT_NAME="angular-payload-size" NODE_MODULES_BIN=$PROJECT_ROOT/node_modules/.bin/ +# Get the gzip size of a file with the specified compression level. +# $1: string - The file path. +# $2: number - The level of compression. +getGzipSize() { + local filePath=$1 + local compLevel=$2 + local compPath=$1$2.gz + local size=-1 + + gzip -c -$compLevel "$filePath" >> "$compPath" + size=$(stat -c%s "$compPath") + rm "$compPath" + + echo $size +} + # Calculate the size of target file uncompressed size, gzip7 size, gzip9 size # Write to global variable $payloadData, $filename calculateSize() { - size["uncompressed"]=$(stat -c%s "$filename") label=$(echo "$filename" | sed "s/.*\///" | sed "s/\..*//") - payloadData="$payloadData\"uncompressed/$label\": ${size["uncompressed"]}, " - gzip -7 $filename -c >> "${filename}7.gz" - size["gzip7"]=$(stat -c%s "${filename}7.gz") - payloadData="$payloadData\"gzip7/$label\": ${size["gzip7"]}, " - - gzip -9 $filename -c >> "${filename}9.gz" - size["gzip9"]=$(stat -c%s "${filename}9.gz") - payloadData="$payloadData\"gzip9/$label\": ${size["gzip9"]}, " + payloadData="$payloadData\"uncompressed/$label\": $(stat -c%s "$filename"), " + payloadData="$payloadData\"gzip7/$label\": $(getGzipSize "$filename" 7), " + payloadData="$payloadData\"gzip9/$label\": $(getGzipSize "$filename" 9), " } # Check whether the file size is under limit. @@ -120,7 +130,6 @@ trackPayloadSize() { # Calculate the file sizes. for filename in $path; do - declare -A size calculateSize done