Skip to content

Commit c2c6f3f

Browse files
Add gitlab-ci.yml
1 parent 751ce70 commit c2c6f3f

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

generators/app/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ module.exports = yeoman.generators.Base.extend({
109109
}.bind(this));
110110
},
111111

112+
askForGitLab: function () {
113+
var done = this.async();
114+
115+
var prompts = [{
116+
type: 'confirm',
117+
name: 'gitlab',
118+
message: 'Would you like to enable GitLab CI?',
119+
default: true,
120+
}];
121+
122+
this.prompt(prompts, function (props) {
123+
this.gitlab = props.gitlab;
124+
done();
125+
}.bind(this));
126+
},
127+
112128
askForCertPath: function () {
113129
var done = this.async();
114130
var travis = this.travis;
@@ -218,6 +234,19 @@ module.exports = yeoman.generators.Base.extend({
218234
}
219235
},
220236

237+
gitlab: function () {
238+
if (!this.gitlab) {
239+
return;
240+
}
241+
var files = [
242+
'.gitlab-ci.yml',
243+
'script/cibuild',
244+
];
245+
files.forEach(function (entry) {
246+
this.fs.copy(this.templatePath(entry), this.destinationPath(entry));
247+
}.bind(this));
248+
},
249+
221250
cocoapods: function () {
222251
if (!this.cocoapods) {
223252
return;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This file is generated by GitLab CI
2+
Unit Test:
3+
stage: build
4+
script:
5+
- "./script/cibuild make test-unit"
6+
tags:
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
say ()
6+
{
7+
if [ "$SILENT" != 1 ];
8+
then
9+
if [ "$1" = "-n" ]
10+
then
11+
echo -n "$2"
12+
else
13+
echo "$1"
14+
fi
15+
fi
16+
}
17+
18+
bootstrap_ci_env ()
19+
{
20+
if [ "$CI_SERVER_NAME" = "GitLab CI" ];
21+
then
22+
say "GitLab CI detected."
23+
GIT_BRANCH=$CI_BUILD_REF_NAME
24+
GIT_COMMIT=$CI_BUILD_REF
25+
VERSION=${GIT_TAG:1}
26+
BUILD=$CI_BUILD_ID
27+
28+
elif [ "$CI" = "true" ] && [ "$CIRCLECI" = "true" ];
29+
then
30+
say "Circle CI detected."
31+
# https://circleci.com/docs/environment-variables
32+
GIT_BRANCH=$CIRCLE_BRANCH
33+
GIT_COMMIT=$CIRCLE_SHA1
34+
VERSION=${GIT_TAG:1}
35+
BUILD=$CIRCLE_BUILD_NUM
36+
fi
37+
38+
# Fallback to default values
39+
GIT_COMMIT=${GIT_COMMIT:-$(git rev-parse --short HEAD)}
40+
GIT_BRANCH=${GIT_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}
41+
GIT_TAG=${GIT_TAG:-$(git describe --GIT_TAGs --exact-match --match "v*" 2>/dev/null || echo "")}
42+
GIT_DIRTY=${GIT_DIRTY:-$(test -n "$(git status --porcelain)" && echo true || echo false)}
43+
GIT_LOG=${GIT_LOG:-$(git log -1 --pretty=format:%s)}
44+
BUILD=${BUILD:-local}
45+
VERSION=${VERSION:-0.0.0}
46+
47+
export GIT_COMMIT GIT_BRANCH GIT_TAG GIT_DIRTY GIT_LOG BUILD VERSION
48+
}
49+
50+
build_default ()
51+
{
52+
cert --import
53+
mobileprovision --import
54+
55+
if [ -n "$GIT_TAG" ];
56+
then
57+
say "Preparing for Beta Release $GIT_TAG"
58+
59+
update_build_number "$BUILD"
60+
update_version "$VERSION"
61+
62+
make release-beta
63+
64+
elif [ "$GIT_BRANCH" = "master" ];
65+
then
66+
say "Preparing for Alpha Release"
67+
68+
update_build_number "$BUILD"
69+
70+
make release-alpha
71+
72+
else
73+
say "Preparing for Development Release"
74+
75+
make test
76+
fi
77+
78+
cert --remove
79+
mobileprovision --remove
80+
}
81+
82+
main () {
83+
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
84+
PATH=$SCRIPT_DIR:$PATH
85+
export SCRIPT_DIR PATH
86+
87+
bootstrap_ci_env
88+
89+
if [ "${BASH_SOURCE[0]}" != "${0}" ];
90+
then
91+
say "*** CI build environment bootstraped"
92+
elif [ "$#" -gt 0 ];
93+
then
94+
say "*** Running $*"
95+
"$@"
96+
else
97+
build_default
98+
fi
99+
}
100+
101+
main "$@"

0 commit comments

Comments
 (0)