-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathci-deploy-firebase-apk.sh
executable file
·93 lines (74 loc) · 2.53 KB
/
ci-deploy-firebase-apk.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
93
#!/bin/bash
#------------------------------------------------------------------------
# A script to deploy a single Firebase application.
#
#------------------------------------------------------------------------
# Utility methods
#
fatal()
{
echo "ci-deploy-firebase-apk.sh: fatal: $1" 1>&2
exit 1
}
info()
{
echo "ci-deploy-firebase-apk.sh: info: $1" 1>&2
}
#------------------------------------------------------------------------
if [ $# -ne 1 ]
then
fatal "usage: project"
fi
PROJECT="$1"
shift
CI_BIN_DIRECTORY=$(realpath .ci) ||
fatal "could not determine bin directory"
export PATH="${PATH}:${CI_BIN_DIRECTORY}:."
NODE_MODULES_BIN=$(realpath node_modules/.bin) ||
fatal "node modules are not installed"
CI_FIREBASE="${NODE_MODULES_BIN}/firebase"
CI_FIREBASE_TOKEN=$(head -n 1 ".ci/credentials/Firebase/token.txt") ||
fatal "could not read firebase token from credentials repository"
START_DIRECTORY=$(pwd) ||
fatal "could not retrieve starting directory"
cd "${PROJECT}" ||
fatal "could not switch to project directory"
CI_FIREBASE_APK=$(head -n 1 "firebase-apk.conf") ||
fatal "could not read firebase-apk.conf"
CI_FIREBASE_APP_ID=$(head -n 1 "firebase-app-id.conf") ||
fatal "could not read firebase-app-id.conf"
CI_FIREBASE_GROUPS=$(head -n 1 "firebase-groups.conf") ||
fatal "could not read firebase-groups.conf"
CI_FIREBASE_APK=$(realpath "${CI_FIREBASE_APK}") ||
fatal "could not resolve APK"
info "firebase: APK: ${CI_FIREBASE_APK}"
info "firebase: app: ${CI_FIREBASE_APP_ID}"
info "firebase: groups: ${CI_FIREBASE_GROUPS}"
CI_FIREBASE_APK_SIZE=$(wc -c "${CI_FIREBASE_APK}" | cut -d' ' -f1) ||
fatal "could not determine APK size"
if [ "${CI_FIREBASE_APK_SIZE}" == "0" ]
then
fatal "attempted to submit a zero-size APK file"
fi
VERSION_AND_TYPE=$(ci-version-and-type.sh gradle.properties) ||
fatal "could not determine version and type"
VERSION_TYPE=$(echo "${VERSION_AND_TYPE}" | awk '{print $1}') ||
fatal "could not determine version type"
case "${VERSION_TYPE}" in
release)
# Use the existing README-CHANGES.txt
;;
snapshot)
ci-git-commit.sh "${START_DIRECTORY}/.git" > "${START_DIRECTORY}/README-CHANGES.txt"
echo "..." >> "${START_DIRECTORY}/README-CHANGES.txt"
;;
*)
fatal "unrecognized release type: ${VERSION_TYPE}"
;;
esac
exec "${CI_FIREBASE}" appdistribution:distribute \
--token "${CI_FIREBASE_TOKEN}" \
--release-notes-file "${START_DIRECTORY}/README-CHANGES.txt" \
--app "${CI_FIREBASE_APP_ID}" \
--groups "${CI_FIREBASE_GROUPS}" \
"${CI_FIREBASE_APK}"