22
33set -e
44
5- SCRIPT_DIR=$( dirname " $0 " )
6- export SCRIPT_DIR
7-
8- # Includes
9- . " $SCRIPT_DIR /update_build_number"
10- . " $SCRIPT_DIR /update_version"
11- . " $SCRIPT_DIR /update_keychain"
12-
13- GIT_COMMIT=$( git rev-parse --short HEAD)
14- GIT_BRANCH=$( git rev-parse --abbrev-ref HEAD)
15- GIT_TAG=$( git describe --GIT_TAGs --exact-match --match " v*" 2> /dev/null || echo " " )
16- GIT_DIRTY=$( test -n " $( git status --porcelain) " && echo true || echo false)
17- GIT_LOG=$( git log -1 --pretty=format:%s)
18- export GIT_COMMIT GIT_BRANCH GIT_TAG GIT_DIRTY GIT_LOG
19-
20- BUILD=
21- VERSION=
22- export BUILD VERSION
23-
24- silent=0
5+ include_funcs ()
6+ {
7+ # Includes
8+ . " $SCRIPT_DIR /update_build_number"
9+ . " $SCRIPT_DIR /update_version"
10+ . " $SCRIPT_DIR /update_keychain"
11+ }
2512
2613say ()
2714{
28- if [ " $silent " = 0 ];
15+ if [ " $SILENT " != 1 ];
2916 then
3017 if [ " $1 " = " -n" ]
3118 then
@@ -36,40 +23,77 @@ say ()
3623 fi
3724}
3825
39- if [ " $CI_SERVER_NAME " = " GitLab CI" ];
40- then
41- say " GitLab CI detected."
42- GIT_BRANCH=$CI_BUILD_REF_NAME
43- GIT_COMMIT=$CI_BUILD_REF
44- VERSION=${GIT_TAG: 1}
45- BUILD=$CI_BUILD_ID
46- fi
26+ bootstrap_ci_env ()
27+ {
28+ if [ " $CI_SERVER_NAME " = " GitLab CI" ];
29+ then
30+ say " GitLab CI detected."
31+ GIT_BRANCH=$CI_BUILD_REF_NAME
32+ GIT_COMMIT=$CI_BUILD_REF
33+ VERSION=${GIT_TAG: 1}
34+ BUILD=$CI_BUILD_ID
35+ fi
4736
48- import_certs
49- import_provisions
37+ # Fallback to default values
38+ GIT_COMMIT=${GIT_COMMIT:- $(git rev-parse --short HEAD)}
39+ GIT_BRANCH=${GIT_BRANCH:- $(git rev-parse --abbrev-ref HEAD)}
40+ GIT_TAG=${GIT_TAG:- $(git describe --GIT_TAGs --exact-match --match " v*" 2>/ dev/ null || echo " " )}
41+ GIT_DIRTY=${GIT_DIRTY:- $(test -n " $( git status --porcelain) " && echo true || echo false)}
42+ GIT_LOG=${GIT_LOG:- $(git log -1 --pretty=format:% s)}
43+ BUILD=${BUILD:- local}
44+ VERSION=${VERSION:- 0.0.0}
5045
51- if [ -n " $GIT_TAG " ];
52- then
53- say " Preparing for Beta Release $GIT_TAG "
46+ export GIT_COMMIT GIT_BRANCH GIT_TAG GIT_DIRTY GIT_LOG BUILD VERSION
47+ }
5448
55- update_build_number " $BUILD "
56- update_version " $VERSION "
49+ build_default ()
50+ {
51+ import_certs
52+ import_provisions
5753
58- make release-beta
54+ if [ -n " $GIT_TAG " ];
55+ then
56+ say " Preparing for Beta Release $GIT_TAG "
5957
60- elif [ " $GIT_BRANCH " = " master" ];
61- then
62- say " Preparing for Alpha Release"
58+ update_build_number " $BUILD "
59+ update_version " $VERSION "
6360
64- update_build_number " $BUILD "
61+ make release-beta
6562
66- make release-alpha
63+ elif [ " $GIT_BRANCH " = " master" ];
64+ then
65+ say " Preparing for Alpha Release"
6766
68- else
69- say " Preparing for Development Release"
67+ update_build_number " $BUILD "
7068
71- make test
72- fi
69+ make release-alpha
70+
71+ else
72+ say " Preparing for Development Release"
73+
74+ make test
75+ fi
76+
77+ delete_provisions
78+ delete_keychain
79+ }
80+
81+ main () {
82+ SCRIPT_DIR=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd)
83+
84+ include_funcs
85+ bootstrap_ci_env
86+
87+ if [ " ${BASH_SOURCE[0]} " != " ${0} " ];
88+ then
89+ say " *** CI build environment bootstraped"
90+ elif [ " $# " -gt 0 ];
91+ then
92+ say " *** Running $* "
93+ " $@ "
94+ else
95+ build_default
96+ fi
97+ }
7398
74- delete_provisions
75- delete_keychain
99+ main " $@ "
0 commit comments