From 344f67a4c28c95c5dec3081a735bfa0ad1f79bbf Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Wed, 11 Dec 2019 16:20:18 +0100 Subject: [PATCH 1/3] Create run-app script to handle common app configuration tasks --- packages/mobile/.env | 2 +- packages/mobile/package.json | 8 +- packages/mobile/scripts/pre-dev.sh | 16 --- packages/mobile/scripts/run_app.sh | 123 ++++++++++++++++++ packages/mobile/scripts/run_e2e.sh | 2 +- .../config/config.integration.env | 2 +- 6 files changed, 129 insertions(+), 24 deletions(-) delete mode 100755 packages/mobile/scripts/pre-dev.sh create mode 100755 packages/mobile/scripts/run_app.sh diff --git a/packages/mobile/.env b/packages/mobile/.env index 20f99890196..ec2ce842b2d 100644 --- a/packages/mobile/.env +++ b/packages/mobile/.env @@ -10,4 +10,4 @@ SHOW_TESTNET_BANNER=true SHOW_GET_INVITE_LINK=false DEV_SETTINGS_ACTIVE_INITIALLY=true # Enable for true hot reloading while dev-ing UI -DEV_RESTORE_NAV_STATE_ON_RELOAD=false \ No newline at end of file +DEV_RESTORE_NAV_STATE_ON_RELOAD=false diff --git a/packages/mobile/package.json b/packages/mobile/package.json index fdf53fdf4ad..482374a5f27 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -5,17 +5,15 @@ "license": "Apache-2.0", "private": true, "scripts": { - "start": "react-native start", - "start:bg": "react-native start &", + "start": "./scripts/run_app.sh", + "start:android": "./scripts/run_app.sh -p android", + "start:ios": "./scripts/run_app.sh -p ios", "lint": "tslint -c tslint.json --project tsconfig.json", "build": "yarn run build:ts && yarn run build:metro", "build:sdk": "yarn --cwd ../walletkit build:for-env", "build:ts": "tsc --noEmit", "build:metro": "echo 'NOT WORKING RIGHT NOW'", "build:gen-graphql-types": "gql-gen --schema http://localhost:8080/graphql --template graphql-codegen-typescript-template --out ./typings/ 'src/**/*.tsx'", - "predev": "./scripts/pre-dev.sh", - "dev": "react-native run-android --appIdSuffix \"debug\" --no-packager && yarn start || echo 'Could not start metro server'", - "dev:ios": "react-native run-ios --simulator \"iPhone 11\"", "dev:show-menu": "adb devices | grep '\t' | awk '{print $1}' | sed 's/\\s//g' | xargs -I {} adb -s {} shell input keyevent 82", "dev:clear-data": "adb shell pm clear org.celo.mobile.debug", "dev:clean-android": "cd android && ./gradlew clean", diff --git a/packages/mobile/scripts/pre-dev.sh b/packages/mobile/scripts/pre-dev.sh deleted file mode 100755 index 0d33045da86..00000000000 --- a/packages/mobile/scripts/pre-dev.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# ==================================== -# Tasks to run before running yarn dev -# ==================================== - -# Detect network from .env and build the sdk for it -ENV_FILENAME="${ENVFILE:-.env}" -export $(grep -v '^#' $ENV_FILENAME | xargs) -echo "Building sdk for testnet $DEFAULT_TESTNET" -yarn build:sdk $DEFAULT_TESTNET -echo "Done building sdk" -echo "Jetifying react native libraries" -cd ../../ && yarn run jetify -echo "Jetified" \ No newline at end of file diff --git a/packages/mobile/scripts/run_app.sh b/packages/mobile/scripts/run_app.sh new file mode 100755 index 00000000000..d2bc211f206 --- /dev/null +++ b/packages/mobile/scripts/run_app.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ==================================== +# Configure and run the mobile app +# ==================================== + +# Flags: +# -n: Name of the network to run on +# -p: Platform (android or ios) +# -f: Fast (skip steps not required unless network or depedencies changes) +# -h: Hot Reload (Restore nav state on reload) + +NETWORK="" +PLATFORM="" +FAST=false +HOT_RELOAD=false +while getopts 'n:p:fh' flag; do + case "${flag}" in + n) NETWORK="$OPTARG" ;; + p) PLATFORM="$OPTARG" ;; + f) FAST=true ;; + h) HOT_RELOAD=true ;; + *) error "Unexpected option ${flag}" ;; + esac +done + +[ -z "$PLATFORM" ] && echo "Need to set the PLATFORM via the -p flag" && exit 1; + +# Get machine type (needed later) +unameOut="$(uname -s)" +case "${unameOut}" in + Linux*) MACHINE=Linux;; + Darwin*) MACHINE=Mac;; + CYGWIN*) MACHINE=Cygwin;; + MINGW*) MACHINE=MinGw;; + *) MACHINE="UNKNOWN:${unameOut}" +esac +echo "Machine type: $MACHINE" +echo "Current directory: `pwd`" + +# Read values from the .env file and put them in env vars +ENV_FILENAME="${ENVFILE:-.env}" +export $(grep -v '^#' $ENV_FILENAME | xargs) + +if [ -z "$NETWORK" ]; then + echo "No network set." + read -p "Use $DEFAULT_TESTNET network set in .env file (y/n)? " + if [[ $REPLY =~ ^[Yy]$ ]]; then + NETWORK=$DEFAULT_TESTNET + else + echo "No network chosen. Exiting." + exit 1 + fi +fi + +# Set DEFAULT_TESTNET in .env file +sed -i.bak "s/DEFAULT_TESTNET=.*/DEFAULT_TESTNET=$NETWORK/g" $ENV_FILENAME + +# Set Hot Reload (saved nav state) in .env file +sed -i.bak "s/DEV_RESTORE_NAV_STATE_ON_RELOAD=.*/DEV_RESTORE_NAV_STATE_ON_RELOAD=$HOT_RELOAD/g" $ENV_FILENAME + +# Set Firebase settings in google service config files +ANDROID_GSERVICES_PATH="./android/app/src/debug/google-services.json" +IOS_GSERVICES_PATH="./ios/GoogleService-Info.plist" +sed -i.bak "s/celo-org-mobile-.*firebaseio.com/celo-org-mobile-$NETWORK.firebaseio.com/g" $ANDROID_GSERVICES_PATH +sed -i.bak "s/celo-org-mobile-.*firebaseio.com/celo-org-mobile-$NETWORK.firebaseio.com/g" $IOS_GSERVICES_PATH + +# Cleanup artifacts from in-place sed replacement on BSD based systems (macOS) +rm -f $ENV_FILENAME.bak +rm -f $ANDROID_GSERVICES_PATH.bak +rm -f $IOS_GSERVICES_PATH.bak + + +# Build Wallet Kit for env +if [ "$FAST" = false ]; then + echo "Building sdk for testnet $NETWORK" + yarn build:sdk $NETWORK + echo "Done building sdk" +fi + +# Build the app and run it +if [ $PLATFORM = "android" ]; then + echo "Using platform android" + + NUM_DEVICES=`adb devices -l | wc -l` + if [ $NUM_DEVICES -lt 3 ]; then + echo "No android devices found" + exit 1 + fi + + # Run jettify to fix non-android-x compatible libs + if [ "$FAST" = false ]; then + echo "Jetifying react native libraries" + cd ../../ && yarn run jetify && cd packages/mobile + echo "Jetified" + fi + + if [ $MACHINE = "Mac" ]; then + echo "Starting packager in new terminal" + RN_START_CMD="cd `pwd`;yarn react-native start" + OSASCRIPT_CMD="tell application \"Terminal\" to do script \"$RN_START_CMD\"" + echo "FULLCMD: $OSASCRIPT_CMD" + osascript -e "$OSASCRIPT_CMD" + # Run android without packager because RN cli doesn't work with yarn workspaces + yarn react-native run-android --appIdSuffix \"debug\" --no-packager + else + # Run android without packager because RN cli doesn't work with yarn workspaces + yarn react-native run-android --appIdSuffix \"debug\" --no-packager + yarn react-native start + fi + +elif [ $PLATFORM = "ios" ]; then + echo "Using platform ios" + # TODO have iOS build and start from command line + echo -e "\nFor now ios must be build and run from xcode\nStarting RN bundler\n" + yarn react-native start + +else + echo "Invalid value for platform, must be 'android' or 'ios'" + exit 1 +fi + diff --git a/packages/mobile/scripts/run_e2e.sh b/packages/mobile/scripts/run_e2e.sh index 38990a72a9f..54740a719b8 100755 --- a/packages/mobile/scripts/run_e2e.sh +++ b/packages/mobile/scripts/run_e2e.sh @@ -39,7 +39,7 @@ bash ./scripts/unlock.sh echo "Killing previous metro server (if any)" react-native-kill-packager || echo 'Failed to kill for some reason' echo "Start metro server" -yarn start:bg +yarn react-native start & echo "Waiting for device to connect to Wifi, this is a good proxy the device is ready" diff --git a/packages/notification-service/config/config.integration.env b/packages/notification-service/config/config.integration.env index 90ddb1d1f59..ca04282e554 100644 --- a/packages/notification-service/config/config.integration.env +++ b/packages/notification-service/config/config.integration.env @@ -1,6 +1,6 @@ ENVIRONMENT=integration PORT=80 -FIREBASE_DB=https://celo-org-mobile-int.firebaseio.com +FIREBASE_DB=https://celo-org-mobile-integration.firebaseio.com BLOCKSCOUT_API=https://integration-blockscout.celo-testnet.org/api? NODE_TLS_REJECT_UNAUTHORIZED=0 DEFAULT_LOCALE=en From 56e650a820c5eecfb372f80b5bafed53409e0301 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Thu, 12 Dec 2019 13:02:01 +0100 Subject: [PATCH 2/3] Address feedback --- packages/mobile/package.json | 5 ++--- packages/mobile/scripts/run_app.sh | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/mobile/package.json b/packages/mobile/package.json index 482374a5f27..2fbc7ea19a0 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -5,15 +5,14 @@ "license": "Apache-2.0", "private": true, "scripts": { - "start": "./scripts/run_app.sh", - "start:android": "./scripts/run_app.sh -p android", - "start:ios": "./scripts/run_app.sh -p ios", "lint": "tslint -c tslint.json --project tsconfig.json", "build": "yarn run build:ts && yarn run build:metro", "build:sdk": "yarn --cwd ../walletkit build:for-env", "build:ts": "tsc --noEmit", "build:metro": "echo 'NOT WORKING RIGHT NOW'", "build:gen-graphql-types": "gql-gen --schema http://localhost:8080/graphql --template graphql-codegen-typescript-template --out ./typings/ 'src/**/*.tsx'", + "dev:android": "./scripts/run_app.sh -p android", + "dev:ios": "./scripts/run_app.sh -p ios", "dev:show-menu": "adb devices | grep '\t' | awk '{print $1}' | sed 's/\\s//g' | xargs -I {} adb -s {} shell input keyevent 82", "dev:clear-data": "adb shell pm clear org.celo.mobile.debug", "dev:clean-android": "cd android && ./gradlew clean", diff --git a/packages/mobile/scripts/run_app.sh b/packages/mobile/scripts/run_app.sh index d2bc211f206..d2a9165ffdc 100755 --- a/packages/mobile/scripts/run_app.sh +++ b/packages/mobile/scripts/run_app.sh @@ -9,18 +9,18 @@ set -euo pipefail # -n: Name of the network to run on # -p: Platform (android or ios) # -f: Fast (skip steps not required unless network or depedencies changes) -# -h: Hot Reload (Restore nav state on reload) +# -r: Hot Reload (Restore nav state on reload) NETWORK="" PLATFORM="" FAST=false HOT_RELOAD=false -while getopts 'n:p:fh' flag; do +while getopts 'n:p:fr' flag; do case "${flag}" in n) NETWORK="$OPTARG" ;; p) PLATFORM="$OPTARG" ;; f) FAST=true ;; - h) HOT_RELOAD=true ;; + r) HOT_RELOAD=true ;; *) error "Unexpected option ${flag}" ;; esac done @@ -103,10 +103,10 @@ if [ $PLATFORM = "android" ]; then echo "FULLCMD: $OSASCRIPT_CMD" osascript -e "$OSASCRIPT_CMD" # Run android without packager because RN cli doesn't work with yarn workspaces - yarn react-native run-android --appIdSuffix \"debug\" --no-packager + yarn react-native run-android --appIdSuffix "debug" --no-packager else # Run android without packager because RN cli doesn't work with yarn workspaces - yarn react-native run-android --appIdSuffix \"debug\" --no-packager + yarn react-native run-android --appIdSuffix "debug" --no-packager yarn react-native start fi From d4aa8f3e0bb0f6277888554e6868a2f19332353a Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Thu, 12 Dec 2019 15:45:58 +0100 Subject: [PATCH 3/3] Fix old int firebase db references --- .env.baklava | 2 -- .env.baklavastaging | 2 -- packages/blockchain-api/.env | 2 +- packages/blockchain-api/app.integration.yaml | 2 +- packages/notification-service/config/config.local.env | 2 +- packages/notification-service/config/config.test.env | 2 +- 6 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.env.baklava b/.env.baklava index 0a6f4413518..4e51f19c2cc 100644 --- a/.env.baklava +++ b/.env.baklava @@ -103,8 +103,6 @@ STACKDRIVER_NOTIFICATION_APPLICATIONS_PREFIX="notification-service-,blockchain-a MOBILE_WALLET_PLAYSTORE_LINK="https://play.google.com/apps/internaltest/4700990475000634666" -# NOTIFICATION_SERVICE_FIREBASE_DB="https://console.firebase.google.com/u/0/project/celo-org-mobile/database/celo-org-mobile-int/data" - PROMTOSD_SCRAPE_INTERVAL="5m" PROMTOSD_EXPORT_INTERVAL="5m" diff --git a/.env.baklavastaging b/.env.baklavastaging index 05ef6c7faf0..2eec1477a44 100644 --- a/.env.baklavastaging +++ b/.env.baklavastaging @@ -102,8 +102,6 @@ STACKDRIVER_NOTIFICATION_APPLICATIONS_PREFIX="notification-service-,blockchain-a MOBILE_WALLET_PLAYSTORE_LINK="https://play.google.com/apps/internaltest/4700990475000634666" -# NOTIFICATION_SERVICE_FIREBASE_DB="https://console.firebase.google.com/u/0/project/celo-org-mobile/database/celo-org-mobile-int/data" - PROMTOSD_SCRAPE_INTERVAL="5m" PROMTOSD_EXPORT_INTERVAL="5m" diff --git a/packages/blockchain-api/.env b/packages/blockchain-api/.env index a8b4881e5d2..e3601c7664d 100644 --- a/packages/blockchain-api/.env +++ b/packages/blockchain-api/.env @@ -1,7 +1,7 @@ DEPLOY_ENV=local EXCHANGE_RATES_API=https://apilayer.net/api BLOCKSCOUT_API=https://integration-blockscout.celo-testnet.org/api -FIREBASE_DB=https://celo-org-mobile-int.firebaseio.com +FIREBASE_DB=https://celo-org-mobile-integration.firebaseio.com FAUCET_ADDRESS=0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95 VERIFICATION_REWARDS_ADDRESS=0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5 WEB3_PROVIDER_URL=https://integration-forno.celo-testnet.org diff --git a/packages/blockchain-api/app.integration.yaml b/packages/blockchain-api/app.integration.yaml index df237830d74..5489ece4f70 100644 --- a/packages/blockchain-api/app.integration.yaml +++ b/packages/blockchain-api/app.integration.yaml @@ -5,7 +5,7 @@ env_variables: DEPLOY_ENV: "integration" EXCHANGE_RATES_API: "https://apilayer.net/api" BLOCKSCOUT_API: "https://integration-blockscout.celo-testnet.org/api" - FIREBASE_DB: "https://celo-org-mobile-int.firebaseio.com" + FIREBASE_DB: "https://celo-org-mobile-integration.firebaseio.com" # TODO Pull addresses from the build artifacts of the network in protocol/build FAUCET_ADDRESS: "0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95" VERIFICATION_REWARDS_ADDRESS: "0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5" diff --git a/packages/notification-service/config/config.local.env b/packages/notification-service/config/config.local.env index 89bd2d05065..7760f7ff0b6 100644 --- a/packages/notification-service/config/config.local.env +++ b/packages/notification-service/config/config.local.env @@ -1,6 +1,6 @@ ENVIRONMENT=local PORT=8080 -FIREBASE_DB=https://celo-org-mobile-int.firebaseio.com +FIREBASE_DB=https://celo-org-mobile-integration.firebaseio.com BLOCKSCOUT_API=https://integration-blockscout.celo-testnet.org/api? NODE_TLS_REJECT_UNAUTHORIZED=0 DEFAULT_LOCALE=en diff --git a/packages/notification-service/config/config.test.env b/packages/notification-service/config/config.test.env index 89bd2d05065..7760f7ff0b6 100644 --- a/packages/notification-service/config/config.test.env +++ b/packages/notification-service/config/config.test.env @@ -1,6 +1,6 @@ ENVIRONMENT=local PORT=8080 -FIREBASE_DB=https://celo-org-mobile-int.firebaseio.com +FIREBASE_DB=https://celo-org-mobile-integration.firebaseio.com BLOCKSCOUT_API=https://integration-blockscout.celo-testnet.org/api? NODE_TLS_REJECT_UNAUTHORIZED=0 DEFAULT_LOCALE=en