-
Notifications
You must be signed in to change notification settings - Fork 3
/
dominus.sh
executable file
·330 lines (256 loc) · 5.22 KB
/
dominus.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/bin/bash
# UTF-8
export LANG=en_US.UTF-8
# Exit on failure
set -e
#
# Load all functions from library and utilities
#
load()
{
for filename in $(find . -iname '*.sh' -path "*/utility/*");
do
source $filename
done
for filename in $(find . -iname '*.sh' -path "*/library/*");
do
source $filename
done
for filename in $(find . -iname '*.sh' -path "*/integration/*");
do
source $filename
done
}
#
# Update
#
update()
{
echo '[DOMINUS]: Updating scripts in' $SCRIPT_PATH
#
# Find Dominus.sh script
#
DOMINUS_SCRIPT=`find . -name dominus.sh | head -n1`
if [[ ! -f $DOMINUS_SCRIPT ]]; then
echo '[DOMINUS]: Running myself, but no script:' $DOMINUS_SCRIPT 'Aborting...'
exit 1;
fi
#
# Get directory of Dominus script and attempt to up
#
DOMINUS_DIR=`dirname $DOMINUS_SCRIPT`
if [[ -f $DOMINUS_DIR'/.git' ]]; then
echo '[DOMINUS]: Found Dominus .git repository. Updating...'
PREVIOUS_DIR=`pwd`
cd $DOMINUS_DIR
git pull origin master
cd $PREVIOUS_DIR
echo '[DOMINUS]: Successfully updated Dominus code from GitHub.'
else
echo '[DOMINUS]: Cannot find Dominus .git repository:' $DOMINUS_DIR'/.git, unable to update. Skipping...'
fi
}
#
# Setup
#
setup()
{
case "$1" in
environment) environment;;
project) project;;
travis) travis;;
certificate) certificate;;
*) help_setup
exit 1
;;
esac
}
#
# Integrate
#
integrate()
{
#
# Store action as global
#
if [[ ! -z $1 ]]; then
ACTION=$1
fi
if [[ -z $ACTION ]]; then
ACTION='build'
fi
if [ "$ACTION" == "test" ]; then
ACTION='run_tests'
fi
#
# Create build and test SDK's if both sdk and platform are specified
#
if [[ -z $PLATFORM ]]; then
PLATFORM='iphone'
fi
if [[ ! -z $SDK ]] && [[ ! -z $PLATFORM ]]; then
if [ "$PLATFORM" == "iphone" ]; then
if [ "$ACTION" != "run_tests" ]; then
BUILD_SDK=$PLATFORM'os'
BUILD_SDK=$BUILD_SDK"$SDK"
fi
#
# If no developer provisioning is defined, we will set Build SDK to be the simulator
#
if [[ -z $DEVELOPER_PROVISIONING ]]; then
BUILD_SDK=$PLATFORM'simulator'
BUILD_SDK=$BUILD_SDK"$SDK"
fi
TEST_SDK=$PLATFORM'simulator'$SDK
else
BUILD_SDK=$PLATFORM"$SDK"
TEST_SDK=$PLATFORM"$SDK"
fi
fi
export BUILD_SDK=$BUILD_SDK
export TEST_SDK=$TEST_SDK
#
# Init and library is always run on CI, since it always starts
# from point 0
#
if [ "$CI" = true ] && [ "$ACTION" != "report" ]; then
init
#library
fi
#
# Version 2.x.x Creates a Fastlane integration
#
init
fastlane_integrate
exit 0
#
# Define actions
#
case "$ACTION" in
init) init;;
library) library;;
build) provision;
cert;
project_build;;
run_tests) run_tests;;
quality) quality;;
report) report;;
deploy) provision;
cert;
project_build;
send;;
send) send;;
*) exit 1;;
esac
#
# Finalize report and clean
#
if [ "$ACTION" != "report" ]; then
report
fi
clean
}
#
# Environment
#
environment()
{
if [[ -f $SCRIPT_PATH'setup/environment.sh' ]]; then
$SCRIPT_PATH'setup/environment.sh'
else
echo '[DOMINUS]: Unable to find 'environment' script. Try to run' \"$0 update\"'.'
exit 1
fi
}
#
# Project
#
project()
{
if [[ -f $SCRIPT_PATH'setup/project.sh' ]]; then
$SCRIPT_PATH'setup/project.sh' -c
else
echo '[DOMINUS]: Unable to find 'project' script. Try to run' \"$0 update\"'.'
exit 1
fi
}
#
# Travis
#
travis()
{
if [[ -f $SCRIPT_PATH'setup/project.sh' ]]; then
$SCRIPT_PATH'setup/project.sh' -t
else
echo '[DOMINUS]: Unable to find 'project' script. Try to run' \"$0 update\"'.'
exit 1
fi
}
#
# Certificate
#
certificate()
{
echo '[DOMINUS]: Certificate Not implemented'
}
#
# Build project
#
project_build()
{
#
# Add CI build number to building
#
PROFILE=$DEVELOPER_PROVISIONING
if [ "$DEPLOY_USE_BUILD_NUMBER" == "ci" ] && [[ ! -z $CI_BUILD_NUMBER ]]; then
BUILD_NUMBER=$CI_BUILD_NUMBER
elif [ "$DEPLOY_USE_BUILD_NUMBER" == "project" ] && [[ ! -z $CI_BUILD_NUMBER ]]; then
BUILD_NUMBER=$CI_BUILD_NUMBER
ADD_BUILD_NUMBER_TO_PROJECT=true
fi
build
}
#
# Global settings
#
VARIABLE_PATH='./dominus.cfg'
ATLANTIS_PATH='distribution'
#
# Search for correct script path
#
SCRIPT_PATH=`find . -name dominus.sh | head -n1`
SCRIPT_PATH=$(dirname ${SCRIPT_PATH})
SCRIPT_PATH=$SCRIPT_PATH'/scripts/'
SCRIPT_VERSION='2.0.0-alpha1'
echo '[DOMINUS]: System started. Script version:' $SCRIPT_VERSION
echo '[DOMINUS]: Integration by Dal Rupnik <legoless@gmail.com>'
#
# Load all utility functions and CI environment
#
load
load_ci_environment
check_excluded_branch
check_included_branch
#
# Load environment variables from file, if it exists, otherwise they should be loaded
# in environment by CI itself, to make it secure.
#
set -a
if [ -f $VARIABLE_PATH ]; then
test -f $VARIABLE_PATH && . $VARIABLE_PATH
fi
set +a
#set -o
#
# Check if there was any command provided, otherwise display usage
#
case "$1" in
help) help_usage;;
version) version;;
update) update;;
setup) setup $2;;
integrate) integrate $2;;
*) help_usage
exit 1
;;
esac