44set -e
55
66function usage {
7- echo " Usage: $0 <project_id >"
7+ echo " Usage: $0 <project_id_node_6> <project_id_node_8 >"
88 exit 1
99}
1010
11+ # This script takes 1 or 2 params, both of which are Firebase project ids.
12+ # If there is only one given, that project will be used for both node6 and node8
13+ # Otherwise, param1 will be used for node6
14+ # and param2 will be used for node8
1115# The first parameter is required and is the Firebase project id.
1216if [[ $1 == " " ]]; then
1317 usage
1418fi
15- PROJECT_ID=$1
19+ if [[ $2 == " " ]]; then
20+ PROJECT_ID_NODE_6=$1
21+ PROJECT_ID_NODE_8=$1
22+ else
23+ PROJECT_ID_NODE_6=$1
24+ PROJECT_ID_NODE_8=$2
25+ fi
1626
1727# Directory where this script lives.
1828DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
@@ -31,11 +41,13 @@ function build_sdk {
3141
3242function pick_node6 {
3343 cd $DIR
44+ PROJECT_ID=$PROJECT_ID_NODE_6
3445 cp package.node6.json functions/package.json
3546}
3647
3748function pick_node8 {
3849 cd $DIR
50+ PROJECT_ID=$PROJECT_ID_NODE_8
3951 cp package.node8.json functions/package.json
4052}
4153
@@ -51,15 +63,47 @@ function delete_all_functions {
5163 cd $DIR
5264 # Try to delete, if there are errors it is because the project is already empty,
5365 # in that case do nothing.
54- firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --project=$PROJECT_ID -f || :
66+ firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_6 || : &
67+ if ! [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then
68+ firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_8 || : &
69+ fi
70+ wait
5571 announce " Project emptied."
5672}
5773
5874function deploy {
5975 cd $DIR
6076 ./functions/node_modules/.bin/tsc -p functions/
61- # Deploy functions, and security rules for database and Firestore
62- firebase deploy --project=$PROJECT_ID --only functions,database,firestore
77+ # Deploy functions, and security rules for database and Firestore. If the deploy fails, retry twice
78+ for i in 1 2 3; do firebase deploy --project=$PROJECT_ID --only functions,database,firestore && break ; done
79+ }
80+
81+ # At the moment, functions take 30-40 seconds AFTER firebase deploy returns successfully to go live
82+ # This needs to be fixed separately
83+ # However, so that we have working integration tests in the interim, waitForPropagation is a workaround
84+ function waitForPropagation {
85+ announce " Waiting 50 seconds for functions changes to propagate"
86+ sleep 50
87+ }
88+
89+ function run_all_tests {
90+ announce " Running the integration tests..."
91+
92+ # Constructs the URLs for both test functions. This may change in the future,
93+ # causing this script to start failing, but currently we don't have a very
94+ # reliable way of determining the URL dynamically.
95+ TEST_DOMAIN=" cloudfunctions.net"
96+ if [[ $FIREBASE_FUNCTIONS_URL == " https://preprod-cloudfunctions.sandbox.googleapis.com" ]]; then
97+ TEST_DOMAIN=" txcloud.net"
98+ fi
99+ TEST_URL_NODE_6=" https://us-central1-$PROJECT_ID_NODE_6 .$TEST_DOMAIN /integrationTests"
100+ TEST_URL_NODE_8=" https://us-central1-$PROJECT_ID_NODE_8 .$TEST_DOMAIN /integrationTests"
101+ echo $TEST_URL_NODE_6
102+ echo $TEST_URL_NODE_8
103+ curl --fail $TEST_URL_NODE_6 & NODE6PID=$!
104+ curl --fail $TEST_URL_NODE_8 & NODE8PID=$!
105+ wait $NODE6PID && echo ' node 6 passed' || (announce ' Node 6 tests failed' ; cleanup; announce ' Tests failed' ; exit 1)
106+ wait $NODE8PID && echo ' node 8 passed' || (announce ' Node 8 tests failed' ; cleanup; announce ' Tests failed' ; exit 1)
63107}
64108
65109function run_tests {
@@ -93,10 +137,18 @@ install_deps
93137delete_all_functions
94138announce " Deploying functions to Node 8 runtime ..."
95139deploy
96- run_tests
140+ if [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then
141+ waitForPropagation
142+ run_tests
143+ fi
97144pick_node6
98145announce " Re-deploying the same functions to Node 6 runtime ..."
99146deploy
100- run_tests
147+ waitForPropagation
148+ if [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then
149+ run_tests
150+ else
151+ run_all_tests
152+ fi
101153cleanup
102154announce " All tests pass!"
0 commit comments