ci(aio): deploy commits on the stable branch to production

The current stable branch is determined based on the current version mapped to
the npm `latest` tag (by replacing the patch version number with 'x' - e.g.
`1.2.3` --> `1.2.x`).
PRs against the stable branch will be deployed to the preview server (as long as
the rest of the requirements are met). Commits on the stable branch itself will
be deployed to production.

Fixes #16908
This commit is contained in:
Georgios Kalpakas 2017-05-23 11:36:02 +03:00 committed by Alex Rickabaugh
parent ed73d4f3ac
commit 234268eec2
7 changed files with 74 additions and 50 deletions

View File

@ -1,5 +0,0 @@
{
"projects": {
"staging": "aio-staging"
}
}

View File

@ -20,7 +20,8 @@
"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-staging.sh",
"deploy-staging": "scripts/deploy-to-firebase.sh staging",
"deploy-production": "scripts/deploy-to-firebase.sh production",
"check-env": "node ../tools/check-environment.js",
"predocs": "rimraf src/generated/{docs,*.json}",
"docs": "dgeni ./tools/transforms/angular.io-package",

View File

@ -1,24 +0,0 @@
#!/usr/bin/env bash
# WARNING: FIREBASE_TOKEN should NOT be printed.
set +x -eu -o pipefail
FIREBASE_PROJECT_ID=aio-staging
DEPLOYED_URL=https://$FIREBASE_PROJECT_ID.firebaseapp.com
(
cd "`dirname $0`/.."
# Build the app
yarn build
# Deploy to staging
firebase use "$FIREBASE_PROJECT_ID" --token "$FIREBASE_TOKEN"
firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$FIREBASE_TOKEN"
# Run PWA-score tests
# TODO(gkalpak): Figure out why this fails and re-enable.
sleep 10
yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE" "$PWA_RESULTS_LOG" || true
)

View File

@ -0,0 +1,39 @@
#!/usr/bin/env bash
# WARNING: FIREBASE_TOKEN should NOT be printed.
set +x -eu -o pipefail
readonly deployEnv=$1
case $deployEnv in
staging)
readonly projectId=aio-staging
readonly deployedUrl=https://$projectId.firebaseapp.com/
readonly firebaseToken=$FIREBASE_TOKEN
;;
production)
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
(
cd "`dirname $0`/.."
# Build the app
yarn build
# Deploy to Firebase
firebase use "$projectId" --token "$firebaseToken"
firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$firebaseToken"
# Run PWA-score tests
# TODO(gkalpak): Figure out why this fails and re-enable.
yarn test-pwa-score -- "$deployedUrl" "$MIN_PWA_SCORE" "$PWA_RESULTS_LOG" || true
)

View File

@ -44,10 +44,10 @@ if [[ ${CI_MODE:-} == "aio" ]]; then
cd "`dirname $0`/../../aio"
yarn build
# If this is a PR for angular/angular@master, deploy a snapshot for previewing early
# (if preconditions are met) regardless of the test outcome.
# If this is a PR for angular/angular@master or angular/angular@<stable-branch>, deploy a
# snapshot for previewing early (if preconditions are met) regardless of the test outcome.
if [[ ${TRAVIS_REPO_SLUG} == "angular/angular" ]] &&
[[ ${TRAVIS_BRANCH} == "master" ]] &&
([[ $TRAVIS_BRANCH == "master" ]] || [[ $TRAVIS_BRANCH == $STABLE_BRANCH ]]) &&
[[ $TRAVIS_PULL_REQUEST != "false" ]]; then
travisFoldStart "deploy.aio.pr-preview"
yarn deploy-preview -- --skip-build

View File

@ -40,24 +40,33 @@ case ${CI_MODE} in
travisFoldEnd "deploy.packages"
;;
aio)
# Don't deploy if this build is not for master
if [[ ${TRAVIS_BRANCH} != "master" ]]; then
echo "Skipping deploy because this build is not for master."
exit 0
fi
# Only deploy if this not a PR. PRs are deployed early in `build.sh`.
if [[ $TRAVIS_PULL_REQUEST == "false" ]]; then
travisFoldStart "deploy.aio"
(
cd ${TRAVIS_BUILD_DIR}/aio
# Only deploy if this not a PR. PRs are deployed early in `build.sh`.
if [[ $TRAVIS_PULL_REQUEST == "false" ]]; then
# This is upstream master: Deploy to staging
travisFoldStart "deploy.aio.staging"
yarn deploy-staging
travisFoldEnd "deploy.aio.staging"
# 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
)
travisFoldEnd "deploy.aio"
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
)
travisFoldEnd "deploy.aio"
fi
;;
esac

View File

@ -59,6 +59,10 @@ if [[ ${TRAVIS:-} ]]; then
setEnvVar KARMA_JS_BROWSERS `node -e "console.log(require('/home/travis/build/angular/angular/browser-providers.conf').browserstackAliases.CI_OPTIONAL.join(','))"`
;;
aio)
# Determine the current stable branch.
readonly versionRe="^\s*([0-9]+\.[0-9]+)\.[0-9]+.*$"
setEnvVar STABLE_BRANCH `npm info @angular/core dist-tags.latest | sed -r "s/$versionRe/\1.x/"`
setEnvVar MIN_PWA_SCORE 95
;;
esac