-
Notifications
You must be signed in to change notification settings - Fork 1
/
hail.sh
executable file
·113 lines (98 loc) · 2.07 KB
/
hail.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
CONFIG_FILE=~/.config/hail/config.yaml
UPLOAD_OUTPUT={"error":500}
#
# util functions
#
build () {
print_v "Executing: $assemble on version: $app_version_name"
# no backup file
sed -i "" "s/.*versionName.*/versionName '$app_version_name'/" $gradle_file
./gradlew $assemble
}
install () {
print_v "Installing apk: $apk_path"
adb install $apk_path
}
release () {
# send form post multipart
# optional --progress-bar
url="https://rink.hockeyapp.net/api/2/apps/$app_id/app_versions/upload"
params=(
-F "status=$available_for_download"
-F "notify=$should_notify"
-F "notes=`cat $release_notes_path`"
-F "notes_type=$notes_type"
-F "ipa=@$apk_path"
)
headers=(
-H "X-HockeyAppToken: $user_app_token"
)
print_v "Releasing: $app_version_name"
UPLOAD_OUTPUT=$(curl "${params[@]}" "${headers[@]}" "$url" | tee /dev/null)
}
output () {
app_version=$(jq '.id' <<< "$UPLOAD_OUTPUT")
# -r raw to avoid quotes
public_url=$(jq -r '.public_url' <<< "$UPLOAD_OUTPUT")
# not part of verbose but actual output
echo "$public_url/app_versions/$app_version"
}
# util functions
print_usage () {
printf "Usage: -v -r -b -i -f flavor or -vrbi -f flavor -c file.yml"
}
print_v () {
if [ "$VERBOSE" = "true" ]
then
printf "%s\n" "v: $1"
fi
}
load_config () {
cat $CONFIG_FILE | shyaml key-values-0 $1 |
while read_liner key value; do
printf "%s=%s\n" "$key" "'$value'"
done
}
read_liner () {
while [ "$1" ]; do
IFS=$'\0' read -r -d '' "$1" || return 1
shift
done
}
#
# main
#
while getopts 'birc:f:v' flag; do
case "${flag}" in
b) BUILD='true' ;;
c) CONFIG_FILE="${OPTARG}" ;;
f) FLAVOR="${OPTARG}" ;;
i) INSTALL='true' ;;
r) RELEASE='true' ;;
v) VERBOSE='true' ;;
*) print_usage
exit 1 ;;
esac
done
eval $(load_config defaults.build)
eval $(load_config defaults.release)
if [ ! -z "$FLAVOR" ]
then
eval $(load_config $FLAVOR.build)
eval $(load_config $FLAVOR.release)
fi
cd $root_dir
if [ "$BUILD" = "true" ]
then
build
fi
if [ "$INSTALL" = "true" ]
then
install
fi
if [ "$RELEASE" = "true" ]
then
release
output
fi