2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#!/usr/bin/env bash
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# WARNING: CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN should NOT be printed.
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								set +x -eu -o pipefail
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-18 14:49:30 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# Do not deploy if we are running in a fork.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								if [[ "$CI_REPO_OWNER/$CI_REPO_NAME" != "angular/angular" ]]; then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  echo "Skipping deploy because this is not angular/angular."
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  exit 0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Do not deploy if this is a PR. PRs are deployed in the `aio_preview` CircleCI job.
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								if [[ $CI_PULL_REQUEST != "false" ]]; then
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  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.
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-18 14:49:30 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								readonly latestCommit=$(git ls-remote origin $CI_BRANCH | cut -c1-40)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								if [[ $CI_COMMIT != $latestCommit ]]; then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  echo "Skipping deploy because $CI_COMMIT is not the latest commit ($latestCommit)."
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  exit 0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# The deployment mode is computed based on the branch we are building
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								if [[ $CI_BRANCH == master ]]; then
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  readonly deployEnv=next
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-18 14:49:30 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								elif [[ $CI_BRANCH == $CI_STABLE_BRANCH ]]; then
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-13 22:41:32 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  readonly deployEnv=stable
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								else
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-28 11:57:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  # Extract the major versions from the branches, e.g. the 4 from 4.3.x
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  readonly majorVersion=${CI_BRANCH%%.*}
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-18 14:49:30 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  readonly majorVersionStable=${CI_STABLE_BRANCH%%.*}
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-28 11:57:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # Do not deploy if the major version is not less than the stable branch major version
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-01 14:04:59 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  if [[ !( "$majorVersion" < "$majorVersionStable" ) ]]; then
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    echo "Skipping deploy of branch \"$CI_BRANCH\" to firebase."
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-18 14:49:30 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    echo "We only deploy archive branches with the major version less than the stable branch: \"$CI_STABLE_BRANCH\""
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-28 11:57:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    exit 0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01: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 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  # Do not deploy as it is not the latest branch for the given major version
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  if [[ $CI_BRANCH != $mostRecentMinorVersion ]]; then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    echo "Skipping deploy of branch \"$CI_BRANCH\" to firebase."
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    echo "There is a more recent branch with the same major version: \"$mostRecentMinorVersion\""
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    exit 0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-28 11:57:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  readonly deployEnv=archive
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								fi
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								case $deployEnv in
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  next)
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    readonly projectId=aio-staging
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-28 11:57:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    readonly deployedUrl=https://next.angular.io/
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ;;
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  stable)
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    readonly projectId=angular-io
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    readonly deployedUrl=https://angular.io/
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ;;
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  archive)
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-03 15:05:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    readonly projectId=v${majorVersion}-angular-io
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    readonly deployedUrl=https://v${majorVersion}.angular.io/
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ;;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								esac
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								echo "Git branch        : $CI_BRANCH"
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-27 16:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								echo "Build/deploy mode : $deployEnv"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								echo "Firebase project  : $projectId"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								echo "Deployment URL    : $deployedUrl"
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-08 02:35:07 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-08 23:59:25 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								if [[ ${1:-} == "--dry-run" ]]; then
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-28 11:57:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  exit 0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-08 02:35:07 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# Deploy
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  cd "`dirname $0`/.."
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # Build the app
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-09 14:52:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  yarn build --configuration=$deployEnv --progress=false
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-26 20:41:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  # Include any mode-specific files
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  cp -rf src/extra-files/$deployEnv/. dist/
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-30 18:32:32 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  # Set deployedUrl as parameter in the opensearch description
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # deployedUrl must end with /
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  yarn set-opensearch-url $deployedUrl
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-16 16:25:42 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  # Check payload size
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  yarn payload-size
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # Deploy to Firebase
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-25 13:07:45 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  yarn firebase use "$projectId" --token "$firebaseToken"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  yarn firebase deploy --message "Commit: $CI_COMMIT" --non-interactive --token "$firebaseToken"
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # Run PWA-score tests
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-17 19:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  yarn test-pwa-score "$deployedUrl" "$CI_AIO_MIN_PWA_SCORE"
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-23 11:36:02 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								)
							 |