From bcb36d9b6d972d8ff1be8e3f72ccd096d5790fb6 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 27 Jul 2017 16:12:04 +0100 Subject: [PATCH] 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 --- aio/.angular-cli.json | 5 +- aio/package.json | 5 +- aio/scripts/deploy-to-firebase.sh | 83 ++++++++++++++----- aio/src/environments/environment.archive.ts | 6 ++ aio/src/environments/environment.next.ts | 6 ++ ...ironment.prod.ts => environment.stable.ts} | 5 +- aio/src/environments/environment.stage.ts | 5 -- aio/src/environments/environment.ts | 5 +- scripts/ci/deploy.sh | 25 +----- 9 files changed, 87 insertions(+), 58 deletions(-) create mode 100644 aio/src/environments/environment.archive.ts create mode 100644 aio/src/environments/environment.next.ts rename aio/src/environments/{environment.prod.ts => environment.stable.ts} (57%) delete mode 100644 aio/src/environments/environment.stage.ts diff --git a/aio/.angular-cli.json b/aio/.angular-cli.json index 6b3ef2df2f..10b25f2812 100644 --- a/aio/.angular-cli.json +++ b/aio/.angular-cli.json @@ -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" } } ], diff --git a/aio/package.json b/aio/package.json index 54ace41568..2d7da6c94c 100644 --- a/aio/package.json +++ b/aio/package.json @@ -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}", diff --git a/aio/scripts/deploy-to-firebase.sh b/aio/scripts/deploy-to-firebase.sh index a14ba8965b..b9e3d22449 100755 --- a/aio/scripts/deploy-to-firebase.sh +++ b/aio/scripts/deploy-to-firebase.sh @@ -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 diff --git a/aio/src/environments/environment.archive.ts b/aio/src/environments/environment.archive.ts new file mode 100644 index 0000000000..5100c50a77 --- /dev/null +++ b/aio/src/environments/environment.archive.ts @@ -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' +}; diff --git a/aio/src/environments/environment.next.ts b/aio/src/environments/environment.next.ts new file mode 100644 index 0000000000..63682ea65e --- /dev/null +++ b/aio/src/environments/environment.next.ts @@ -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' +}; diff --git a/aio/src/environments/environment.prod.ts b/aio/src/environments/environment.stable.ts similarity index 57% rename from aio/src/environments/environment.prod.ts rename to aio/src/environments/environment.stable.ts index 0f5ad5b335..f454b83ddc 100644 --- a/aio/src/environments/environment.prod.ts +++ b/aio/src/environments/environment.stable.ts @@ -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' }; diff --git a/aio/src/environments/environment.stage.ts b/aio/src/environments/environment.stage.ts deleted file mode 100644 index 97a992c88f..0000000000 --- a/aio/src/environments/environment.stage.ts +++ /dev/null @@ -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 -}; diff --git a/aio/src/environments/environment.ts b/aio/src/environments/environment.ts index 165a718f55..77d62f0968 100644 --- a/aio/src/environments/environment.ts +++ b/aio/src/environments/environment.ts @@ -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' }; diff --git a/scripts/ci/deploy.sh b/scripts/ci/deploy.sh index c5a85f576b..a6914d590e 100755 --- a/scripts/ci/deploy.sh +++ b/scripts/ci/deploy.sh @@ -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 : 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