-
Notifications
You must be signed in to change notification settings - Fork 2
/
relution_upload.sh
executable file
·139 lines (123 loc) · 3.76 KB
/
relution_upload.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash -e
if [[ -z "$JQ_EXECUTABLE" ]]; then
JQ_EXECUTABLE="jq"
fi
while [[ $# > 1 ]]
do
key="$1"
case $key in
--help)
RU_HELP=true
shift # past argument
;;
-f|--file)
RU_FILE="$2"
shift # past argument
;;
-e|--environment)
RU_ENVIRONMENT_UUID="$2"
shift # past argument
;;
-r|--release_status)
RU_RELEASE_STATUS="$2"
shift # past argument
;;
-h|--host)
RU_HOST="$2"
shift # past argument
;;
-u|--user)
RU_USER="$2"
shift # past argument
;;
-p|--password)
RU_PASSWORD="$2"
shift # past argument
;;
-a|--api_key)
RU_API_KEY="$2"
shift # past argument
;;
-n|--archive)
RU_ARCHIVE_VERSION="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
echo ${RU_HELP}
if [ $RU_HELP ] ; then
echo " _____ _ _ _ "
echo " | __ \ | | | | (_) "
echo " | |__) |___| |_ _| |_ _ ___ _ __ "
echo " | _ // _ \ | | | | __| |/ _ \| '_ \ "
echo " | | \ \ __/ | |_| | |_| | (_) | | | |"
echo " |_| \_\___|_|\__,_|\__|_|\___/|_| |_|"
echo ""
echo "-f --file Path of the artifact that you want to deploy to the Relution Enterprise App Store, relative to the workspace directory. This is typically an Apple iOS (.ipa) or Google Android (.apk) binary."
echo "-h --host The Relution base url to which the file should be deployed."
echo "-r --release_status The Release status in which the file should be put. Valid arguments are release, review, development. Will set development by default."
echo "-e --environment The development hub environment id."
echo "-a --api_key Relution API Token used for the authentication."
echo "-n --archive Wether to archive the previous App Version. Default value is true: will always archive the former version."
fi
if [[ -n "$RU_RELEASE_STATUS" ]]; then
curl_args="?releaseStatus=$RU_RELEASE_STATUS"
else
curl_args="?releaseStatus=DEVELOPMENT"
fi
if [[ -n "$RU_ENVIRONMENT_UUID" ]]; then
curl_args="${curl_args}&environmentUuid=$RU_ENVIRONMENT_UUID"
fi
if [[ -n "$RU_ARCHIVE_VERSION" ]]; then
curl_args="${curl_args}&archiveFormerVersion=$RU_ARCHIVE_VERSION"
fi
if [[ -z "$RU_FILE" ]]; then
echo "Use -f to pass the file path"
exit 1
fi
if [[ -n "$RU_API_KEY" ]]; then
curl_auth="-H X-User-Access-Token:${RU_API_KEY}"
else
curl_auth="-u ${RU_USER}:${RU_PASSWORD}"
fi
# add optional changelog
changelog=""
if [[ -f changelog.md ]]; then
changelog="-F changelog=@changelog.md"
fi
# check if path given was relative or absolute
if [[ "$RU_FILE" = /* ]]
then
# Absolute path
PATH_TO_FILE="$RU_FILE"
else
# Relative path
PATH_TO_FILE="$PWD/$RU_FILE"
fi
filename=$(basename -- "$RU_FILE")
echo "Uploading $filename to $RU_HOST/relution/api/v1/apps/fromFile$curl_args ..."
response=$(curl \
-sS \
-H "Accept:application/json" \
$curl_auth \
$changelog \
-F "app=@$PATH_TO_FILE" \
"$RU_HOST/relution/api/v1/apps$curl_args")
response_message=$(echo "$response" | "$JQ_EXECUTABLE" -r '.message')
response_code=$(echo "$response" | "$JQ_EXECUTABLE" -r '.status')
error_code=$(echo "$response" | "$JQ_EXECUTABLE" -r '.errorCode')
if [[ "$response_code" == "0" ]]; then
echo $response_message
appuuid=$(echo "$response" | "$JQ_EXECUTABLE" -r '.results[0].uuid')
echo "$RU_HOST/relution/portal/#/apps/$appuuid/information"
elif [[ "$error_code" == "VERSION_ALREADY_EXISTS" ]]; then
echo "Version already exists. Current version not uploaded again."
else
echo "There was an error uploading the App. This is the response we got:"
echo "$response" | "$JQ_EXECUTABLE"
exit 1
fi