forked from karrot-dev/karrot-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-android.sh
executable file
·92 lines (63 loc) · 2.07 KB
/
deploy-android.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
set -e
HOST=yuca.yunity.org
REF=$1
APK=$2
DIR=$3
if [ -z "$REF" ] || [ -z "$APK" ] || [ -z "$DIR" ]; then
echo "Usage: <ref> <apk> <dir>"
exit 1
fi
REPO_URL="https://github.com/yunity/karrot-frontend"
COMMIT_SHA=$(git rev-parse HEAD)
COMMIT_SHA_SHORT=$(git rev-parse --short HEAD)
if [ "$DIR" == "release" ]; then
# release
DEPLOY_ENV="production"
DEPLOY_EMOJI=":rocket:"
APK_URL="https://karrot.world/app.apk"
PLAYSTORE_URL="https://play.google.com/store/apps/details?id=world.karrot"
PACKAGE_NAME="world.karrot"
elif [ "$DIR" == "master" ]; then
# dev
DEPLOY_ENV="development"
DEPLOY_EMOJI=":beer:"
APK_URL="https://dev.karrot.world/app.apk"
PLAYSTORE_URL="https://play.google.com/store/apps/details?id=world.karrot.dev"
PACKAGE_NAME="world.karrot.dev"
else
# nothing
echo "Not deploying [$APK] to [$DIR] as it has not been configured in deploy-android.sh"
exit 1
fi
REF_URL="$REPO_URL/tree/$REF"
COMMIT_URL="$REPO_URL/tree/$COMMIT_SHA"
mkdir -p ~/.ssh
ssh-keyscan -H $HOST >> ~/.ssh/known_hosts
echo "deploying app [$APK] to [$HOST] in [$DIR] dir"
# push apk to server
rsync -avz "$APK" "deploy@$HOST:karrot-app/$DIR/app.apk"
# publish in playstore
(
APK_FILE="$(pwd)/$APK"
cd cordova
KEY="$CORDOVA_PLAYSTORE_SERVICEACCOUNT_KEY" PACKAGE_NAME="$PACKAGE_NAME" APK_FILE="$APK_FILE" ./publish_to_playstore
)
if [ ! -z "$SLACK_WEBHOOK_URL" ]; then
COMMIT_MESSAGE=$(git log -1 --pretty="%s - %an")
ATTACHMENT_TEXT=""
ATTACHMENT_TEXT+=":android: Download <$PLAYSTORE_URL|from Play Store> or <$APK_URL|as APK>"
ATTACHMENT_FOOTER="Using git ref <$REF_URL|$REF>, commit <$COMMIT_URL|$COMMIT_SHA_SHORT> - $COMMIT_MESSAGE"
payload=$(printf '{
"channel": "#karrot-git",
"username": "deploy",
"text": ":sparkles: Successful deployment of :karrot: *karrot* app to _%s_ %s",
"attachments": [
{
"text": "%s",
"footer": "%s"
}
]
}' "$DEPLOY_ENV" "$DEPLOY_EMOJI" "$ATTACHMENT_TEXT" "$ATTACHMENT_FOOTER")
curl -X POST --data-urlencode "payload=$payload" "$SLACK_WEBHOOK_URL"
fi