forked from galasa-dev/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-locally.sh
executable file
·650 lines (516 loc) · 20.5 KB
/
build-locally.sh
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
#!/usr/bin/env bash
#
# Copyright contributors to the Galasa project
#
# SPDX-License-Identifier: EPL-2.0
#
# Where is this script executing from ?
BASEDIR=$(dirname "$0");pushd $BASEDIR 2>&1 >> /dev/null ;BASEDIR=$(pwd);popd 2>&1 >> /dev/null
# echo "Running from directory ${BASEDIR}"
export ORIGINAL_DIR=$(pwd)
cd "${BASEDIR}"
#--------------------------------------------------------------------------
#
# Set Colors
#
#--------------------------------------------------------------------------
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 76)
white=$(tput setaf 7)
tan=$(tput setaf 202)
blue=$(tput setaf 25)
#--------------------------------------------------------------------------
#
# Headers and Logging
#
#--------------------------------------------------------------------------
underline() { printf "${underline}${bold}%s${reset}\n" "$@" ;}
h1() { printf "\n${underline}${bold}${blue}%s${reset}\n" "$@" ;}
h2() { printf "\n${underline}${bold}${white}%s${reset}\n" "$@" ;}
debug() { printf "${white}%s${reset}\n" "$@" ;}
info() { printf "${white}➜ %s${reset}\n" "$@" ;}
success() { printf "${green}✔ %s${reset}\n" "$@" ;}
error() { printf "${red}✖ %s${reset}\n" "$@" ;}
warn() { printf "${tan}➜ %s${reset}\n" "$@" ;}
bold() { printf "${bold}%s${reset}\n" "$@" ;}
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@" ;}
#-----------------------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------------------
function usage {
info "Syntax: build-locally.sh [OPTIONS]"
cat << EOF
Options are:
-c | --clean : Do a clean build. One of the --clean or --delta flags are mandatory.
-d | --delta : Do a delta build. One of the --clean or --delta flags are mandatory.
EOF
}
#--------------------------------------------------------------------------
function read_boot_jar_version {
export BOOT_JAR_VERSION=$(cat ${BASEDIR}/build.gradle | grep "galasaBootJarVersion[ ]*=" | cut -f2 -d"'" )
info "Boot jar version is $BOOT_JAR_VERSION"
}
#--------------------------------------------------------------------------
#
# Main script logic
#
#--------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------
# Process parameters
#-----------------------------------------------------------------------------------------
build_type=""
while [ "$1" != "" ]; do
case $1 in
-c | --clean ) build_type="clean"
;;
-d | --delta ) build_type="delta"
;;
-h | --help ) usage
exit
;;
* ) error "Unexpected argument $1"
usage
exit 1
esac
shift
done
if [[ "${build_type}" == "" ]]; then
error "Need to use either the --clean or --delta parameter."
usage
exit 1
fi
#--------------------------------------------------------------------------
h1 "Building the CLI component"
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
h2 "Setting versions of things."
# Could get this bootjar from https://development.galasa.dev/main/maven-repo/obr/dev/galasa/galasa-boot/
read_boot_jar_version
#--------------------------------------------------------------------------
# Create a temporary folder which is never checked in.
function download_dependencies {
h2 "Making sure the tools folder is present."
info "Making sure the boot jar we embed is a fresh one from maven."
rm -fr pkg/embedded/templates/galasahome/lib/*.jar
mkdir -p build/dependencies
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to ensure the tools folder is present. rc=${rc}" ; exit 1 ; fi
success "OK"
#--------------------------------------------------------------------------
# Download the dependencies we define in gradle into a local folder
h2 "Downloading dependencies"
gradle --warning-mode all --info --debug installJarsIntoTemplates
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to run the gradle build to get our dependencies. rc=${rc}" ; exit 1 ; fi
success "OK"
}
#--------------------------------------------------------------------------
function go_mod_tidy {
h2 "Tidying up go.mod..."
if [[ "${build_type}" == "clean" ]]; then
h2 "Tidying go mod file..."
go mod tidy
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to tidy go mod. rc=${rc}" ; exit 1 ; fi
fi
success "OK"
}
#--------------------------------------------------------------------------
# Invoke the generator
function generate_rest_client {
h2 "Generate the openapi client go code..."
# Pick up and use the openapi generator we just downloaded.
# We don't know which version it is (dictated by the gradle build), but as there
# is only one we can just pick the filename up..
# Should end up being something like: ${BASEDIR}/build/dependencies/openapi-generator-cli-6.2.0.jar
export OPENAPI_GENERATOR_CLI_JAR=$(ls ${BASEDIR}/build/dependencies/openapi-generator-cli*)
if [[ "${build_type}" == "clean" ]]; then
h2 "Cleaning the generated code out..."
rm -fr ${BASEDIR}/pkg/galasaapi/*
fi
mkdir -p build
./genapi.sh 2>&1 > build/generate-log.txt
rc=$? ; if [[ "${rc}" != "0" ]]; then cat build/generate-log.txt ; error "Failed to generate the code from the yaml file. rc=${rc}" ; exit 1 ; fi
rm -f build/generate-log.txt
success "Code generation OK"
#--------------------------------------------------------------------------
# Invoke the generator again with different parameters
h2 "Generate the openapi client go code... part II"
./generate.sh 2>&1 > build/generate-log.txt
rc=$? ; if [[ "${rc}" != "0" ]]; then cat build/generate-log.txt ; error "Failed to generate II the code from the yaml file. rc=${rc}" ; exit 1 ; fi
rm -f build/generate-log.txt
success "Code generation part II - OK"
}
#--------------------------------------------------------------------------
#
# Clean out old things if the clean option was specified.
#
#--------------------------------------------------------------------------
function clean {
if [[ "${build_type}" == "clean" ]]; then
h2 "Cleaning the binaries out..."
make clean
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to build binary executable galasactl programs. rc=${rc}" ; exit 1 ; fi
success "Binaries cleaned up - OK"
fi
}
#--------------------------------------------------------------------------
#
# Build the executables
#
#--------------------------------------------------------------------------
function build_executables {
h2 "Building new binaries..."
set -o pipefail # Fail everything if anything in the pipeline fails. Else we are just checking the 'tee' return code.
make all | tee ${BASEDIR}/build/compile-log.txt
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to build binary executable galasactl programs. rc=${rc}. See log at ${BASEDIR}/build/compile-log.txt" ; exit 1 ; fi
success "New binaries built - OK"
}
#--------------------------------------------------------------------------
#
# Testing what was built...
#
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
function calculate_galasactl_executable {
h2 "Calculate the name of the galasactl executable for this machine/os"
raw_os=$(uname -s) # eg: "Darwin"
os=""
case $raw_os in
Darwin*)
os="darwin"
;;
Windows*)
os="windows"
;;
Linux*)
os="linux"
;;
*)
error "Failed to recognise which operating system is in use. $raw_os"
exit 1
esac
architecture=$(uname -m)
case $architecture in
aarch64)
architecture="arm64"
;;
esac
export galasactl_command="galasactl-${os}-${architecture}"
info "galasactl command is ${galasactl_command}"
success "OK"
}
#--------------------------------------------------------------------------
# Invoke the galasactl command to create a project.
function generate_sample_code {
h2 "Invoke the tool to create a sample project."
BUILD_SYSTEM_FLAGS=$*
cd $BASEDIR/temp
export PACKAGE_NAME="dev.galasa.example.banking"
${BASEDIR}/bin/${galasactl_command} project create --development --package ${PACKAGE_NAME} --features payee,account --obr ${BUILD_SYSTEM_FLAGS}
rc=$?
if [[ "${rc}" != "0" ]]; then
error " Failed to create the galasa test project using galasactl command. rc=${rc}"
exit 1
fi
success "OK"
}
#--------------------------------------------------------------------------
# Now build the source it created using maven
function build_generated_source_maven {
h2 "Building the sample project we just generated."
cd ${BASEDIR}/temp/${PACKAGE_NAME}
mvn clean test install
rc=$?
if [[ "${rc}" != "0" ]]; then
error " Failed to build the generated source code which galasactl created."
exit 1
fi
success "OK"
}
#--------------------------------------------------------------------------
# Now build the source it created using gradle
function build_generated_source_gradle {
h2 "Building the sample project we just generated."
cd ${BASEDIR}/temp/${PACKAGE_NAME}
gradle build publishToMavenLocal
rc=$?
if [[ "${rc}" != "0" ]]; then
error " Failed to build the generated source code which galasactl created."
exit 1
fi
success "OK"
}
#--------------------------------------------------------------------------
# Build a portfolio
function build_portfolio {
h2 "Building a portfolio file"
cd ${BASEDIR}/temp
cmd="${BASEDIR}/bin/${galasactl_command} runs prepare \
--portfolio my.portfolio \
--bootstrap file://${GALASA_HOME}/bootstrap.properties \
--class dev.galasa.example.banking.account/dev.galasa.example.banking.account.TestAccountExtended \
--class dev.galasa.example.banking.account/dev.galasa.example.banking.account.TestAccount \
--log ${BASEDIR}/temp/portfolio-create-log.txt"
info "Command is: $cmd"
$cmd
rc=$?
if [[ "${rc}" != "0" ]]; then
error "Failed to build a portfolio file"
exit 1
fi
success "Built portfolio OK"
}
#--------------------------------------------------------------------------
# Initialise Galasa home
function galasa_home_init {
h2 "Initialising galasa home directory"
cd ${BASEDIR}/temp
cmd="${BASEDIR}/bin/${galasactl_command} local init \
--log -"
info "Command is: $cmd"
$cmd
rc=$?
if [[ "${rc}" != "0" ]]; then
error "Failed to initialise galasa home"
exit 1
fi
success "Galasa home initialised"
}
#--------------------------------------------------------------------------
function launch_test_on_ecosystem {
h2 "Launching test on an ecosystem..."
if [[ "${GALASA_BOOTSTRAP}" == "" ]]; then
error "GALASA_BOOTSTRAP environment variable is not set. It should refer to a remote ecosystem"
exit 1
fi
# hostname=$(echo -n "${GALASA_BOOTSTRAP}" | sed -e "s/http:\/\///g" | sed -e "s/https:\/\///g" | sed -e "s/.bootstrap//g")
# info "Host name for boostrap is ${hostname}"
cd ${BASEDIR}/temp
cmd="${BASEDIR}/bin/${galasactl_command} runs submit \
--bootstrap $GALASA_BOOTSTRAP \
--class dev.galasa.example.banking.account/dev.galasa.example.banking.account.TestAccountExtended \
--log -"
info "Command is: $cmd"
$cmd
rc=$?
# We expect a return code of '2' because the ecosystem doesn't know about this testcase.
if [[ "${rc}" != "2" ]]; then
error "Failed to submit a test to a remote ecosystem, and get Unknown back."
exit 1
fi
success "Submitting test to ecosystem worked OK"
}
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# Return to the top folder so we can do other things.
cd ${BASEDIR}
#--------------------------------------------------------------------------
# Initialise Galasa home
function galasa_home_init {
h2 "Initialising galasa home directory"
cd ${BASEDIR}/temp
export GALASA_HOME=${BASEDIR}/temp/home
cmd="${BASEDIR}/bin/${galasactl_command} local init \
--log -"
info "Command is: $cmd"
$cmd
rc=$?
if [[ "${rc}" != "0" ]]; then
error "Failed to initialise galasa home"
exit 1
fi
success "Galasa home initialised"
}
#--------------------------------------------------------------------------
function launch_test_on_ecosystem {
h2 "Launching test on an ecosystem..."
if [[ "${GALASA_BOOTSTRAP}" == "" ]]; then
error "GALASA_BOOTSTRAP environment variable is not set. It should refer to a remote ecosystem"
exit 1
fi
rm -fr ~/.galasa-old
mv ~/.galasa ~/.galasa-old
# hostname=$(echo -n "${GALASA_BOOTSTRAP}" | sed -e "s/http:\/\///g" | sed -e "s/https:\/\///g" | sed -e "s/.bootstrap//g")
# info "Host name for boostrap is ${hostname}"
cd ${BASEDIR}/temp
cmd="${BASEDIR}/bin/${galasactl_command} runs submit \
--bootstrap $GALASA_BOOTSTRAP \
--class dev.galasa.example.banking.account/dev.galasa.example.banking.account.TestAccount \
--log -"
info "Command is: $cmd"
$cmd
rc=$?
# We expect a return code of '2' because the ecosystem doesn't know about this testcase.
if [[ "${rc}" != "2" ]]; then
error "Failed to submit a test to a remote ecosystem, and get Unknown back."
exit 1
fi
success "Submitting test to ecosystem worked OK"
mv ~/.galasa-old ~/.galasa
}
#--------------------------------------------------------------------------
# Build the documentation
function generate_galasactl_documentation {
generated_docs_folder=${BASEDIR}/docs/generated
h2 "Generating documentation"
info "Documentation will be placed in ${generated_docs_folder}"
mkdir -p ${generated_docs_folder}
# Figure out which type of machine this script is currently running on.
unameOut="$(uname -s)"
case "${unameOut}" in
Linux) machine=linux;;
Darwin) machine=darwin;;
*) error "Unknown machine type ${unameOut}"
exit 1
esac
architecture="$(uname -m)"
case $architecture in
aarch64) architecture=arm64
esac
# Call the documentation generator, which builds .md files
info "Using program ${BASEDIR}/bin/gendocs-galasactl-${machine}-${architecture} to generate the documentation..."
${BASEDIR}/bin/gendocs-galasactl-${machine}-${architecture} ${generated_docs_folder}
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to generate documentation. rc=${rc}" ; exit 1 ; fi
# The files have a line "###### Auto generated by cobra at 17/12/2022"
# As we are (currently) checking-in these .md files, we don't want them to show as
# changed in git (which compares the content, not timestamps).
# So lets remove these lines from all the .md files.
info "Removing lines with date/time in, to limit delta changes in git..."
mkdir -p ${BASEDIR}/build
temp_file="${BASEDIR}/build/temp.md"
for FILE in ${generated_docs_folder}/*; do
mv -f ${FILE} ${temp_file}
cat ${temp_file} | grep -v "###### Auto generated by" > ${FILE}
rm ${temp_file}
success "Processed file ${FILE}"
done
success "Documentation generated - OK"
}
#--------------------------------------------------------------------------
# Run test using the galasactl locally in a JVM
function submit_local_test {
h2 "Submitting a local test using galasactl in a local JVM"
cd ${BASEDIR}/temp/*banking
BUNDLE=$1
JAVA_CLASS=$2
OBR_GROUP_ID=$3
OBR_ARTIFACT_ID=$4
OBR_VERSION=$5
LOG_FILE=$6
# Could get this bootjar from https://development.galasa.dev/main/maven-repo/obr/dev/galasa/galasa-boot/
read_boot_jar_version
export GALASA_VERSION=$(cat ${BASEDIR}/VERSION )
export M2_PATH=$(cd ~/.m2 ; pwd)
export BOOT_JAR_PATH=${GALASA_HOME}/lib/${GALASA_VERSION}/galasa-boot-${BOOT_JAR_VERSION}.jar
# Local .m2 content over-rides these anyway...
# use development version of the OBR
export REMOTE_MAVEN=https://development.galasa.dev/main/maven-repo/obr/
# else go to maven central
#export REMOTE_MAVEN=https://repo.maven.apache.org/maven2
unset GALASA_BOOTSTRAP
cmd="${BASEDIR}/bin/${galasactl_command} runs submit local \
--obr mvn:${OBR_GROUP_ID}/${OBR_ARTIFACT_ID}/${OBR_VERSION}/obr \
--class ${BUNDLE}/${JAVA_CLASS} \
--remoteMaven ${REMOTE_MAVEN} \
--throttle 1 \
--requesttype MikeCLI \
--poll 10 \
--progress 1 \
--log ${LOG_FILE}"
# --reportjson myreport.json \
# --reportyaml myreport.yaml \
# --noexitcodeontestfailures \
# --galasaVersion 0.26.0 \
info "Command is ${cmd}"
$cmd
rc=$?
if [[ "${rc}" != "0" ]]; then
error "Failed to run the test. See details in log file ${LOG_FILE}"
exit 1
fi
success "Test ran OK"
}
function check_artifact_saved_in_ras {
# The extended type of test saves an artifact into the RAS store
# The artifact has "Hello Galasa !" inside.
# Lets check the RAS to make sure that file is present.
expected_string_in_test_artifact="Hello Galasa \!"
grep -R "$expected_string_in_test_artifact" $GALASA_HOME/ras > /dev/null
rc=$?
if [[ "${rc}" != "0" ]]; then
error "Failed to find the string \'$expected_string_in_test_artifact\" in RAS. Test case should have generated it."
exit 1
fi
success "Confirmed that test case saved a test artifact to RAS"
}
function run_test_locally_using_galasactl {
export LOG_FILE=$1
# Run the Payee tests.
export TEST_BUNDLE=dev.galasa.example.banking.payee
export TEST_JAVA_CLASS=dev.galasa.example.banking.payee.TestPayeeExtended
export TEST_OBR_GROUP_ID=dev.galasa.example.banking
export TEST_OBR_ARTIFACT_ID=dev.galasa.example.banking.obr
export TEST_OBR_VERSION=0.0.1-SNAPSHOT
submit_local_test $TEST_BUNDLE $TEST_JAVA_CLASS $TEST_OBR_GROUP_ID $TEST_OBR_ARTIFACT_ID $TEST_OBR_VERSION $LOG_FILE
check_artifact_saved_in_ras
}
function test_on_windows {
WINDOWS_HOST="cics-galasa-test"
scp ${BASEDIR}/bin/galasactl-windows-x86_64.exe ${WINDOWS_HOST}:galasactl.exe
ssh ${WINDOWS_HOST} ./galasactl.exe runs submit local --obr mvn:dev.galasa.example.banking/dev.galasa.example.banking.obr/0.0.1-SNAPSHOT/obr --class dev.galasa.example.banking.account/dev.galasa.example.banking.account.TestAccount --log -
}
function cleanup_local_maven_repo {
rm -fr ~/.m2/repository/dev/galasa/example
}
function cleanup_temp {
rm -fr ${BASEDIR}/temp
mkdir -p ${BASEDIR}/temp
cd ${BASEDIR}/temp
}
# The steps to build the CLI
clean
download_dependencies
generate_rest_client
go_mod_tidy
build_executables
# Now the steps to test it.
h2 "Setting up GALASA_HOME"
export GALASA_HOME=${BASEDIR}/temp/home
success "GALASA_HOME is set to be ${GALASA_HOME}"
cleanup_temp
calculate_galasactl_executable
galasa_home_init
# Local environments don't support the portfolio yet.
# build_portfolio
generate_galasactl_documentation
# Gradle ...
cleanup_temp
galasa_home_init
generate_sample_code --gradle
cleanup_local_maven_repo
build_generated_source_gradle
run_test_locally_using_galasactl ${BASEDIR}/temp/local-run-log-gradle.txt
# Maven ...
cleanup_temp
galasa_home_init
generate_sample_code --maven
cleanup_local_maven_repo
build_generated_source_maven
run_test_locally_using_galasactl ${BASEDIR}/temp/local-run-log-maven.txt
# Both Gradle and Maven ...
cleanup_temp
galasa_home_init
generate_sample_code --maven --gradle
cleanup_local_maven_repo
build_generated_source_maven
run_test_locally_using_galasactl ${BASEDIR}/temp/local-run-log-maven.txt
cleanup_local_maven_repo
build_generated_source_gradle
run_test_locally_using_galasactl ${BASEDIR}/temp/local-run-log-gradle.txt
# launch_test_on_ecosystem
# test_on_windows
#--------------------------------------------------------------------------
h2 "Use the results.."
info "Binary executable programs are found in the 'bin' folder."
ls ${BASEDIR}/bin | grep -v "gendocs"