-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcibuild
executable file
·115 lines (94 loc) · 2.71 KB
/
cibuild
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
#!/usr/bin/env bash
set -e
say ()
{
if [ "$SILENT" != 1 ];
then
if [ "$1" = "-n" ]
then
echo -n "$2"
else
echo "$1"
fi
fi
}
bootstrap_ci_env ()
{
if [ "$CI_SERVER_NAME" = "GitLab CI" ];
then
say "GitLab CI detected."
GIT_BRANCH=$CI_BUILD_REF_NAME
GIT_COMMIT=$CI_BUILD_REF
VERSION=${GIT_TAG:1}
BUILD=$CI_BUILD_ID
elif [ "$JENKINS_URL" != "" ];
then
say "Jenkins CI detected."
# Jenkins GIT_BRANCH is like 'origin/master'
GIT_BRANCH=${GIT_BRANCH#*/}
GIT_COMMIT=$GIT_COMMIT
BUILD=$BUILD_NUMBER
VERSION=${GIT_TAG:1}
# $GIT_COMMIT and $GIT_BRANCH is exported by Jenkins
# https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
# https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin-EnvironmentVariables
elif [ "$CI" = "true" ] && [ "$CIRCLECI" = "true" ];
then
say "Circle CI detected."
# https://circleci.com/docs/environment-variables
GIT_BRANCH=$CIRCLE_BRANCH
GIT_COMMIT=$CIRCLE_SHA1
VERSION=${GIT_TAG:1}
BUILD=$CIRCLE_BUILD_NUM
else
say "Unknown CI detected."
fi
# Fallback to default values
GIT_COMMIT=${GIT_COMMIT:-$(git rev-parse --short HEAD)}
GIT_BRANCH=${GIT_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}
GIT_TAG=${GIT_TAG:-$(git describe --GIT_TAGs --exact-match --match "v*" 2>/dev/null || echo "")}
GIT_DIRTY=${GIT_DIRTY:-$(test -n "$(git status --porcelain)" && echo true || echo false)}
GIT_LOG=${GIT_LOG:-$(git log -1 --pretty=format:%s)}
BUILD=${BUILD:-local}
VERSION=${VERSION:-0.0.0}
export GIT_COMMIT GIT_BRANCH GIT_TAG GIT_DIRTY GIT_LOG BUILD VERSION
}
build_default ()
{
cert --import
mobileprovision --import
if [ -n "$GIT_TAG" ];
then
say "Preparing for Beta Release $GIT_TAG"
update_build_number "$BUILD"
update_version "$VERSION"
make release-beta
elif [ "$GIT_BRANCH" = "master" ];
then
say "Preparing for Alpha Release"
update_build_number "$BUILD"
make release-alpha
else
say "Preparing for Development Release"
make test
fi
cert --remove
mobileprovision --remove
}
main () {
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PATH=$SCRIPT_DIR:$PATH
export SCRIPT_DIR PATH
bootstrap_ci_env
if [ "${BASH_SOURCE[0]}" != "${0}" ];
then
say "*** CI build environment bootstraped"
elif [ "$#" -gt 0 ];
then
say "*** Running $*"
"$@"
else
build_default
fi
}
main "$@"