2017-05-23 04:36:02 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# WARNING: FIREBASE_TOKEN should NOT be printed.
|
|
|
|
set +x -eu -o pipefail
|
|
|
|
|
|
|
|
|
|
|
|
readonly deployEnv=$1
|
|
|
|
|
|
|
|
case $deployEnv in
|
|
|
|
staging)
|
2017-06-12 18:51:39 -04:00
|
|
|
readonly buildEnv=stage
|
2017-05-23 04:36:02 -04:00
|
|
|
readonly projectId=aio-staging
|
|
|
|
readonly deployedUrl=https://$projectId.firebaseapp.com/
|
|
|
|
readonly firebaseToken=$FIREBASE_TOKEN
|
|
|
|
;;
|
|
|
|
production)
|
2017-06-12 18:51:39 -04:00
|
|
|
readonly buildEnv=prod
|
2017-05-23 04:36:02 -04:00
|
|
|
readonly projectId=angular-io
|
|
|
|
readonly deployedUrl=https://angular.io/
|
|
|
|
readonly firebaseToken=$FIREBASE_TOKEN
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown deployment environment ('$deployEnv'). Expected 'staging' or 'production'."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2017-07-07 19:35:07 -04:00
|
|
|
# Do not deploy if the current commit is not the latest on its branch.
|
|
|
|
readonly LATEST_COMMIT=$(git ls-remote origin $TRAVIS_BRANCH | cut -c1-40)
|
|
|
|
if [ $TRAVIS_COMMIT != $LATEST_COMMIT ]; then
|
|
|
|
echo "Skipping deploy because $TRAVIS_COMMIT is not the latest commit ($LATEST_COMMIT)."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Deploy
|
2017-05-23 04:36:02 -04:00
|
|
|
(
|
|
|
|
cd "`dirname $0`/.."
|
|
|
|
|
|
|
|
# Build the app
|
2017-06-12 18:51:39 -04:00
|
|
|
yarn build -- --env=$buildEnv
|
2017-05-23 04:36:02 -04:00
|
|
|
|
2017-06-16 19:25:42 -04:00
|
|
|
# Check payload size
|
|
|
|
yarn payload-size
|
|
|
|
|
2017-05-23 04:36:02 -04:00
|
|
|
# Deploy to Firebase
|
|
|
|
firebase use "$projectId" --token "$firebaseToken"
|
|
|
|
firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$firebaseToken"
|
|
|
|
|
|
|
|
# Run PWA-score tests
|
2017-06-30 05:09:53 -04:00
|
|
|
yarn test-pwa-score -- "$deployedUrl" "$MIN_PWA_SCORE"
|
2017-05-23 04:36:02 -04:00
|
|
|
)
|