2017-05-23 04:36:02 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# WARNING: FIREBASE_TOKEN should NOT be printed.
|
|
|
|
set +x -eu -o pipefail
|
|
|
|
|
2017-07-27 11:12:04 -04:00
|
|
|
# Only deploy if this not a PR. PRs are deployed early in `build.sh`.
|
|
|
|
if [[ $TRAVIS_PULL_REQUEST != "false" ]]; then
|
|
|
|
echo "Skipping deploy because this is a PR build."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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)
|
2017-07-28 06:57:44 -04:00
|
|
|
if [[ $TRAVIS_COMMIT != $LATEST_COMMIT ]]; then
|
2017-07-27 11:12:04 -04:00
|
|
|
echo "Skipping deploy because $TRAVIS_COMMIT is not the latest commit ($LATEST_COMMIT)."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# The deployment mode is computed based on the branch we are building
|
2017-07-28 06:57:44 -04:00
|
|
|
if [[ $TRAVIS_BRANCH == master ]]; then
|
2017-07-27 11:12:04 -04:00
|
|
|
readonly deployEnv=next
|
2017-07-28 06:57:44 -04:00
|
|
|
elif [[ $TRAVIS_BRANCH == $STABLE_BRANCH ]]; then
|
|
|
|
readonly deployEnv=stable
|
2017-07-27 11:12:04 -04:00
|
|
|
else
|
2017-07-28 06:57:44 -04:00
|
|
|
# Extract the major versions from the branches, e.g. the 4 from 4.3.x
|
2017-07-27 11:12:04 -04:00
|
|
|
readonly majorVersion=${TRAVIS_BRANCH%%.*}
|
2017-07-28 06:57:44 -04:00
|
|
|
readonly majorVersionStable=${STABLE_BRANCH%%.*}
|
|
|
|
|
|
|
|
# Do not deploy if the major version is not less than the stable branch major version
|
2017-09-01 17:04:59 -04:00
|
|
|
if [[ !( "$majorVersion" < "$majorVersionStable" ) ]]; then
|
2017-07-28 06:57:44 -04:00
|
|
|
echo "Skipping deploy of branch \"${TRAVIS_BRANCH}\" to firebase."
|
|
|
|
echo "We only deploy archive branches with the major version less than the stable branch: \"${STABLE_BRANCH}\""
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2017-07-27 11:12:04 -04:00
|
|
|
# Find the branch that has highest minor version for the given `$majorVersion`
|
|
|
|
readonly mostRecentMinorVersion=$(
|
|
|
|
# List the branches that start with the major version
|
|
|
|
git ls-remote origin refs/heads/${majorVersion}.*.x |
|
|
|
|
# Extract the version number
|
|
|
|
awk -F'/' '{print $3}' |
|
|
|
|
# Sort by the minor version
|
|
|
|
sort -t. -k 2,2n |
|
|
|
|
# Get the highest version
|
|
|
|
tail -n1
|
|
|
|
)
|
2017-05-23 04:36:02 -04:00
|
|
|
|
2017-07-27 11:12:04 -04:00
|
|
|
# Do not deploy as it is not the latest branch for the given major version
|
2017-07-28 06:57:44 -04:00
|
|
|
if [[ $TRAVIS_BRANCH != $mostRecentMinorVersion ]]; then
|
2017-07-27 11:12:04 -04:00
|
|
|
echo "Skipping deploy of branch \"${TRAVIS_BRANCH}\" to firebase."
|
|
|
|
echo "There is a more recent branch with the same major version: \"${mostRecentMinorVersion}\""
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2017-07-28 06:57:44 -04:00
|
|
|
readonly deployEnv=archive
|
2017-07-27 11:12:04 -04:00
|
|
|
fi
|
2017-05-23 04:36:02 -04:00
|
|
|
|
|
|
|
case $deployEnv in
|
2017-07-27 11:12:04 -04:00
|
|
|
next)
|
2017-05-23 04:36:02 -04:00
|
|
|
readonly projectId=aio-staging
|
2017-07-28 06:57:44 -04:00
|
|
|
readonly deployedUrl=https://next.angular.io/
|
2017-05-23 04:36:02 -04:00
|
|
|
readonly firebaseToken=$FIREBASE_TOKEN
|
|
|
|
;;
|
2017-07-27 11:12:04 -04:00
|
|
|
stable)
|
2017-05-23 04:36:02 -04:00
|
|
|
readonly projectId=angular-io
|
|
|
|
readonly deployedUrl=https://angular.io/
|
|
|
|
readonly firebaseToken=$FIREBASE_TOKEN
|
|
|
|
;;
|
2017-07-27 11:12:04 -04:00
|
|
|
archive)
|
|
|
|
readonly projectId=angular-io-${majorVersion}
|
|
|
|
readonly deployedUrl=https://v${majorVersion}.angular.io/
|
|
|
|
readonly firebaseToken=$FIREBASE_TOKEN
|
2017-05-23 04:36:02 -04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2017-07-27 11:12:04 -04:00
|
|
|
echo "Git branch : $TRAVIS_BRANCH"
|
|
|
|
echo "Build/deploy mode : $deployEnv"
|
|
|
|
echo "Firebase project : $projectId"
|
|
|
|
echo "Deployment URL : $deployedUrl"
|
2017-07-07 19:35:07 -04:00
|
|
|
|
2017-08-08 16:59:25 -04:00
|
|
|
if [[ ${1:-} == "--dry-run" ]]; then
|
2017-07-28 06:57:44 -04:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2017-07-07 19:35:07 -04:00
|
|
|
# Deploy
|
2017-05-23 04:36:02 -04:00
|
|
|
(
|
|
|
|
cd "`dirname $0`/.."
|
|
|
|
|
|
|
|
# Build the app
|
2017-07-27 11:12:04 -04:00
|
|
|
yarn build -- --env=$deployEnv
|
2017-05-23 04:36:02 -04:00
|
|
|
|
2017-07-26 15:41:45 -04:00
|
|
|
# Include any mode-specific files
|
|
|
|
cp -rf src/extra-files/$deployEnv/. dist/
|
|
|
|
|
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
|
2017-08-28 15:39:21 -04:00
|
|
|
firebase use "$projectId" --token "$firebaseToken"
|
|
|
|
firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$firebaseToken"
|
2017-05-23 04:36:02 -04:00
|
|
|
|
|
|
|
# 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
|
|
|
)
|