forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci
executable file
·235 lines (202 loc) · 7.17 KB
/
ci
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
#!/usr/bin/env bash
# this ensures any failures along the way result in a CI failure
set -eu
node-0() {
is_enabled "drivers" && export ENGINES="h2,mongo,mysql,bigquery" || export ENGINES="h2"
if is_engine_enabled "mongo"; then
run_step install-mongodb
fi
MB_MYSQL_TEST_USER=ubuntu run_step lein-test
}
node-1() {
run_step lein with-profile +ci docstring-checker
is_enabled "drivers" && export ENGINES="h2,sqlserver,oracle" || export ENGINES="h2"
if is_engine_enabled "oracle"; then
run_step install-oracle
fi
MB_DB_TYPE=postgres MB_DB_DBNAME=circle_test MB_DB_PORT=5432 MB_DB_USER=ubuntu MB_DB_HOST=localhost \
run_step lein-test
}
node-2() {
run_step lein with-profile +ci bikeshed
is_enabled "drivers" && export ENGINES="h2,postgres,sqlite,presto" || export ENGINES="h2"
if is_engine_enabled "crate"; then
run_step install-crate
fi
if is_engine_enabled "presto"; then
run_step install-presto
fi
MB_ENCRYPTION_SECRET_KEY='Orw0AAyzkO/kPTLJRxiyKoBHXa/d6ZcO+p+gpZO/wSQ=' MB_DB_TYPE=mysql MB_DB_DBNAME=circle_test MB_DB_PORT=3306 MB_DB_USER=ubuntu MB_DB_HOST=localhost \
MB_PRESTO_TEST_HOST=localhost MB_PRESTO_TEST_PORT=8080 MB_POSTGRESQL_TEST_USER=ubuntu \
run_step lein-test
}
node-3() {
run_step yarn run lint
run_step yarn run flow
is_enabled "drivers" && export ENGINES="h2,redshift,druid,vertica" || export ENGINES="h2"
if is_engine_enabled "vertica"; then
run_step install-vertica
fi
# this is redundant with node 0 unless one of the non-H2 driver tests is enabled
if [ ENGINES != "h2" ]; then
run_step lein-test
fi
}
node-4() {
run_step ./bin/reflection-linter
run_step ./bin/build version frontend sample-dataset uberjar
report-frontend-size
report-uberjar-size
}
node-5() {
run_step lein with-profile +ci eastwood
run_step yarn run test-karma
run_step yarn run test-unit
report-frontend-coverage
}
node-6() {
run_step ./bin/build version sample-dataset uberjar
run_step yarn run test-integrated
}
report() {
timestamp="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
name="$1"
value="$2"
if ! [ -z ${STATS_DB+x} ]; then
psql "$STATS_DB" -c "INSERT INTO build_stats (timestamp, name, value, build_number, node_index, branch, hash) VALUES ('$timestamp', '$name', $value, $CIRCLE_BUILD_NUM, $CIRCLE_NODE_INDEX, '$CIRCLE_BRANCH', '$CIRCLE_SHA1');" > /dev/null
fi
}
report-frontend-coverage() {
report "frontend-coverage-lines" $(node -e "console.log(require('./coverage-summary.json').total.lines.pct)")
report "frontend-coverage-functions" $(node -e "console.log(require('./coverage-summary.json').total.functions.pct)")
report "frontend-coverage-branches" $(node -e "console.log(require('./coverage-summary.json').total.branches.pct)")
report "frontend-coverage-statements" $(node -e "console.log(require('./coverage-summary.json').total.statements.pct)")
report "frontend-loc" $(node -e "console.log(require('./coverage-summary.json').total.lines.total)")
}
report-frontend-size() {
report "frontend-size" "$(wc -c < resources/frontend_client/app/dist/app-main.bundle.js)"
}
report-uberjar-size() {
report "uberjar-size" "$(wc -c < target/uberjar/metabase.jar)"
}
install-crate() {
sudo add-apt-repository ppa:crate/stable -y
sudo apt-get update
sudo apt-get install -y crate
# ulimit setting refused Crate service to start on CircleCI container - so comment it
sudo sed -i '/MAX_LOCKED_MEMORY/s/^/#/' /etc/init/crate.conf
echo "psql.port: 5200" | sudo tee -a /etc/crate/crate.yml
sudo service crate restart
}
install-mongodb() {
sudo apt-get purge mongodb-org*
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod restart
}
install-oracle() {
wget --output-document=plugins/ojdbc7.jar $ORACLE_JDBC_JAR
}
install-vertica() {
wget --output-document=plugins/vertica-jdbc-7.1.2-0.jar $VERTICA_JDBC_JAR
docker run --detach --publish 5433:5433 sumitchawla/vertica
sleep 60
}
install-presto() {
docker run --detach --publish 8080:8080 metabase/presto-mb-ci
sleep 10
}
lein-test() {
lein with-profile +ci test
}
if [ -z ${CIRCLE_BRANCH_REGEX+x} ]; then
CIRCLE_BRANCH_REGEX='^master|release-.+$'
fi
is_enabled() {
(echo "$CIRCLE_BRANCH" | grep -qE "$CIRCLE_BRANCH_REGEX") ||
[[ "$CIRCLE_COMMIT_MESSAGE" == *"[ci $1]"* ]] ||
[[ "$CIRCLE_COMMIT_MESSAGE" == *"[ci all]"* ]]
}
is_engine_enabled() {
[[ "$ENGINES" == *"$1"* ]]
}
# print a summary on exit
status=0
summary=""
# records the time and exit code of each step
run_step() {
status=0
start=$(date +%s)
# run in the background then `wait` so fail_fast can interrupt it
"$@" &
wait $! || status=$?
elapsed=$(expr $(date +%s) - $start || true)
summary="${summary}status=$status time=$elapsed command=$@\n"
report "run-status \"$*\"" "$status"
report "run-time \"$*\"" "$elapsed"
return $status
}
summary() {
# if last status was failure then fail the rest of the nodes
if [ $status != 0 ]; then
fail_fast
fi
echo -e "========================================"
echo -en "$summary"
echo -e "========================================"
}
trap summary EXIT
fail_fast() {
if [ -z ${CIRCLE_NODE_TOTAL+x} ]; then
return 0
fi
echo -e "========================================"
echo -e "Failing fast! Stopping other nodes..."
# Touch a file to differentiate between a local failure and a
# failure triggered by another node
touch '/tmp/local-fail'
# ssh to the other CircleCI nodes and send SIGUSR1 to tell them to exit early
for (( i = 0; i < $CIRCLE_NODE_TOTAL; i++ )); do
if [ $i != $CIRCLE_NODE_INDEX ]; then
ssh node$i 'touch /tmp/fail; pkill -SIGUSR1 -f "bash ./bin/ci"' 2> /dev/null || true
fi
done
}
exit_early() {
echo -e "========================================"
echo -e "Exited early! Did not necesssarily pass!"
pkill -TERM -P $$ || true
exit 0
}
trap exit_early SIGUSR1
if [ -z ${CIRCLE_BUILD_NUM+x} ]; then
export CIRCLE_BUILD_NUM="-1"
fi
if [ -z ${CIRCLE_SHA1+x} ]; then
export CIRCLE_SHA1="$(git rev-parse HEAD)"
fi
if [ -z ${CIRCLE_BRANCH+x} ]; then
export CIRCLE_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
fi
export CIRCLE_COMMIT_MESSAGE="$(git log --format=oneline -n 1 $CIRCLE_SHA1)"
# This local-fail check is to guard against two nodes failing at the
# same time. Both nodes ssh to each node and drop /tmp/fail. Those
# failing nodes then get here and see and the other node has told it
# to exit early. This results in both nodes exiting early, and thus
# not failing, causing the build to succeed
if [[ -f "/tmp/fail" && ! -f "/tmp/local-fail" ]]; then
exit_early
fi
if [ -z ${CIRCLE_NODE_INDEX+x} ]; then
# If CIRCLE_NODE_INDEX isn't set, read node numbers from the args
# Useful for testing locally.
for i in "$@"; do
export CIRCLE_NODE_INDEX="$i"
node-$i
done
else
# Normal mode on CircleCI
node-$CIRCLE_NODE_INDEX
fi