|
1 | | -#!/bin/bash |
2 | | -( |
3 | | - echo "##### Building SDK..." && |
4 | | - ( |
5 | | - cd ../ && |
6 | | - rm -f firebase-functions-*.tgz && |
7 | | - npm run build:pack && |
8 | | - mv firebase-functions-*.tgz integration_test/functions/firebase-functions.tgz |
9 | | - ) && |
10 | | - echo "##### Installing dependencies..." && |
11 | | - ( |
12 | | - cd functions && |
13 | | - npm install |
14 | | - ) && |
15 | | - echo "##### Deploying empty index.js to project..." && |
16 | | - ./functions/node_modules/.bin/tsc -p functions/ && # Make sure the functions/lib directory actually exists. |
17 | | - echo "" > functions/lib/index.js && |
18 | | - firebase deploy --debug 2> /dev/null && |
19 | | - echo && |
20 | | - echo "##### Project emptied. Deploying functions..." && |
21 | | - ./functions/node_modules/.bin/tsc -p functions/ && |
22 | | - firebase deploy --only functions --debug 2> /dev/null && |
23 | | - echo && |
24 | | - echo "##### Running the integration tests..." && |
25 | | - funcURL=$(tail -n 1 firebase-debug.log | awk '{ print $5 }') && # URL is printed on last line of log. |
26 | | - wget --content-on-error -qO- $funcURL && |
27 | | - echo && |
28 | | - echo "##### Integration test run passed!" && |
29 | | - echo "##### Re-deploying the same functions, to make sure updates work..." && |
30 | | - firebase deploy --only functions --debug 2> /dev/null && |
31 | | - echo && |
32 | | - echo "##### Running the integration tests..." && |
33 | | - wget --content-on-error -qO- $funcURL && |
34 | | - echo && |
35 | | - echo "##### Integration test run passed!" && |
36 | | - echo "##### Removing all functions" && |
37 | | - echo "" > functions/lib/index.js && |
38 | | - firebase deploy --only functions --debug 2> /dev/null && |
39 | | - rm functions/firebase-functions.tgz && |
40 | | - rm -f functions/firebase-debug.log && |
41 | | - echo && |
42 | | - echo "##### All tests pass!" |
43 | | -) || ( |
44 | | - echo && |
45 | | - echo "XXXXX Something failed XXXXX" && |
46 | | - false # Finish with an error code. |
47 | | -) |
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Exit immediately if a command exits with a non-zero status. |
| 4 | +set -e |
| 5 | + |
| 6 | +function usage { |
| 7 | + echo "Usage: $0 <project_id>" |
| 8 | + exit 1 |
| 9 | +} |
| 10 | + |
| 11 | +# The first parameter is required and is the Firebase project id. |
| 12 | +if [[ $1 == "" ]]; then |
| 13 | + usage |
| 14 | +fi |
| 15 | +PROJECT_ID=$1 |
| 16 | + |
| 17 | +# Directory where this script lives. |
| 18 | +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 19 | + |
| 20 | +function announce { |
| 21 | + echo -e "\n\n##### $1" |
| 22 | +} |
| 23 | + |
| 24 | +function build_sdk { |
| 25 | + announce "Building SDK..." |
| 26 | + cd $DIR/.. |
| 27 | + rm -f firebase-functions-*.tgz |
| 28 | + npm run build:pack |
| 29 | + mv firebase-functions-*.tgz integration_test/functions/firebase-functions.tgz |
| 30 | +} |
| 31 | + |
| 32 | +function install_deps { |
| 33 | + announce "Installing dependencies..." |
| 34 | + cd $DIR/functions |
| 35 | + npm install |
| 36 | +} |
| 37 | + |
| 38 | +function delete_all_functions { |
| 39 | + announce "Deploying empty index.js to project..." |
| 40 | + cd $DIR |
| 41 | + ./functions/node_modules/.bin/tsc -p functions/ # Make sure the functions/lib directory actually exists. |
| 42 | + echo "" > functions/lib/index.js |
| 43 | + firebase deploy --project=$PROJECT_ID --only functions |
| 44 | + announce "Project emptied." |
| 45 | +} |
| 46 | + |
| 47 | +function deploy { |
| 48 | + announce "Deploying functions..." |
| 49 | + cd $DIR |
| 50 | + ./functions/node_modules/.bin/tsc -p functions/ |
| 51 | + firebase deploy --project=$PROJECT_ID --only functions |
| 52 | +} |
| 53 | + |
| 54 | +function run_tests { |
| 55 | + announce "Running the integration tests..." |
| 56 | + |
| 57 | + # Construct the URL for the test function. This may change in the future, |
| 58 | + # causing this script to start failing, but currently we don't have a very |
| 59 | + # reliable way of determining the URL dynamically. |
| 60 | + TEST_URL=https://us-central1-$PROJECT_ID.cloudfunctions.net/integrationTests |
| 61 | + echo $TEST_URL |
| 62 | + |
| 63 | + curl --fail $TEST_URL |
| 64 | +} |
| 65 | + |
| 66 | +function cleanup { |
| 67 | + announce "Performing cleanup..." |
| 68 | + delete_all_functions |
| 69 | + rm $DIR/functions/firebase-functions.tgz |
| 70 | + rm -f $DIR/functions/firebase-debug.log |
| 71 | +} |
| 72 | + |
| 73 | +build_sdk |
| 74 | +install_deps |
| 75 | +delete_all_functions |
| 76 | +deploy |
| 77 | +run_tests |
| 78 | +announce "Re-deploying the same functions to make sure updates work..." |
| 79 | +deploy |
| 80 | +run_tests |
| 81 | +cleanup |
| 82 | +announce "All tests pass!" |
0 commit comments