Skip to content

Commit

Permalink
[MOBILE-277] Add a CI task that builds the sample app.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianBatchelder authored Aug 10, 2018
1 parent 45610d9 commit 160d921
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ A sample can be found in the Example directory.

1. Add your UA credentials to the `config_sample.xml` file in the root directory and save.
2. Add your development team id to the `build_sample.json` file in the root directory and save.
3. Run the script with the command `./create_sample.sh PROJECT_PATH PROJECT_NAME`
3. Run the script with the command `./scripts/create_sample.sh PROJECT_PATH PROJECT_NAME`
4. cd to the newly-created project directory, e.g. sample/test
5. Build the platform you want to test.
* iOS
Expand Down
22 changes: 12 additions & 10 deletions create_sample.sh → scripts/create_sample.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash -ex
#!/bin/bash

cd "$(dirname "${BASH_SOURCE[0]}")"
ROOT_DIR="$(pwd)"
set -euxo pipefail

cd `dirname "${0}"`/../
ROOT_PATH="$(pwd)"
cd -

CORDOVA_PATH=$1
Expand All @@ -14,8 +16,8 @@ fi

# Set up script to create a sample for iOS and android testing.
# Follow the steps below.
# 1. Add the UA credentials to the `config_sample.xml` file in the test directory and save.
# 2. Run the script with the command `./create_sample.sh `
# 1. Add the UA credentials to the `config_sample.xml` file and save.
# 2. Run the script with the command `./scripts/create_sample.sh `
# 3. Build the platform you want to test (see comments below).

# keep cordova up to date
Expand All @@ -31,13 +33,13 @@ cordova create test com.urbanairship.sample Test
cd test

# add the plugin
cordova plugin add $ROOT_DIR
cordova plugin add $ROOT_PATH

# copy config and example files
cp $ROOT_DIR/config_sample.xml config.xml
cp $ROOT_DIR/Example/index.html www/index.html
cp $ROOT_DIR/Example/css/* www/css
cp $ROOT_DIR/Example/js/* www/js
cp $ROOT_PATH/config_sample.xml config.xml
cp $ROOT_PATH/Example/index.html www/index.html
cp $ROOT_PATH/Example/css/* www/css
cp $ROOT_PATH/Example/js/* www/js

# add the device plugin
cordova plugin add cordova-plugin-device
Expand Down
103 changes: 103 additions & 0 deletions scripts/run_ci_tasks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash

#
# run_ci_tasks.sh [OPTIONS] [PATH TO SAMPLE APP]
# where OPTIONS are:
# -a to run Android CI tasks.
# -i to run iOS CI tasks.
# Defaults to -a -i.
#

set -euxo pipefail

SCRIPT_DIRECTORY=`dirname "$0"`
SCRIPT_NAME=`basename "$0"`

# get platforms to build
ANDROID=false
IOS=false

# Parse arguments
OPTS=`getopt haid $*`

if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
eval set -- "$OPTS"

if [ "$1" == "--" ]; then
# set the default options
eval set -- "-a" "-i" $@
fi

while true; do
case "${1:-}" in
-h ) echo -ne "\n${SCRIPT_NAME} [OPTIONS] [PATH TO SAMPLE APP]\nwhere OPTIONS are:\n -a to run Android CI tasks.\n -i to run iOS CI tasks.\n Defaults to -a -i. \n"; exit 0;;
-a ) ANDROID=true;;
-i ) IOS=true;;
-- ) ;;
* ) break ;;
esac
shift
done

SAMPLE_APP_PATH=${1:-}

if [ "$ANDROID" = "true" ] || [ "$IOS" = "true" ]; then
# create the sample for building
if [ -z "$SAMPLE_APP_PATH" ]; then
SAMPLE_APP_PATH=$(mktemp -d /tmp/cordova-sample-app-XXXXX)
fi

# if sample app doesn't already exist, create it
if [[ ! -d $SAMPLE_APP_PATH/test ]]; then
${SCRIPT_DIRECTORY}/create_sample.sh $SAMPLE_APP_PATH
fi
cd $SAMPLE_APP_PATH/test
fi

if [ "$ANDROID" = "true" ]; then
# Make sure google-services.json exists
GOOGLE_SERVICES_FILE_PATH="$(pwd)/platforms/android/app/google-services.json"
if [[ ! -f ${GOOGLE_SERVICES_FILE_PATH} ]]; then
if [[ "${GOOGLE_SERVICES_JSON:-}" == "" ]]; then
echo "ERROR: You must provide ${GOOGLE_SERVICES_FILE_PATH}."
exit 1
else
echo $GOOGLE_SERVICES_JSON > ${GOOGLE_SERVICES_FILE_PATH}
fi
fi

# Build android
cordova build android -- --gradleArg=-PcdvMinSdkVersion=16 2>&1 | tee -a /tmp/CORDOVA-$$.out

# check for failures
if grep "BUILD FAILED" /tmp/CORDOVA-$$.out; then
# Set build status to failed
echo "ANDROID BUILD FAILED"
exit 1
else
echo "ANDROID BUILD SUCCEEDED"
fi
fi

if [ "$IOS" = "true" ]; then
# Build ios
cordova build ios --emulator 2>&1 | tee -a /tmp/CORDOVA-$$.out

# check for failures
if grep "BUILD FAILED" /tmp/CORDOVA-$$.out; then
# Set build status to failed
echo "iOS BUILD FAILED"
exit 1
fi

if grep "Failed to install 'com.urbanairship.cordova'" /tmp/CORDOVA-$$.out; then
# Set build status to failed
echo "iOS BUILD FAILED"
exit 1
fi

echo "iOS BUILD SUCCEEDED"

fi

echo "CI TASKS SUCCEEDED"

0 comments on commit 160d921

Please sign in to comment.