ci: fix `payload-size.sh` (#26377)

PR Close #26377
This commit is contained in:
George Kalpakas 2018-10-18 15:43:58 +03:00 committed by Alex Rickabaugh
parent 1bbf28ad19
commit 9b8a244a15
4 changed files with 42 additions and 30 deletions

View File

@ -25,8 +25,9 @@ var_3: &define_env_vars
# This is the branch being built; e.g. `pull/12345` for PR builds.
echo "export CI_BRANCH=$CIRCLE_BRANCH" | tee -a $BASH_ENV
echo "export CI_COMMIT=$CIRCLE_SHA1" | tee -a $BASH_ENV
# TODO(gkalpak): Fix this.
echo "export CI_COMMIT_RANGE=???" | tee -a $BASH_ENV
# `CI_COMMIT_RANGE` will only be available when `CIRCLE_COMPARE_URL` is also available,
# i.e. on push builds (a.k.a. non-PR builds). That is fine, since we only need it in push builds.
echo "export CI_COMMIT_RANGE=$(sed -r 's|^.*/([0-9a-f]+\.\.\.[0-9a-f]+)$|\1|i' <<< ${CIRCLE_COMPARE_URL:-})" | tee -a $BASH_ENV
echo "export CI_PULL_REQUEST=${CIRCLE_PR_NUMBER:-false}" | tee -a $BASH_ENV
echo "export CI_REPO_NAME=$CIRCLE_PROJECT_REPONAME" | tee -a $BASH_ENV
echo "export CI_REPO_OWNER=$CIRCLE_PROJECT_USERNAME" | tee -a $BASH_ENV
@ -172,8 +173,7 @@ jobs:
command: xvfb-run --auto-servernum yarn --cwd aio test-pwa-score-localhost $CI_AIO_MIN_PWA_SCORE
# Check the bundle sizes.
# (Run before unit and e2e tests, which destroy the `dist/` directory.)
# TODO(gkalpak): Fix this.
# - run: yarn --cwd aio payload-size
- run: yarn --cwd aio payload-size
# Run unit tests
- run: xvfb-run --auto-servernum yarn --cwd aio test --watch=false
# Run e2e tests

View File

@ -34,10 +34,6 @@ 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 to "angular-payload-size" firebase project
# This token was generated using the payload@angular.io account using `firebase login:ci` and password from valentine
- secure: "SxotP/ymNy6uWAVbfwM9BlwETPEBpkRvU/F7fCtQDDic99WfQHzzUSQqHTk8eKk3GrGAOSL09vT0WfStQYEIGEoS5UHWNgOnelxhw+d5EnaoB8vQ0dKQBTK092hQg4feFprr+B/tCasyMV6mVwpUzZMbIJNn/Rx7H5g1bp+Gkfg="
matrix:
# Order: a slower build first, so that we don't occupy an idle travis worker waiting for others to complete.
- CI_MODE=e2e

View File

@ -48,7 +48,6 @@ setEnvVar CI_PULL_REQUEST $TRAVIS_PULL_REQUEST
setEnvVar PROJECT_ROOT $(cd ${thisDir}/../..; pwd)
# WARNING: Secrets (do not print).
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=$FIREBASE_TOKEN
export CI_SECRET_PAYLOAD_FIREBASE_TOKEN=$ANGULAR_PAYLOAD_FIREBASE_TOKEN
if [[ ${TRAVIS:-} ]]; then
case ${CI_MODE} in

View File

@ -42,22 +42,28 @@ addTimestamp() {
}
# Write travis commit message to global variable `$payloadData`.
# $1: string - The commit range for this build (in `<SHA-1>...<SHA-2>` format).
addMessage() {
commitRange="$1"
# Grab the set of SHAs for the message. This can fail when you force push or do initial build
# because $CI_COMMIT_RANGE may contain the previous SHA which will not be in the
# force push or commit, hence we default to last commit.
message=$(git log --oneline $CI_COMMIT_RANGE -- || git log --oneline -n1)
message=$(git log --oneline $commitRange -- || git log --oneline -n1)
message=$(echo $message | sed 's/\\/\\\\/g' | sed 's/"/\\"/g')
payloadData="$payloadData\"message\": \"$message\""
payloadData="$payloadData\"message\": \"$message\", "
}
# Add change source: `application`, `dependencies`, or `application+dependencies`
# Read from global variable `$parentDir`.
# Update the change source in global variable `$payloadData`.
addChange() {
# $1: string - The commit range for this build (in `<SHA-1>...<SHA-2>` format).
addChangeType() {
commitRange="$1"
yarnChanged=false
allChangedFiles=$(git diff --name-only $CI_COMMIT_RANGE $parentDir | wc -l)
allChangedFileNames=$(git diff --name-only $CI_COMMIT_RANGE $parentDir)
allChangedFiles=$(git diff --name-only $commitRange $parentDir | wc -l)
allChangedFileNames=$(git diff --name-only $commitRange $parentDir)
if [[ $allChangedFileNames == *"yarn.lock"* ]]; then
yarnChanged=true
@ -77,23 +83,24 @@ addChange() {
payloadData="$payloadData\"change\": \"$change\", "
}
# Convert the current `payloadData` value to a JSON string.
# (Basically remove trailing `,` and wrap in `{...}`.)
payloadToJson() {
echo "{$(sed -r 's|, *$||' <<< $payloadData)}"
}
# 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}}"
echo $payloadData > /tmp/current.log
readonly safeBranchName=$(echo $CI_BRANCH | sed -e 's/\./_/g')
readonly dbPath=/payload/$name/$safeBranchName/$CI_COMMIT
readonly jsonPayload=$(payloadToJson)
if [[ "$CI_PULL_REQUEST" == "false" ]]; then
readonly dbPath=/payload/$name/$safeBranchName/$CI_COMMIT
# WARNING: CI_SECRET_PAYLOAD_FIREBASE_TOKEN should NOT be printed.
set +x
$NODE_MODULES_BIN/firebase database:update --data "$payloadData" --project $PROJECT_NAME --confirm --token "$CI_SECRET_PAYLOAD_FIREBASE_TOKEN" $dbPath
fi
# WARNING: CI_SECRET_PAYLOAD_FIREBASE_TOKEN should NOT be printed.
set +x
$NODE_MODULES_BIN/firebase database:update --data "$jsonPayload" --project $PROJECT_NAME --confirm --token "$CI_SECRET_PAYLOAD_FIREBASE_TOKEN" $dbPath
}
# Track payload size.
@ -106,21 +113,31 @@ trackPayloadSize() {
name="$1"
path="$2"
checkSize="$3"
trackChange="$4"
trackChangeType="$4"
limitFile="${5:-}"
payloadData=""
# Calculate the file sizes.
for filename in $path; do
declare -A size
calculateSize
done
addTimestamp
if [[ $trackChange = true ]]; then
addChange
# Save the file sizes to be retrieved from `payload-size.js`.
echo "$(payloadToJson)" > /tmp/current.log
# If this is a non-PR build, upload the data to firebase.
if [[ "$CI_PULL_REQUEST" == "false" ]]; then
if [[ $trackChangeType = true ]]; then
addChangeType $CI_COMMIT_RANGE
fi
addTimestamp
addMessage $CI_COMMIT_RANGE
uploadData $name
fi
addMessage
uploadData $name
# Check the file sizes against the specified limits.
if [[ $checkSize = true ]]; then
checkSize $name $limitFile
fi