-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·433 lines (392 loc) · 12.4 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·433 lines (392 loc) · 12.4 KB
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!/bin/bash
if [ ! -e node_modules ]
then
mkdir node_modules
fi
# Set CI_OPTION to " -T " if running in CI environment
CI_OPTION=""
if [ ! -z "$CI" ] && [ "$CI" = "true" ]
then
CI_OPTION=" -T "
fi
case `uname -s` in
MINGW* | Darwin*)
USER_UID=1000
GROUP_UID=1000
;;
*)
if [ -z ${USER_UID:+x} ]
then
USER_UID=`id -u`
GROUP_GID=`id -g`
fi
esac
# build options
NO_DOCKER=""
SPRINGBOARD="recette"
# Initialize MODULE from env; --module=/-m= overrides it.
MODULE="${MODULE:-}"
MVN_OPTS="-Duser.home=/var/maven -T 4"
for i in "$@"
do
case $i in
--no-docker*)
NO_DOCKER="true"
MVN_OPTS=""
shift
;;
-s=*|--springboard=*)
SPRINGBOARD="${i#*=}"
shift
;;
-m=*|--module=*)
MODULE="${i#*=}"
shift
;;
*)
;;
esac
done
if [ "$MODULE" = "" ]; then
GRADLE_OPTION=""
NODE_OPTION=""
else
GRADLE_OPTION=":$MODULE:"
NODE_OPTION="--module $MODULE"
if [ -e "$MODULE/backend" ]; then
echo "BACKEND SUB-PROJECT $MODULE/backend DETECTED"
MVN_OPTS="$MVN_OPTS --projects $MODULE/backend -am"
else
MVN_OPTS="$MVN_OPTS --projects $MODULE -am"
fi
fi
#try jenkins branch name => then local git branch name => then jenkins params
echo "[buildNode] Get branch name from jenkins env..."
BRANCH_NAME=`echo $GIT_BRANCH | sed -e "s|origin/||g"`
if [ "$BRANCH_NAME" = "" ]; then
echo "[buildNode] Get branch name from git..."
BRANCH_NAME=`git branch | sed -n -e "s/^\* \(.*\)/\1/p"`
fi
if [ ! -z "$FRONT_TAG" ]; then
echo "[buildNode] Get tag name from jenkins param... $FRONT_TAG"
BRANCH_NAME="$FRONT_TAG"
fi
if [ "$BRANCH_NAME" = "" ]; then
echo "[buildNode] Branch name should not be empty!"
exit -1
fi
echo "======================"
echo "BRANCH_NAME = $BRANCH_NAME"
echo "======================"
init() {
me=`id -u`:`id -g`
echo "DEFAULT_DOCKER_USER=$me" > .env
# If CLI_VERSION is empty set $cli_version to latest
if [ -z "$CLI_VERSION" ]; then
CLI_VERSION="latest"
fi
# Create a build.compose.yaml file from following template
cat <<EOF > build.compose.yaml
services:
edifice-cli:
image: opendigitaleducation/edifice-cli:$CLI_VERSION
user: "$DEFAULT_DOCKER_USER"
EOF
# Copy /root/edifice from edifice-cli container to host machine
docker compose -f build.compose.yaml create edifice-cli
docker compose -f build.compose.yaml cp edifice-cli:/root/edifice ./edifice
docker compose -f build.compose.yaml rm -fsv edifice-cli
rm -f build.compose.yaml
chmod +x edifice
./edifice version $EDIFICE_CLI_DEBUG_OPTION
}
clean () {
if [ "$NO_DOCKER" = "true" ] ; then
mvn $MVN_OPTS clean
else
docker compose run --rm $USER_OPTION maven mvn $MVN_OPTS clean
fi
}
syncReactFrontendBuildToResources() {
sync_target_root="$1"
sync_resources_dir="$sync_target_root/src/main/resources"
sync_public_dir="$sync_resources_dir/public"
sync_view_dir="$sync_resources_dir/view"
# Move dist to resources dir
cp -R ./dist/* "$sync_resources_dir/"
# Create resources/view directory if needed
mkdir -p "$sync_view_dir"
# Move generated HTML entrypoints into the view directory when present.
for html_file in "$sync_resources_dir"/*.html; do
[ -f "$html_file" ] || continue
echo "...moving HTML file $html_file to $sync_view_dir/"
mv "$html_file" "$sync_view_dir/"
done
unset sync_target_root sync_resources_dir sync_public_dir sync_view_dir file file_name html_file
}
buildFrontend () {
# --- Build angularJS-based frontends
if [ "$MODULE" = "" ] || [ ! "$MODULE" = "admin" ] && [ ! -e ./"$MODULE"/frontend ] || [ "$MODULE" = "timeline" ] || [ "$MODULE" = "auth" ]; then
if [ "$BRANCH_NAME" = 'master' ] || [ "$BRANCH_NAME" = 'fix' ] || [ "$BRANCH_NAME" = 'release' ]; then
echo "[buildNode] Use entcore version from package.json ($BRANCH_NAME)"
case `uname -s` in
MINGW*)
docker compose run --rm -u "$USER_UID:$GROUP_GID" $CI_OPTION node sh -c "npm install --no-bin-links --legacy-peer-deps && npm update --legacy-peer-deps entcore && node_modules/gulp/bin/gulp.js build $NODE_OPTION"
;;
*)
docker compose run --rm -u "$USER_UID:$GROUP_GID" $CI_OPTION node sh -c "npm install --legacy-peer-deps && npm update --legacy-peer-deps entcore && node_modules/gulp/bin/gulp.js build $NODE_OPTION --springboard=/home/node/$SPRINGBOARD"
esac
else
echo "[buildNode] Use entcore tag $BRANCH_NAME"
docker compose run --rm -u "$USER_UID:$GROUP_GID" $CI_OPTION node sh -c "npm rm --no-save entcore ode-ts-client ode-ngjs-front && npm install --no-save entcore@$BRANCH_NAME ode-ts-client@$BRANCH_NAME ode-ngjs-front@$BRANCH_NAME"
case `uname -s` in
MINGW*)
docker compose run --rm -T -u "$USER_UID:$GROUP_GID" $CI_OPTION node sh -c "npm install --no-bin-links --legacy-peer-deps && node_modules/gulp/bin/gulp.js build $NODE_OPTION"
;;
*)
docker compose run --rm -T -u "$USER_UID:$GROUP_GID" $CI_OPTION node sh -c "npm install --legacy-peer-deps && node_modules/gulp/bin/gulp.js build $NODE_OPTION --springboard=/home/node/$SPRINGBOARD"
esac
fi
fi
# --- Build react-based frontends
local modules
if [ "$MODULE" = "" ]; then
modules=($(ls -d */ | cut -f1 -d'/'))
else
modules=($MODULE)
fi
for module in "${modules[@]}"; do
if [ -e ./"$module"/frontend ]; then
echo -e "[Build React] Build react frontend for module $module"
cd ./"$module"/frontend
if [ "$NO_DOCKER" = "true" ] ; then
./build.sh --no-docker clean init build
else
./build.sh clean init build
fi
if [ $? -ne 0 ]; then
echo "Error while building React frontend for module $module"
exit 1
fi
# Create directory structure and copy frontend build files.
if [ "$module" = "timeline" ] || [ "$module" = "auth" ]; then
# compatibility mode : preserve legacy frontends files in ../src
syncReactFrontendBuildToResources ".."
else
syncReactFrontendBuildToResources "../backend"
fi
# Clean up
rm -rf ./dist
cd ../..
fi
if [ -e ./"$module"/frontend-crna ]; then
echo -e "[Build React] Build react frontend-crna for module $module"
cd ./"$module"/frontend-crna
if [ "$NO_DOCKER" = "true" ] ; then
./build.sh --no-docker clean init build
else
./build.sh clean init build
fi
if [ $? -ne 0 ]; then
echo "Error while building React frontend-crna for module $module"
exit 1
fi
syncReactFrontendBuildToResources ".."
rm -rf ./dist
cd ../..
fi
done
# --- Build angular-based frontends
if [ "$MODULE" = "" ] || [ "$MODULE" = "admin" ]; then
case `uname -s` in
MINGW*)
docker compose run --rm -u "$USER_UID:$GROUP_GID" $CI_OPTION node16 sh -c "npm install --no-bin-links && npm rm --no-save ngx-ode-core ngx-ode-sijil ngx-ode-ui && npm install --no-save ngx-ode-core@$BRANCH_NAME ngx-ode-sijil@$BRANCH_NAME ngx-ode-ui@$BRANCH_NAME && npm run build-docker-prod"
;;
*)
docker compose run --rm -u "$USER_UID:$GROUP_GID" $CI_OPTION node16 sh -c "npm install && npm rm --no-save ngx-ode-core ngx-ode-sijil ngx-ode-ui && npm install --no-save ngx-ode-core@$BRANCH_NAME ngx-ode-sijil@$BRANCH_NAME ngx-ode-ui@$BRANCH_NAME && npm run build-docker-prod"
esac
fi
}
buildBackend () {
if [ "$NO_DOCKER" = "true" ] ; then
mvn $MVN_OPTS install -DskipTests
else
docker compose run --rm $USER_OPTION maven mvn $MVN_OPTS install -DskipTests -U
fi
}
install () {
docker compose run $CI_OPTION --rm maven mvn $MVN_OPTS clean install -DskipTests -U
cd broker-parent/broker-client/quarkus
./build.sh install
cd -
}
test () {
if [ -z "$JAVA_8_HOME" ]
then
mvn test
else
JAVA_HOME=$JAVA_8_HOME mvn test
fi
}
localDep () {
for dep in ode-ts-client ode-ngjs-front ; do
if [ -e $PWD/../$dep ]; then
rm -rf $dep.tar $dep.tar.gz
mkdir $dep.tar && mkdir $dep.tar/dist \
&& cp -R $PWD/../$dep/dist $PWD/../$dep/package.json $dep.tar
tar cfzh $dep.tar.gz $dep.tar
docker compose run --rm -u "$USER_UID:$GROUP_GID" $CI_OPTION node sh -c "npm install --no-save $dep.tar.gz"
rm -rf $dep.tar $dep.tar.gz
fi
done
}
watch () {
docker compose run --rm maven sh -c "mvn $MVN_OPTS help:evaluate -Dexpression=project.groupId -q -DforceStdout -pl $MODULE && echo -n '~$MODULE~' && mvn $MVN_OPTS help:evaluate -Dexpression=project.version -pl $MODULE -q -DforceStdout" > .version.properties
docker compose run --rm \
$USER_OPTION \
-v $PWD/../$SPRINGBOARD:/home/node/$SPRINGBOARD \
node sh -c "npx gulp watch-$MODULE $NODE_OPTION --springboard=../$SPRINGBOARD "
rm -f .version.properties
}
# ex: ./build.sh -m=workspace -s=paris watch
ngWatch () {
docker compose run --rm -u "$USER_UID:$GROUP_GID" $CI_OPTION --publish 4200:4200 node16 sh -c "npm run dev"
}
infra () {
docker compose run --rm -u "$USER_UID:$GROUP_GID" $CI_OPTION node sh -c "npm install /home/node/infra-front"
}
publish() {
version=`docker compose run --rm $USER_OPTION maven mvn $MVN_OPTS help:evaluate -Dexpression=project.version -q -DforceStdout`
level=`echo $version | cut -d'-' -f3`
case "$level" in
*SNAPSHOT) export nexusRepository='snapshots' ;;
*) export nexusRepository='releases' ;;
esac
docker compose run --rm maven mvn $MVN_OPTS -DrepositoryId=ode-$nexusRepository -DskipTests --settings /var/maven/.m2/settings.xml deploy
}
image() {
./edifice image --project-type=entcore --rebuild=false $EDIFICE_CLI_DEBUG_OPTION
}
check_prefix_sh_file() {
dir_path=$1 # Directory path
search_str=$2 # String to check
# Loop over each .sh file in the directory
for file in "$dir_path"/*.sh; do
if [ -f "$file" ]; then
# Get the file name without the extension
base_name=$(basename "$file" .sh)
# Check if the file name is a prefix of the search string
if [[ "$search_str" == "$base_name"* ]]; then
return 0 # Found a match, return 0 (success)
fi
fi
done
return 1 # No match found, return 1 (failure)
}
itTests() {
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd $script_dir/tests/src/test/js
docker compose run --rm -T node18 pnpm i --force
cd $script_dir/tests/src/test/js/it/scenarios
failed_files=()
exit_code=0
js_files=($(find . -type f -name '*.ts' ! -name '_*'))
for it_file in "${js_files[@]}"; do
short_file_name=$(basename -s .ts $it_file)
file_dir=$(dirname $it_file)
check_prefix_sh_file "$file_dir" "$short_file_name"
if [ $? -eq 1 ]; then
echo executing $it_file
docker compose run --rm -T k6 run --compatibility-mode=experimental_enhanced file:///home/k6/src/it/scenarios/$it_file
if [ $? -ne 0 ]; then
exit_code=1
failed_files+=("$it_file")
echo "Error while executing : $it_file"
fi
fi
done
sh_files=($(find . -type f -name '*.sh'))
for sh_file in "${sh_files[@]}"; do
echo executing $sh_file
"$sh_file" "$script_dir/tests/src/test/resources/data" "$script_dir/../$SPRINGBOARD"
if [ $? -ne 0 ]; then
exit_code=1
failed_files+=("$sh_file")
echo "Error while executing : $sh_file"
fi
done
cd -
# Output summary of failed files
if [ ${#failed_files[@]} -ne 0 ]; then
echo "|-------------------------|"
echo "|--- FAILED TEST FILES ---|"
for failed in "${failed_files[@]}"; do
echo "| $failed"
done
echo "|-------------------------|"
fi
echo "|-------------------------|"
[ $exit_code -ne 0 ] && echo "|---- itTests FAILED ----|" || echo "|--- itTests SUCCEEDED ---|"
echo "|-------------------------|"
exit $exit_code
}
if [ ! -e .env ]; then
init
fi
for param in "$@"
do
case $param in
'--no-user')
;;
init)
init
;;
clean)
clean
;;
buildFrontend)
buildFrontend
;;
buildBackend)
buildBackend
;;
buildMvn)
install
;;
install)
buildFrontend && buildBackend
;;
buildBack)
install
;;
localDep)
localDep
;;
watch)
watch
;;
ngWatch)
ngWatch
;;
test)
test
;;
itTests)
itTests
;;
infra)
infra
;;
publish)
publish
;;
image)
image
;;
*)
echo "Invalid argument : $param"
esac
if [ ! $? -eq 0 ]; then
exit 1
fi
done