ci(aio): compute AIO deployment mode

There are now 3 modes for deployment: next, stable, archive.
We compute which mode (and other deployment properties)
from the `TRAVIS_BRANCH` and the `STABLE_BRANCH`.

If the TRAVIS_BRANCH is master we deploy as "next".
Otherwise if the branch is the highest of its minor versions
we deploy as "stable" if the `TRAVIS_BRANCH` matches the `STABLE_BRANCH` or
else "archive".

For "archive" deployments we compute the firebase project and deployment
url based on the major version of the `TRAVIS_BRANCH`.

As well as choosing where to deploy the build, we also use this
to select the environment file for the AIO Angular app.
This will enable the app to change its rendering and behaviour
based on its mode.

See #18287
This commit is contained in:
Peter Bacon Darwin 2017-07-27 16:12:04 +01:00 committed by Victor Berchet
parent ca695e0632
commit bcb36d9b6d
9 changed files with 87 additions and 58 deletions

View File

@ -31,8 +31,9 @@
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"stage": "environments/environment.stage.ts",
"prod": "environments/environment.prod.ts"
"next": "environments/environment.next.ts",
"stable": "environments/environment.stable.ts",
"archive": "environments/environment.archive.ts"
}
}
],

View File

@ -9,7 +9,7 @@
"ng": "yarn check-env && ng",
"start": "yarn check-env && ng serve",
"prebuild": "yarn check-env && yarn setup",
"build": "ng build -prod -sm -bo",
"build": "ng build --target=production --environment=stable -sm -bo",
"postbuild": "yarn sw-manifest && yarn sw-copy",
"lint": "yarn check-env && yarn docs-lint && ng lint && yarn example-lint",
"test": "yarn check-env && ng test",
@ -22,8 +22,7 @@
"example-e2e": "node ./tools/examples/run-example-e2e",
"example-lint": "tslint -c \"content/examples/tslint.json\" \"content/examples/**/*.ts\" -e \"content/examples/styleguide/**/*.avoid.ts\"",
"deploy-preview": "scripts/deploy-preview.sh",
"deploy-staging": "scripts/deploy-to-firebase.sh staging",
"deploy-production": "scripts/deploy-to-firebase.sh production",
"deploy-production": "scripts/deploy-to-firebase.sh",
"check-env": "node scripts/check-environment",
"payload-size": "scripts/payload.sh",
"predocs": "rimraf src/generated/{docs,*.json}",

View File

@ -3,27 +3,11 @@
# WARNING: FIREBASE_TOKEN should NOT be printed.
set +x -eu -o pipefail
readonly deployEnv=$1
case $deployEnv in
staging)
readonly buildEnv=stage
readonly projectId=aio-staging
readonly deployedUrl=https://$projectId.firebaseapp.com/
readonly firebaseToken=$FIREBASE_TOKEN
;;
production)
readonly buildEnv=prod
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
# 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)
@ -32,12 +16,67 @@ if [ $TRAVIS_COMMIT != $LATEST_COMMIT ]; then
exit 0
fi
# The deployment mode is computed based on the branch we are building
if [ $TRAVIS_BRANCH == master ]; then
readonly deployEnv=next
else
# Extract the major version from the branch that we are deploying, e.g. the 4 from 4.3.x
readonly majorVersion=${TRAVIS_BRANCH%%.*}
# 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
)
# Do not deploy as it is not the latest branch for the given major version
if [ $TRAVIS_BRANCH != $mostRecentMinorVersion ]; then
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
if [ $TRAVIS_BRANCH == $STABLE_BRANCH ]; then
readonly deployEnv=stable
else
readonly deployEnv=archive
fi
fi
case $deployEnv in
next)
readonly projectId=aio-staging
readonly deployedUrl=https://$projectId.firebaseapp.com/
readonly firebaseToken=$FIREBASE_TOKEN
;;
stable)
readonly projectId=angular-io
readonly deployedUrl=https://angular.io/
readonly firebaseToken=$FIREBASE_TOKEN
;;
archive)
readonly projectId=angular-io-${majorVersion}
readonly deployedUrl=https://v${majorVersion}.angular.io/
readonly firebaseToken=$FIREBASE_TOKEN
;;
esac
echo "Git branch : $TRAVIS_BRANCH"
echo "Build/deploy mode : $deployEnv"
echo "Firebase project : $projectId"
echo "Deployment URL : $deployedUrl"
# Deploy
(
cd "`dirname $0`/.."
# Build the app
yarn build -- --env=$buildEnv
yarn build -- --env=$deployEnv
# Check payload size
yarn payload-size

View File

@ -0,0 +1,6 @@
// This is for archived sites, which are hosted at https://vX.angular.io, where X is the major Angular version.
export const environment = {
gaId: 'UA-8594346-15', // Production id (since it is linked from the main site)
production: true,
mode: 'archive'
};

View File

@ -0,0 +1,6 @@
// This is for the staging site, which is hosted at https://next.angular.io (and https://aio-staging.firebaseapp.org)
export const environment = {
gaId: 'UA-8594346-15', // Production id (since it is linked from the main site)
production: true,
mode: 'next'
};

View File

@ -1,5 +1,6 @@
// This is for the production site, which is hosted at https://angular.io
export const environment = {
gaId: 'UA-8594346-15',
production: true
gaId: 'UA-8594346-15', // Production id
production: true,
mode: 'stable'
};

View File

@ -1,5 +0,0 @@
// This is for the staging site, which is hosted at https://aio-staging.firebaseapp.org
export const environment = {
gaId: 'UA-8594346-26',
production: true
};

View File

@ -13,6 +13,7 @@ import 'core-js/es7/reflect';
export const environment = {
gaId: 'UA-8594346-26', // Staging site
production: false
gaId: 'UA-8594346-26', // Development id
production: false,
mode: 'stable'
};

View File

@ -28,6 +28,7 @@ fi
case ${CI_MODE} in
e2e)
# Don't deploy if this is a PR build
if [[ ${TRAVIS_PULL_REQUEST} != "false" ]]; then
@ -39,34 +40,14 @@ case ${CI_MODE} in
${thisDir}/publish-build-artifacts.sh
travisFoldEnd "deploy.packages"
;;
aio)
# Only deploy if this not a PR. PRs are deployed early in `build.sh`.
if [[ $TRAVIS_PULL_REQUEST == "false" ]]; then
# Don't deploy if this build is not for master or the stable branch.
if [[ $TRAVIS_BRANCH != "master" ]] && [[ $TRAVIS_BRANCH != $STABLE_BRANCH ]]; then
echo "Skipping deploy because this build is not for master or the stable branch ($STABLE_BRANCH)."
exit 0
fi
travisFoldStart "deploy.aio"
(
cd ${TRAVIS_BUILD_DIR}/aio
if [[ $TRAVIS_BRANCH == $STABLE_BRANCH ]]; then
# This is upstream <stable-branch>: Deploy to production.
travisFoldStart "deploy.aio.production"
yarn deploy-production
travisFoldEnd "deploy.aio.production"
else
# This is upstream master: Deploy to staging.
travisFoldStart "deploy.aio.staging"
yarn deploy-staging
travisFoldEnd "deploy.aio.staging"
fi
yarn deploy-production
)
travisFoldEnd "deploy.aio"
fi
;;
esac