ci: fix the payload-size checking scripts (#20683)
The scripts were accidentally broken in #20524. More specifically, when a limit was exceeded the script would break while trying to log an error message due to a missing `commit` variable. This commit fixes it and also does some minor clean-up (improve docs, use more descriptive variable names, remove dead code, etc). PR Close #20683
This commit is contained in:

committed by
Igor Minar

parent
9dc310eb50
commit
6c78cfb9d1
@ -1,5 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eu -o pipefail
|
||||
|
||||
readonly PROJECT_NAME="angular-payload-size"
|
||||
|
||||
# Calculate the size of target file uncompressed size, gzip7 size, gzip9 size
|
||||
@ -18,23 +20,24 @@ calculateSize() {
|
||||
payloadData="$payloadData\"gzip9/$label\": ${size["gzip9"]}, "
|
||||
}
|
||||
|
||||
# Check whether the file size is under limit
|
||||
# Write to global variable $failed
|
||||
# Read from global variables $size, $size7, $size9, $label, $limitUncompressed
|
||||
# Check whether the file size is under limit.
|
||||
# Exit with an error if limit is exceeded.
|
||||
# $1: string - The name in database.
|
||||
# $2: string - The payload size limit file.
|
||||
checkSize() {
|
||||
name="$1"
|
||||
limitFile="$2"
|
||||
node ${PROJECT_ROOT}/scripts/ci/payload-size.js $limitFile $name $TRAVIS_BRANCH
|
||||
node ${PROJECT_ROOT}/scripts/ci/payload-size.js $limitFile $name $TRAVIS_BRANCH $TRAVIS_COMMIT
|
||||
}
|
||||
|
||||
# Write timestamp to global variable $payloadData
|
||||
# Write timestamp to global variable `$payloadData`.
|
||||
addTimestamp() {
|
||||
# Add Timestamp
|
||||
timestamp=$(date +%s)
|
||||
payloadData="$payloadData\"timestamp\": $timestamp, "
|
||||
}
|
||||
|
||||
# Write travis commit message to global variable $payloadData
|
||||
# Write travis commit message to global variable `$payloadData`.
|
||||
addMessage() {
|
||||
# Grab the set of SHAs for the message. This can fail when you force push or do initial build
|
||||
# because $TRAVIS_COMMIT_RANGE will contain the previous SHA which will not be in the
|
||||
@ -44,9 +47,9 @@ addMessage() {
|
||||
payloadData="$payloadData\"message\": \"$message\""
|
||||
}
|
||||
|
||||
# Add change source: application, dependencies, or 'application+dependencies'
|
||||
# Read from global variables $parentDir
|
||||
# Update the change source to global variable $payloadData
|
||||
# Add change source: `application`, `dependencies`, or `application+dependencies`
|
||||
# Read from global variable `$parentDir`.
|
||||
# Update the change source in global variable `$payloadData`.
|
||||
addChange() {
|
||||
yarnChanged=false
|
||||
allChangedFiles=$(git diff --name-only $TRAVIS_COMMIT_RANGE $parentDir | wc -l)
|
||||
@ -70,8 +73,8 @@ addChange() {
|
||||
payloadData="$payloadData\"change\": \"$change\", "
|
||||
}
|
||||
|
||||
# Upload data to firebase database if it's commit, print out data for pull
|
||||
# requests
|
||||
# Upload data to firebase database if it's commit, print out data for pull requests.
|
||||
# $1: string - The name in database.
|
||||
uploadData() {
|
||||
name="$1"
|
||||
payloadData="{${payloadData}}"
|
||||
@ -91,18 +94,21 @@ uploadData() {
|
||||
fi
|
||||
}
|
||||
|
||||
# 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
|
||||
# Track payload size.
|
||||
# $1: string - The name in database.
|
||||
# $2: string - The file path.
|
||||
# $3: true | false - Whether to check the payload size and fail the test if it exceeds limit.
|
||||
# $4: true | false - Whether to record the type of changes.
|
||||
# $5: [string] - The payload size limit file. Only necessary if `$3` is `true`.
|
||||
trackPayloadSize() {
|
||||
name="$1"
|
||||
path="$2"
|
||||
checkSize="$3"
|
||||
trackChange=$4
|
||||
trackChange="$4"
|
||||
limitFile="${5:-}"
|
||||
|
||||
payloadData=""
|
||||
failed=false
|
||||
|
||||
for filename in $path; do
|
||||
declare -A size
|
||||
calculateSize
|
||||
@ -114,10 +120,6 @@ trackPayloadSize() {
|
||||
addMessage
|
||||
uploadData $name
|
||||
if [[ $checkSize = true ]]; then
|
||||
checkSize $name "$5"
|
||||
fi
|
||||
if [[ $failed = true ]]; then
|
||||
echo exit 1
|
||||
exit 1
|
||||
checkSize $name $limitFile
|
||||
fi
|
||||
}
|
||||
|
Reference in New Issue
Block a user