Skip to content

Commit 10897d6

Browse files
petebacondarwinvicb
authored andcommitted
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 angular#18287 Closes angular#18297
1 parent 340837a commit 10897d6

8 files changed

Lines changed: 192 additions & 23 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ env:
5353
- CI_MODE=browserstack_required
5454
- CI_MODE=saucelabs_optional
5555
- CI_MODE=browserstack_optional
56-
- CI_MODE=docs_test
56+
- CI_MODE=aio_tools_test
5757
- CI_MODE=aio
5858
- CI_MODE=aio_e2e AIO_SHARD=0
5959
- CI_MODE=aio_e2e AIO_SHARD=1

aio/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"docs-watch": "node tools/transforms/authors-package/watchr.js",
3131
"docs-lint": "eslint --ignore-path=\"tools/transforms/.eslintignore\" tools/transforms",
3232
"docs-test": "node tools/transforms/test.js",
33+
"tools-test": "./scripts/deploy-to-firebase.test.sh && yarn docs-test",
3334
"serve-and-sync": "concurrently --kill-others \"yarn docs-watch\" \"yarn start\"",
3435
"~~update-webdriver": "webdriver-manager update --standalone false --gecko false",
3536
"boilerplate:add": "node ./tools/examples/example-boilerplate add",

aio/scripts/deploy-to-firebase.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@ fi
1111

1212
# Do not deploy if the current commit is not the latest on its branch.
1313
readonly LATEST_COMMIT=$(git ls-remote origin $TRAVIS_BRANCH | cut -c1-40)
14-
if [ $TRAVIS_COMMIT != $LATEST_COMMIT ]; then
14+
if [[ $TRAVIS_COMMIT != $LATEST_COMMIT ]]; then
1515
echo "Skipping deploy because $TRAVIS_COMMIT is not the latest commit ($LATEST_COMMIT)."
1616
exit 0
1717
fi
1818

1919
# The deployment mode is computed based on the branch we are building
20-
if [ $TRAVIS_BRANCH == master ]; then
20+
if [[ $TRAVIS_BRANCH == master ]]; then
2121
readonly deployEnv=next
22+
elif [[ $TRAVIS_BRANCH == $STABLE_BRANCH ]]; then
23+
readonly deployEnv=stable
2224
else
23-
# Extract the major version from the branch that we are deploying, e.g. the 4 from 4.3.x
25+
# Extract the major versions from the branches, e.g. the 4 from 4.3.x
2426
readonly majorVersion=${TRAVIS_BRANCH%%.*}
27+
readonly majorVersionStable=${STABLE_BRANCH%%.*}
28+
29+
# Do not deploy if the major version is not less than the stable branch major version
30+
if [[ $majorVersion -ge $majorVersionStable ]]; then
31+
echo "Skipping deploy of branch \"${TRAVIS_BRANCH}\" to firebase."
32+
echo "We only deploy archive branches with the major version less than the stable branch: \"${STABLE_BRANCH}\""
33+
exit 0
34+
fi
35+
2536
# Find the branch that has highest minor version for the given `$majorVersion`
2637
readonly mostRecentMinorVersion=$(
2738
# List the branches that start with the major version
@@ -35,23 +46,19 @@ else
3546
)
3647

3748
# Do not deploy as it is not the latest branch for the given major version
38-
if [ $TRAVIS_BRANCH != $mostRecentMinorVersion ]; then
49+
if [[ $TRAVIS_BRANCH != $mostRecentMinorVersion ]]; then
3950
echo "Skipping deploy of branch \"${TRAVIS_BRANCH}\" to firebase."
4051
echo "There is a more recent branch with the same major version: \"${mostRecentMinorVersion}\""
4152
exit 0
4253
fi
4354

44-
if [ $TRAVIS_BRANCH == $STABLE_BRANCH ]; then
45-
readonly deployEnv=stable
46-
else
47-
readonly deployEnv=archive
48-
fi
55+
readonly deployEnv=archive
4956
fi
5057

5158
case $deployEnv in
5259
next)
5360
readonly projectId=aio-staging
54-
readonly deployedUrl=https://$projectId.firebaseapp.com/
61+
readonly deployedUrl=https://next.angular.io/
5562
readonly firebaseToken=$FIREBASE_TOKEN
5663
;;
5764
stable)
@@ -71,6 +78,10 @@ echo "Build/deploy mode : $deployEnv"
7178
echo "Firebase project : $projectId"
7279
echo "Deployment URL : $deployedUrl"
7380

81+
if [[ $1 == "--dry-run" ]]; then
82+
exit 0
83+
fi
84+
7485
# Deploy
7586
(
7687
cd "`dirname $0`/.."
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env bash
2+
3+
function check {
4+
if [[ $1 == $2 ]]; then
5+
echo Pass
6+
exit 0
7+
fi
8+
echo Fail
9+
echo ---- Expected ----
10+
echo "$2"
11+
echo ---- Actual ----
12+
echo "$1"
13+
exit 1
14+
}
15+
16+
(
17+
echo ===== master - skip deploy - pull request
18+
actual=$(
19+
export TRAVIS_PULL_REQUEST=true
20+
`dirname $0`/deploy-to-firebase.sh --dry-run
21+
)
22+
expected="Skipping deploy because this is a PR build."
23+
check "$actual" "$expected"
24+
)
25+
26+
(
27+
echo ===== master - deploy success
28+
actual=$(
29+
export TRAVIS_PULL_REQUEST=false
30+
export TRAVIS_BRANCH=master
31+
export TRAVIS_COMMIT=$(git ls-remote origin master | cut -c-40)
32+
export FIREBASE_TOKEN=XXXXX
33+
`dirname $0`/deploy-to-firebase.sh --dry-run
34+
)
35+
expected="Git branch : master
36+
Build/deploy mode : next
37+
Firebase project : aio-staging
38+
Deployment URL : https://next.angular.io/"
39+
check "$actual" "$expected"
40+
)
41+
42+
(
43+
echo ===== master - skip deploy - commit not HEAD
44+
actual=$(
45+
export TRAVIS_PULL_REQUEST=false
46+
export TRAVIS_BRANCH=master
47+
export TRAVIS_COMMIT=DUMMY_TEST_COMMIT
48+
`dirname $0`/deploy-to-firebase.sh --dry-run
49+
)
50+
expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin master | cut -c1-40))."
51+
check "$actual" "$expected"
52+
)
53+
54+
(
55+
echo ===== stable - deploy success
56+
actual=$(
57+
export TRAVIS_PULL_REQUEST=false
58+
export TRAVIS_BRANCH=4.3.x
59+
export STABLE_BRANCH=4.3.x
60+
export TRAVIS_COMMIT=$(git ls-remote origin 4.3.x | cut -c-40)
61+
export FIREBASE_TOKEN=XXXXX
62+
`dirname $0`/deploy-to-firebase.sh --dry-run
63+
)
64+
expected="Git branch : 4.3.x
65+
Build/deploy mode : stable
66+
Firebase project : angular-io
67+
Deployment URL : https://angular.io/"
68+
check "$actual" "$expected"
69+
)
70+
71+
(
72+
echo ===== stable - skip deploy - commit not HEAD
73+
actual=$(
74+
export TRAVIS_PULL_REQUEST=false
75+
export TRAVIS_BRANCH=4.3.x
76+
export STABLE_BRANCH=4.3.x
77+
export TRAVIS_COMMIT=DUMMY_TEST_COMMIT
78+
`dirname $0`/deploy-to-firebase.sh --dry-run
79+
)
80+
expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin 4.3.x | cut -c1-40))."
81+
check "$actual" "$expected"
82+
)
83+
84+
(
85+
echo ===== archive - deploy success
86+
actual=$(
87+
export TRAVIS_PULL_REQUEST=false
88+
export TRAVIS_BRANCH=2.4.x
89+
export STABLE_BRANCH=4.3.x
90+
export TRAVIS_COMMIT=$(git ls-remote origin 2.4.x | cut -c-40)
91+
export FIREBASE_TOKEN=XXXXX
92+
`dirname $0`/deploy-to-firebase.sh --dry-run
93+
)
94+
expected="Git branch : 2.4.x
95+
Build/deploy mode : archive
96+
Firebase project : angular-io-2
97+
Deployment URL : https://v2.angular.io/"
98+
check "$actual" "$expected"
99+
)
100+
101+
(
102+
echo ===== archive - skip deploy - commit not HEAD
103+
actual=$(
104+
export TRAVIS_PULL_REQUEST=false
105+
export TRAVIS_BRANCH=2.4.x
106+
export STABLE_BRANCH=4.3.x
107+
export TRAVIS_COMMIT=DUMMY_TEST_COMMIT
108+
export FIREBASE_TOKEN=XXXXX
109+
`dirname $0`/deploy-to-firebase.sh --dry-run
110+
)
111+
expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin 2.4.x | cut -c1-40))."
112+
check "$actual" "$expected"
113+
)
114+
115+
(
116+
echo ===== archive - skip deploy - major version too high, lower minor
117+
actual=$(
118+
export TRAVIS_PULL_REQUEST=false
119+
export TRAVIS_BRANCH=2.1.x
120+
export STABLE_BRANCH=2.2.x
121+
export TRAVIS_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40)
122+
export FIREBASE_TOKEN=XXXXX
123+
`dirname $0`/deploy-to-firebase.sh --dry-run
124+
)
125+
expected="Skipping deploy of branch \"2.1.x\" to firebase.
126+
We only deploy archive branches with the major version less than the stable branch: \"2.2.x\""
127+
check "$actual" "$expected"
128+
)
129+
130+
(
131+
echo ===== archive - skip deploy - major version too high, higher minor
132+
actual=$(
133+
export TRAVIS_PULL_REQUEST=false
134+
export TRAVIS_BRANCH=2.4.x
135+
export STABLE_BRANCH=2.2.x
136+
export TRAVIS_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40)
137+
export FIREBASE_TOKEN=XXXXX
138+
`dirname $0`/deploy-to-firebase.sh --dry-run
139+
)
140+
expected="Skipping deploy of branch \"2.1.x\" to firebase.
141+
We only deploy archive branches with the major version less than the stable branch: \"2.2.x\""
142+
check "$actual" "$expected"
143+
)
144+
145+
(
146+
echo ===== archive - skip deploy - minor version too low
147+
actual=$(
148+
export TRAVIS_PULL_REQUEST=false
149+
export TRAVIS_BRANCH=2.1.x
150+
export STABLE_BRANCH=4.3.x
151+
export TRAVIS_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40)
152+
export FIREBASE_TOKEN=XXXXX
153+
`dirname $0`/deploy-to-firebase.sh --dry-run
154+
)
155+
expected="Skipping deploy of branch \"2.1.x\" to firebase.
156+
There is a more recent branch with the same major version: \"2.4.x\""
157+
check "$actual" "$expected"
158+
)

scripts/ci/deploy.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ case ${CI_MODE} in
4242
;;
4343

4444
aio)
45-
travisFoldStart "deploy.aio"
46-
(
47-
cd ${TRAVIS_BUILD_DIR}/aio
48-
yarn deploy-production
49-
)
50-
travisFoldEnd "deploy.aio"
51-
fi
45+
travisFoldStart "deploy.aio"
46+
(
47+
cd ${TRAVIS_BUILD_DIR}/aio
48+
yarn deploy-production
49+
)
50+
travisFoldEnd "deploy.aio"
5251
;;
5352
esac

scripts/ci/install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ if [[ ${CI_MODE} != "aio" && ${CI_MODE} != 'docs_test' ]]; then
4242
fi
4343

4444

45-
if [[ ${TRAVIS} && (${CI_MODE} == "e2e" || ${CI_MODE} == "e2e_2" || ${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e" || ${CI_MODE} == "docs_test") ]]; then
45+
if [[ ${TRAVIS} && (${CI_MODE} == "e2e" || ${CI_MODE} == "e2e_2" || ${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e" || ${CI_MODE} == "aio_tools_test") ]]; then
4646
# Install version of yarn that we are locked against
4747
travisFoldStart "install-yarn"
4848
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version "${YARN_VERSION}"
4949
travisFoldEnd "install-yarn"
5050
fi
5151

5252

53-
if [[ ${TRAVIS} && (${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e" || ${CI_MODE} == "docs_test") ]]; then
53+
if [[ ${TRAVIS} && (${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e" || ${CI_MODE} == "aio_tools_test") ]]; then
5454
# angular.io: Install all yarn dependencies according to angular.io/yarn.lock
5555
travisFoldStart "yarn-install.aio"
5656
(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ source ${thisDir}/_travis-fold.sh
1010
travisFoldStart "test.docs"
1111
(
1212
cd ${PROJECT_ROOT}/aio
13-
yarn docs-test
13+
yarn tools-test
1414
)
1515
travisFoldEnd "test.docs"

scripts/ci/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ case ${CI_MODE} in
3737
browserstack_optional)
3838
${thisDir}/test-browserstack.sh
3939
;;
40-
docs_test)
41-
${thisDir}/test-docs.sh
40+
aio_tools_test)
41+
${thisDir}/test-aio-tools.sh
4242
;;
4343
aio)
4444
${thisDir}/test-aio.sh

0 commit comments

Comments
 (0)