From c421ccaae9817d5f6ea46caac000202e4fe0e9d5 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Fri, 28 Jul 2017 11:57:44 +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". If the `TRAVIS_BRANCH` matches the `STABLE_BRANCH` we deploy as "stable". Otherwise if the branch has a major version lower than the stable version and its minor version is highest of similar branches we deploy as "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 --- .travis.yml | 2 +- aio/package.json | 1 + aio/scripts/deploy-to-firebase.sh | 31 ++-- aio/scripts/deploy-to-firebase.test.sh | 158 ++++++++++++++++++ scripts/ci/deploy.sh | 13 +- scripts/ci/install.sh | 4 +- .../ci/{test-docs.sh => test-aio-tools.sh} | 2 +- scripts/ci/test.sh | 4 +- 8 files changed, 192 insertions(+), 23 deletions(-) create mode 100755 aio/scripts/deploy-to-firebase.test.sh rename scripts/ci/{test-docs.sh => test-aio-tools.sh} (92%) diff --git a/.travis.yml b/.travis.yml index d574adc770..04c0c2a707 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,7 +53,7 @@ env: - CI_MODE=browserstack_required - CI_MODE=saucelabs_optional - CI_MODE=browserstack_optional - - CI_MODE=docs_test + - CI_MODE=aio_tools_test - CI_MODE=aio - CI_MODE=aio_e2e AIO_SHARD=0 - CI_MODE=aio_e2e AIO_SHARD=1 diff --git a/aio/package.json b/aio/package.json index 2d7da6c94c..7309a5c78a 100644 --- a/aio/package.json +++ b/aio/package.json @@ -30,6 +30,7 @@ "docs-watch": "node tools/transforms/authors-package/watchr.js", "docs-lint": "eslint --ignore-path=\"tools/transforms/.eslintignore\" tools/transforms", "docs-test": "node tools/transforms/test.js", + "tools-test": "./scripts/deploy-to-firebase.test.sh && yarn docs-test", "serve-and-sync": "concurrently --kill-others \"yarn docs-watch\" \"yarn start\"", "~~update-webdriver": "webdriver-manager update --standalone false --gecko false", "boilerplate:add": "node ./tools/examples/example-boilerplate add", diff --git a/aio/scripts/deploy-to-firebase.sh b/aio/scripts/deploy-to-firebase.sh index 0e95fc74c7..1542067de0 100755 --- a/aio/scripts/deploy-to-firebase.sh +++ b/aio/scripts/deploy-to-firebase.sh @@ -11,17 +11,28 @@ 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) -if [ $TRAVIS_COMMIT != $LATEST_COMMIT ]; then +if [[ $TRAVIS_COMMIT != $LATEST_COMMIT ]]; then 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 -if [ $TRAVIS_BRANCH == master ]; then +if [[ $TRAVIS_BRANCH == master ]]; then readonly deployEnv=next +elif [[ $TRAVIS_BRANCH == $STABLE_BRANCH ]]; then + readonly deployEnv=stable else - # Extract the major version from the branch that we are deploying, e.g. the 4 from 4.3.x + # Extract the major versions from the branches, e.g. the 4 from 4.3.x readonly majorVersion=${TRAVIS_BRANCH%%.*} + readonly majorVersionStable=${STABLE_BRANCH%%.*} + + # Do not deploy if the major version is not less than the stable branch major version + if [[ $majorVersion -ge $majorVersionStable ]]; then + 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 + # Find the branch that has highest minor version for the given `$majorVersion` readonly mostRecentMinorVersion=$( # List the branches that start with the major version @@ -35,23 +46,19 @@ else ) # Do not deploy as it is not the latest branch for the given major version - if [ $TRAVIS_BRANCH != $mostRecentMinorVersion ]; then + 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 + readonly deployEnv=archive fi case $deployEnv in next) readonly projectId=aio-staging - readonly deployedUrl=https://$projectId.firebaseapp.com/ + readonly deployedUrl=https://next.angular.io/ readonly firebaseToken=$FIREBASE_TOKEN ;; stable) @@ -71,6 +78,10 @@ echo "Build/deploy mode : $deployEnv" echo "Firebase project : $projectId" echo "Deployment URL : $deployedUrl" +if [[ $1 == "--dry-run" ]]; then + exit 0 +fi + # Deploy ( cd "`dirname $0`/.." diff --git a/aio/scripts/deploy-to-firebase.test.sh b/aio/scripts/deploy-to-firebase.test.sh new file mode 100755 index 0000000000..dd9a3235fd --- /dev/null +++ b/aio/scripts/deploy-to-firebase.test.sh @@ -0,0 +1,158 @@ +#!/usr/bin/env bash + +function check { + if [[ $1 == $2 ]]; then + echo Pass + exit 0 + fi + echo Fail + echo ---- Expected ---- + echo "$2" + echo ---- Actual ---- + echo "$1" + exit 1 +} + +( + echo ===== master - skip deploy - pull request + actual=$( + export TRAVIS_PULL_REQUEST=true + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Skipping deploy because this is a PR build." + check "$actual" "$expected" +) + +( + echo ===== master - deploy success + actual=$( + export TRAVIS_PULL_REQUEST=false + export TRAVIS_BRANCH=master + export TRAVIS_COMMIT=$(git ls-remote origin master | cut -c-40) + export FIREBASE_TOKEN=XXXXX + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Git branch : master +Build/deploy mode : next +Firebase project : aio-staging +Deployment URL : https://next.angular.io/" + check "$actual" "$expected" +) + +( + echo ===== master - skip deploy - commit not HEAD + actual=$( + export TRAVIS_PULL_REQUEST=false + export TRAVIS_BRANCH=master + export TRAVIS_COMMIT=DUMMY_TEST_COMMIT + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin master | cut -c1-40))." + check "$actual" "$expected" +) + +( + echo ===== stable - deploy success + actual=$( + export TRAVIS_PULL_REQUEST=false + export TRAVIS_BRANCH=4.3.x + export STABLE_BRANCH=4.3.x + export TRAVIS_COMMIT=$(git ls-remote origin 4.3.x | cut -c-40) + export FIREBASE_TOKEN=XXXXX + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Git branch : 4.3.x +Build/deploy mode : stable +Firebase project : angular-io +Deployment URL : https://angular.io/" + check "$actual" "$expected" +) + +( + echo ===== stable - skip deploy - commit not HEAD + actual=$( + export TRAVIS_PULL_REQUEST=false + export TRAVIS_BRANCH=4.3.x + export STABLE_BRANCH=4.3.x + export TRAVIS_COMMIT=DUMMY_TEST_COMMIT + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin 4.3.x | cut -c1-40))." + check "$actual" "$expected" +) + +( + echo ===== archive - deploy success + actual=$( + export TRAVIS_PULL_REQUEST=false + export TRAVIS_BRANCH=2.4.x + export STABLE_BRANCH=4.3.x + export TRAVIS_COMMIT=$(git ls-remote origin 2.4.x | cut -c-40) + export FIREBASE_TOKEN=XXXXX + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Git branch : 2.4.x +Build/deploy mode : archive +Firebase project : angular-io-2 +Deployment URL : https://v2.angular.io/" + check "$actual" "$expected" +) + +( + echo ===== archive - skip deploy - commit not HEAD + actual=$( + export TRAVIS_PULL_REQUEST=false + export TRAVIS_BRANCH=2.4.x + export STABLE_BRANCH=4.3.x + export TRAVIS_COMMIT=DUMMY_TEST_COMMIT + export FIREBASE_TOKEN=XXXXX + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin 2.4.x | cut -c1-40))." + check "$actual" "$expected" +) + +( + echo ===== archive - skip deploy - major version too high, lower minor + actual=$( + export TRAVIS_PULL_REQUEST=false + export TRAVIS_BRANCH=2.1.x + export STABLE_BRANCH=2.2.x + export TRAVIS_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40) + export FIREBASE_TOKEN=XXXXX + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Skipping deploy of branch \"2.1.x\" to firebase. +We only deploy archive branches with the major version less than the stable branch: \"2.2.x\"" + check "$actual" "$expected" +) + +( + echo ===== archive - skip deploy - major version too high, higher minor + actual=$( + export TRAVIS_PULL_REQUEST=false + export TRAVIS_BRANCH=2.4.x + export STABLE_BRANCH=2.2.x + export TRAVIS_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40) + export FIREBASE_TOKEN=XXXXX + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Skipping deploy of branch \"2.1.x\" to firebase. +We only deploy archive branches with the major version less than the stable branch: \"2.2.x\"" + check "$actual" "$expected" +) + +( + echo ===== archive - skip deploy - minor version too low + actual=$( + export TRAVIS_PULL_REQUEST=false + export TRAVIS_BRANCH=2.1.x + export STABLE_BRANCH=4.3.x + export TRAVIS_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40) + export FIREBASE_TOKEN=XXXXX + `dirname $0`/deploy-to-firebase.sh --dry-run + ) + expected="Skipping deploy of branch \"2.1.x\" to firebase. +There is a more recent branch with the same major version: \"2.4.x\"" + check "$actual" "$expected" +) diff --git a/scripts/ci/deploy.sh b/scripts/ci/deploy.sh index a6914d590e..e88bac203a 100755 --- a/scripts/ci/deploy.sh +++ b/scripts/ci/deploy.sh @@ -42,12 +42,11 @@ case ${CI_MODE} in ;; aio) - travisFoldStart "deploy.aio" - ( - cd ${TRAVIS_BUILD_DIR}/aio - yarn deploy-production - ) - travisFoldEnd "deploy.aio" - fi + travisFoldStart "deploy.aio" + ( + cd ${TRAVIS_BUILD_DIR}/aio + yarn deploy-production + ) + travisFoldEnd "deploy.aio" ;; esac diff --git a/scripts/ci/install.sh b/scripts/ci/install.sh index 67aee1a004..45dce806e2 100755 --- a/scripts/ci/install.sh +++ b/scripts/ci/install.sh @@ -42,7 +42,7 @@ if [[ ${CI_MODE} != "aio" && ${CI_MODE} != 'docs_test' ]]; then fi -if [[ ${TRAVIS} && (${CI_MODE} == "e2e" || ${CI_MODE} == "e2e_2" || ${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e" || ${CI_MODE} == "docs_test") ]]; then +if [[ ${TRAVIS} && (${CI_MODE} == "e2e" || ${CI_MODE} == "e2e_2" || ${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e" || ${CI_MODE} == "aio_tools_test") ]]; then # Install version of yarn that we are locked against travisFoldStart "install-yarn" curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version "${YARN_VERSION}" @@ -50,7 +50,7 @@ if [[ ${TRAVIS} && (${CI_MODE} == "e2e" || ${CI_MODE} == "e2e_2" || ${CI_MODE} = fi -if [[ ${TRAVIS} && (${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e" || ${CI_MODE} == "docs_test") ]]; then +if [[ ${TRAVIS} && (${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e" || ${CI_MODE} == "aio_tools_test") ]]; then # angular.io: Install all yarn dependencies according to angular.io/yarn.lock travisFoldStart "yarn-install.aio" ( diff --git a/scripts/ci/test-docs.sh b/scripts/ci/test-aio-tools.sh similarity index 92% rename from scripts/ci/test-docs.sh rename to scripts/ci/test-aio-tools.sh index 74d8a90593..cf608c4312 100755 --- a/scripts/ci/test-docs.sh +++ b/scripts/ci/test-aio-tools.sh @@ -10,6 +10,6 @@ source ${thisDir}/_travis-fold.sh travisFoldStart "test.docs" ( cd ${PROJECT_ROOT}/aio - yarn docs-test + yarn tools-test ) travisFoldEnd "test.docs" diff --git a/scripts/ci/test.sh b/scripts/ci/test.sh index d8f08932b3..a72da1aca7 100755 --- a/scripts/ci/test.sh +++ b/scripts/ci/test.sh @@ -37,8 +37,8 @@ case ${CI_MODE} in browserstack_optional) ${thisDir}/test-browserstack.sh ;; - docs_test) - ${thisDir}/test-docs.sh + aio_tools_test) + ${thisDir}/test-aio-tools.sh ;; aio) ${thisDir}/test-aio.sh