1#!/bin/bash
2set -e
3
4echo "Using time: ${TIMESTAMP:=`date "+%s"`}"
5
6
7: ${PLATFORM:?"Need to set PLATFORM"}
8: ${PLATFORM_BUILD_PATH:?"Need to set PLATFORM_BUILD_PATH, this is the path to the apk/app"}
9: ${APPETIZE_TOKEN:?"Need to set APPETIZE_TOKEN"}
10: ${BUILD_URL:?"Need to set BUILD_URL"}
11: ${S3_URL:?"Need to set S3_URL"}
12
13
14if [ ! -f ~/.aws/config ]; then
15  : ${AWS_ACCESS_KEY_ID:?"Need to set AWS_ACCESS_KEY_ID"}
16  : ${AWS_SECRET_ACCESS_KEY:?"Need to set AWS_SECRET_ACCESS_KEY"}
17fi
18
19
20if [ "$PLATFORM" = "android" ]
21then
22  BUILD_NAME="app-$TIMESTAMP.apk"
23elif [ "$PLATFORM" = "ios" ]
24then
25  BUILD_NAME="app-$TIMESTAMP.app"
26else
27  echo "Platform should be either Android or iOS"
28  exit 1
29fi
30
31echo "Uploading to: $S3_URL$BUILD_NAME"
32
33JSON_PAYLOAD="{\"token\": \"$APPETIZE_TOKEN\", \"url\": \"$BUILD_URL$BUILD_NAME\", \"platform\": \"$PLATFORM\"}"
34
35if [ -n "$DRY_RUN" ];
36then
37
38  echo "curl https://api.appetize.io/v1/app/update"
39  echo "  -H 'Content-Type: application/json'"
40  echo "  -d '$JSON_PAYLOAD'"
41  exit 0
42fi
43
44aws s3 cp $PLATFORM_BUILD_PATH $S3_URL$BUILD_NAME
45
46echo "APK_URL: $BUILD_URL$BUILD_NAME"
47curl https://api.appetize.io/v1/app/update -H 'Content-Type: application/json' -d "$JSON_PAYLOAD"
48
49exit 0
50
51# Example Run Config
52# DRY_RUN=1 \
53# PLATFORM=android \
54# PLATFORM_BUILD_PATH="android/app/build/outputs/apk/app-debug.apk" \
55# BUILD_URL="https://s3-us-west-2.amazonaws.com/kb-appbuilds/" \
56# S3_URL="s3://kb-appbuilds/"
57# ./uploadApp.sh
58# remove DRY_RUN to actually run
59