-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathneo4j
executable file
·803 lines (696 loc) · 26.4 KB
/
neo4j
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
#!/usr/bin/env bash
function _export_global_variables() {
export ROOT_DIR
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
export MANIFEST_PATH="$ROOT_DIR"/src/main/resources/manifest.txt
export PROJECT_URL=https://github.com/ICIJ/datashare-extension-neo4j
export DOCKER_HOME=/home/dev
export PYTHON_APP_DIR="$ROOT_DIR/neo4j-app"
export NEO4J_APP_BIN="neo4j-app"
export ELASTICSEARCH_VERSION=7.17.9
DOCKER_UID="$(id -u)"
export DOCKER_UID
DOCKER_GID="$(id -g)"
export DOCKER_GID
export ELASTICSEARCH_PORT=9201
export NEO4J_VERSION=4.4.29
export TEST_APP_PORT=8002
BIN_ARCHI="$(arch)"
if [ "$BIN_ARCHI" == "x86_64" ] || [ "$BIN_ARCHI" == "i386" ] || [ "$BIN_ARCHI" == "amd64" ]; then
# Renormalize the BIN_ARCHI name
BIN_ARCHI="x86_64"
export DOCKER_PLATFORM="linux/amd64"
export NEO4J_IMAGE="neo4j"
elif [ "$BIN_ARCHI" == "aarch64" ] || [ "$BIN_ARCHI" == "arm64" ]; then
# Renormalize the BIN_ARCHI name
BIN_ARCHI="arm64"
export DOCKER_PLATFORM="linux/arm64"
export NEO4J_IMAGE="arm64v8/neo4j"
else
_exit_with_message "Unsupported architecture $BIN_ARCHI"
fi
export BIN_ARCHI
PLATFORM=$(uname)
export PLATFORM
if [ "$PLATFORM" == "Darwin" ]; then
export BIN_PLATFORM="darwin-universal2"
elif [ "$PLATFORM" == "Linux" ]; then
export BIN_PLATFORM="unknown-linux-$BIN_ARCHI"
else
_exit_with_message "Unsupported platform $PLATFORM"
fi
}
function _helpers() {
function _array_contains() {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
function _build_neo4j_app() {
cd "$ROOT_DIR"/neo4j-app
local groups=
if [[ -n "$OPENSEARCH_SUPPORT" ]]; then
groups=" --with opensearch"
fi
poetry install"$groups"
_poetry_shell
command -v pyinstaller 1>/dev/null 2>&1 || python3 -m pip install pyinstaller==6.3.0
local app_dir
app_dir="$ROOT_DIR"/bins
local site_packages_path
site_packages_path=$(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
local app_bin
app_bin=$(_make_neoj_binary_name)
# TODO: provide hook rather than hidden imports here
PYTHONHASHSEED=42 PYTHONOPTIMIZE=1 pyinstaller neo4j_app/run/run.py \
--distpath "$app_dir" \
-F \
-y \
--name "$app_bin" \
--specpath "$app_dir" \
--add-data "$app_dir"/../neo4j-app/neo4j_app/scripts/bulk-import.sh:neo4j_app/scripts \
--hidden-import neo4j_app.tasks \
--hidden-import gunicorn.glogging \
-p neo4j_app \
-p "$site_packages_path"
echo "Successfully built bins/$app_bin"
chmod +x "$app_dir/$app_bin"
cd "$ROOT_DIR"
}
function _build_neo4j_graph_widget_plugin() {
cd "$ROOT_DIR"/plugins/neo4j-graph-widget
yarn build
local tar_filename
tar_filename=$(yarn -s build:pack)
cp "$tar_filename" "$ROOT_DIR/bins"
cd "$ROOT_DIR/bins"
_unpack_npm_package "$tar_filename"
}
function _check_release_version() {
# TODO: add flags.... per projects
local file_version
file_version=$(head -n 1 "$ROOT_DIR"/version)
if [[ $(git tag -l "$file_version") ]]; then
_exit_with_message "Tag $file_version already exists. Bump the release version using ./neo4j set_version"
fi
# Source version
local source_version
source_version=$("$ROOT_DIR"/neo4j --version)
if ! [ "$source_version" = "$file_version" ]; then _exit_with_message "Source version \"$source_version\" differs from \"$file_version\""; fi
if _should_run_project "neo4j_extension"; then
local java_version
java_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
if ! [ "$java_version" = "$file_version" ]; then _exit_with_message "Java version \"$java_version\" differs from \"$file_version\""; fi
fi
if _should_run_project "neo4j_app"; then
cd "$ROOT_DIR"/neo4j-app
local python_version
python_version=$(poetry version -s)
if ! [ "$python_version" = "$file_version" ]; then _exit_with_message "Python version \"$python_version\" differs from \"$file_version\""; fi
fi
if _should_run_project "neo4j_graph_widget_plugin"; then
cd "$ROOT_DIR"/plugins/neo4j-graph-widget
local npm_version
npm_version=$(jq -r '.version' package.json)
if ! [ "$npm_version" = "$file_version" ]; then _exit_with_message "Dump plugin version \"$npm_version\" differs from \"$file_version\""; fi
fi
cd "$ROOT_DIR"
echo "All versions match !"
}
function _docker_build() {
local target
target=$1
DOCKER_BUILDKIT=1 docker build --progress=plain \
--target "$target" \
-t "$target":latest \
"${@:2}" \
.
}
function _docker_run() {
docker run --mount type=bind,source="$ROOT_DIR"/.data/.cache,target="$DOCKER_HOME"/.cache \
--mount type=bind,source="$ROOT_DIR"/.data/.m2,target="$DOCKER_HOME"/.m2 \
--network="host" "${@}"
}
function _frontend_checks() {
command -v npm 1>/dev/null 2>&1 || _exit_with_message "NPM is not installed"
command -v yarn 1>/dev/null 2>&1 || _exit_with_message "yarn is not installed"
}
function _get_release_upload_url() {
local version
version=$1
upload_url=$(
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/ICIJ/datashare-extension-neo4j/releases | jq --arg jq_version "$version" 'map(select(.tag_name == $jq_version))[0].upload_url // empty'
)
if [[ -z $upload_url ]]; then
if [[ -n $CREATE_RELEASE ]]; then
upload_url=$(
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/ICIJ/datashare-extension-neo4j/releases \
-d "{\"tag_name\":\"$version\",\"name\":\"$version\",\"draft\":true,\"generate_release_notes\":true}" | jq ".upload_url"
)
else
_exit_with_message "Release $version do not exist, please create it"
fi
fi
upload_url=$(echo "${upload_url%\{*}" | tr -d '"')
echo "$upload_url"
}
function _install_black() (
_pip_install black==24.2.0
)
function _join_by {
local d=${1-} f=${2-}
if shift 2; then
printf %s "$f" "${@/#/$d}"
fi
}
function _make_neoj_binary_name() {
echo "$NEO4J_APP_BIN-$BIN_PLATFORM-$(_print_version)"
}
function _make_neo4j_extension_jar_name() {
echo "datashare-extension-neo4j-$(_print_version)-jar-with-dependencies.jar"
}
function _make_neo4j_graph_widget_binary_name() {
echo "datashare-plugin-neo4j-graph-widget-$(_print_version)"
}
function _pip_install() (
# TODO: we might alreading by insider poetry
poetry run python3 -m pip install "$@"
)
function _poetry_shell() {
command -v poetry 1>/dev/null 2>&1 || _exit_with_message "Poetry is not installed"
local venv_path
venv_path=$(poetry env info -p)
. "$venv_path"/bin/activate
}
function _print_step() {
printf "\n##### -> %s\n" "$1"
}
function _print_version() (
cat "$ROOT_DIR"/version
)
function _publish_neo4j_app() {
local version
version=$(_print_version)
_run_manifest_checksums "$MANIFEST_PATH" "$version"
local upload_url
upload_url=$(_get_release_upload_url "$version")
sed -nr "s@.*(bins/$NEO4J_APP_BIN-.+-$version)\$@\1@p" "$MANIFEST_PATH" | while read -r binary; do
local package_name
package_name=$(basename -- "$binary")
local url
url="$upload_url?name=$package_name"
echo "Uploading $binary to $url"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$url" \
--data-binary "@$binary"
done
}
function _publish_neo4j_extension() {
local version
version=$(_print_version)
local upload_url
upload_url=$(_get_release_upload_url "$version")
local jar_path
jar_path="$ROOT_DIR/target/datashare-extension-neo4j-$version-jar-with-dependencies.jar"
package_name=$(basename -- "$jar_path")
local url
url="$upload_url?name=$package_name"
echo "Uploading $jar_path to $url"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$url" \
--data-binary "@$jar_path"
}
function _publish_neo4j_graph_widget_plugin() {
local version
version=$(_print_version)
local tar_path
tar_path="$ROOT_DIR/bins/datashare-plugin-neo4j-graph-widget-$version.tgz"
local zip_path
zip_path="$ROOT_DIR/bins/datashare-plugin-neo4j-graph-widget-$version.zip"
# Create the zip distribution
cat "$tar_path" | zip > "$zip_path"
local tar_filename
local zip_filename
tar_filename=$(basename -- "$tar_path")
zip_filename=$(basename -- "$zip_path")
local upload_url
upload_url=$(_get_release_upload_url "$version")
local tar_url
tar_url="$upload_url?name=$tar_filename"
echo "Uploading $tar_path to $tar_url"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$tar_url" \
--data-binary "@$tar_path"
local zip_url
zip_url="$upload_url?name=$zip_filename"
echo "Uploading $zip_path to $zip_url"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$zip_url" \
--data-binary "@$zip_path"
}
function _pytest() {
poetry run python3 -m pytest -vvv --cache-clear --show-capture=all -r A "${@}"
}
function _run_manifest_checksums() {
local manifest_path
manifest_path=$1
local version
version=$2
if [ -z "$manifest_path" ]; then exit_with_message "Can't update manifest without manifest_path !"; fi
if cat "$manifest_path" | grep "$version$" | shasum -a 256 -c; then return 0; else return 1; fi
}
function _should_run_project() {
if [ "$PROJECT" = ALL ] || [ "$PROJECT" = "$1" ]; then
return 0
else
return 1
fi
}
function _unpack_npm_package() {
local tar_path
tar_path=$1
local package_name
package_name=$(basename -- "$tar_path")
package_name="${package_name%.*}"
local transform
if [ "$PLATFORM" == "Darwin" ]; then
transform="-s,package/,$package_name/,g"
elif [ "$PLATFORM" == "Linux" ]; then
transform="--transform=s,package/,$package_name/,"
else
_exit_with_message "Unknown platform $PLATFORM"
fi
tar "$transform" -xvzf "$tar_path"
# Repackage to a tar.gz where package is replaced with the package name
tar -cvzf "$tar_path" "$package_name"
}
function _update_manifest() {
local manifest_path
manifest_path=$1
if [ -z "$manifest_path" ]; then exit_with_message "Can't update manifest without manifest_path !"; fi
local bin_path
bin_path=$2
if [ -z "$bin_path" ]; then exit_with_message "Can't update manifest with an empty asset name !"; fi
local manifest_path
shasum -a 256 "$bin_path" >>"$manifest_path"
}
}
function _commands() {
function binary_name() {
if _should_run_project "neo4j_app"; then
_make_neoj_binary_name
else
_exit_with_message "No binary available for $PROJECT"
fi
}
function build() {
if _should_run_project "neo4j_app"; then
if [ -z "$PRINT_SHA" ]; then _print_step "Building Python app executable"; fi
_build_neo4j_app
if [ -n "$PRINT_SHA" ]; then
# TODO: to avoid this, we could redirect logs from _build_neo4j_app to stderr and echo the bin path
# to stdout
local bin_path
bin_path="bins/$(_make_neoj_binary_name)"
shasum -a 256 "$bin_path"
fi
elif _should_run_project "neo4j_extension"; then
_print_step "Compiling the java extension"
cd "$ROOT_DIR"
mvn validate package -Dmaven.test.skip=true
local jar
jar="$ROOT_DIR"/target/$(_make_neo4j_extension_jar_name)
chmod +x "$jar"
cp "$jar" "$ROOT_DIR/bins"
elif _should_run_project "neo4j_graph_widget_plugin"; then
_print_step "Compiling the graph widget plugin"
_build_neo4j_graph_widget_plugin
else
_exit_with_message "Can't build project $PROJECT"
fi
}
function docker_build() {
if _should_run_project "base"; then
_print_step "Building base docker image..."
_docker_build base
elif _should_run_project "neo4j_extension"; then
_print_step "Building neo4j extension jar..."
_docker_build base-java
mkdir -p "$ROOT_DIR"/target
_docker_run --mount type=bind,source="$ROOT_DIR"/target,target="$DOCKER_HOME"/target \
base-java:latest \
./neo4j build -p neo4j_extension
else
_exit_with_message "Can't docker build project $PROJECT"
fi
}
function docker_build_test_services() {
_print_step "Building test services images..."
_docker_build neo4j
_docker_build elasticsearch
}
function docker_test() {
if _should_run_project "neo4j_app"; then
_docker_build base-python
_docker_run base-python:latest ./neo4j setup -p neo4j_app
_docker_run --mount type=bind,source="$ROOT_DIR"/.data/neo4j,target="$DOCKER_HOME"/.data/neo4j \
base-python:latest \
./neo4j test -p neo4j_app
elif _should_run_project "neo4j_app_format"; then
_docker_build base-python
_docker_run base-python:latest ./neo4j setup -p neo4j_app
_docker_run base-python:latest ./neo4j format_test_python
elif _should_run_project "neo4j_extension"; then
_docker_build base-java
_docker_run base-java:latest ./neo4j test -p neo4j_extension
elif _should_run_project "neo4j_extension_format"; then
_docker_build base-java
# TODO: mount the target dir to do some maven caching ?
_docker_run base-java:latest ./neo4j format_test_java
elif _should_run_project "neo4j_script"; then
_docker_build base-script
_docker_run base-script:latest ./neo4j test -p neo4j_script
elif _should_run_project "release_version"; then
_docker_build base-script
_docker_run base-script:latest ./neo4j test -p release_version
else
_exit_with_message "Can't test project $PROJECT"
fi
}
function format() {
format_python
}
function format_python() {
# Black
cd "$PYTHON_APP_DIR"
_install_black
black --config pyproject.toml .
}
function format_test() {
format_test_python
format_test_java
}
function format_test_java() {
_print_step "Testing java formatting..."
cd "$ROOT_DIR"
mvn validate
if ! mvn checkstyle:check; then
_exit_with_message "Java source code does not comply with style guidelines.
Please check the README.md to see how to automatically format the code and fix"
fi
}
function format_test_python() {
_print_step "Testing python formatting..."
cd "$PYTHON_APP_DIR"
_install_black
if ! poetry run python3 -m black --config pyproject.toml --check .; then
_exit_with_message "Python project is not properly formatted.
Please run ./neo4j format"
fi
echo "Python format test succeeded !"
}
function install_poetry() (
local poetry_home
poetry_home=$1
if [ -z "$poetry_home" ]; then _exit_with_message "Missing poetry_home !"; fi
local python_version
python_version=$2
if [ -z "$python_version" ]; then _exit_with_message "Missing python_version !"; fi
echo "Installing Poetry to $poetry_home..."
curl -sSL https://install.python-poetry.org | POETRY_HOME=$poetry_home $python_version -
export PATH="$poetry_home/bin:$PATH"
)
function is_publishable() {
_check_release_version
}
function publish() {
if _should_run_project "neo4j_app"; then
_publish_neo4j_app
elif _should_run_project "neo4j_extension"; then
_publish_neo4j_extension
elif _should_run_project "neo4j_graph_widget_plugin"; then
_publish_neo4j_graph_widget_plugin
else
_exit_with_message "Can't pre-publish project $PROJECT"
fi
}
function run() {
if _should_run_project "neo4j_app"; then
# TODO: maybe we should run the binary we've copied to the java dir
"$ROOT_DIR/bins/$(_make_neoj_binary_name)"
else
_exit_with_message "Can't run project $PROJECT"
fi
}
function run_datashare() {
local template_path
template_path="$ROOT_DIR"/.data/datashare.properties.template
local settings_path
settings_path="$ROOT_DIR"/.data/datashare.properties
if [ -n "$DEV_FLAG" ]; then
local local_extension_path
local_extension_path="$ROOT_DIR/bins/$(_make_neoj_binary_name)"
sed -r "s@^neo4jStartServerCmd=.*\$@neo4jStartServerCmd=$local_extension_path --config-path $settings_path@" \
"$template_path" >"$settings_path"
else
cp "$template_path" "$settings_path"
fi
local ds_data_dir
ds_data_dir=""
if [[ -n $DS_DOCKER_DATA_DIR ]]; then
ds_data_dir=" --dataDir $DS_DOCKER_DATA_DIR"
fi
datashare -m LOCAL -s "$settings_path" "$ds_data_dir" --pluginsDir="$ROOT_DIR"/bins --extensionsDir="$ROOT_DIR"/bins
}
function set_version() {
# Update root file
local file_version
file_version=$1
if [ -z "$file_version" ]; then _exit_with_message "Empty version !"; fi
echo "$file_version" >"$ROOT_DIR"/version
cd "$PYTHON_APP_DIR"
_pip_install tomlkit==0.11.6
poetry run python3 "$ROOT_DIR"/scripts/update_versions.py
}
function setup() {
if _should_run_project "build_env"; then
if [ "$PLATFORM" == "Darwin" ]; then
"$ROOT_DIR"/.circleci/setup/darwin
elif [ "$PLATFORM" == "Linux" ]; then
"$ROOT_DIR"/.circleci/setup/unknown-linux
else
_exit_with_message "Unknown platform $PLATFORM"
fi
elif _should_run_project "neo4j_app"; then
_print_step "Setting up neo4j_app"
command -v poetry 1>/dev/null 2>&1 || echo "poetry is not installed"
cd "$PYTHON_APP_DIR"
poetry install --no-interaction -vvv --with=dev --no-ansi
echo "Python setup succeeded !"
elif _should_run_project "neo4j_graph_widget_plugin"; then
_print_step "Setting up neo4j_graph_widget_plugin"
_frontend_checks
cd "$ROOT_DIR/plugins/neo4j-graph-widget"
yarn install --immutable
else
_exit_with_message "Can't setup project $PROJECT"
fi
}
function start_all_test_services() (
if [[ -z $OLD_ELASTICSEARCH ]]; then
docker compose up --detach \
--wait \
--build \
test-elasticsearch \
test-neo4j
else
docker compose up --detach \
--wait \
--build \
test-old-elasticsearch \
test-neo4j
fi
)
function start_debug_app() (
cd "$ROOT_DIR"/neo4j-app
poetry run uvicorn --factory --reload --port "$TEST_APP_PORT" neo4j_app.run.run:debug_app
)
function start_test_elasticsearch() (
docker compose up --wait --build test-elasticsearch
)
function start_test_neo4j() (
docker compose up --build --wait test-neo4j
)
function stop_all_test_services() (
docker compose stop test-elasticsearch test-neo4j test-old-elasticsearch
)
function stop_test_elasticsearch() (
docker compose stop test-elasticsearch
)
function stop_test_neo4j() (
docker compose stop test-neo4j
)
function test() {
if _should_run_project "neo4j_app"; then
cd "$ROOT_DIR"/neo4j-app
# TODO: parallelize pytest...
# Here we expect the docker test images to be launched either by the user or the CI
_pytest neo4j_app
elif _should_run_project "neo4j_extension"; then
mvn -X test
elif _should_run_project "neo4j_script"; then
for file in "$ROOT_DIR"/scripts/tests/test_*; do
"$file"
done
elif _should_run_project "release_version"; then
_check_release_version
else
_exit_with_message "Can't test project $PROJECT"
fi
}
function update_manifest() {
if _should_run_project "neo4j_app"; then
local args
args=("${@:3}")
local num_args
num_args=${#args[@]}
if [[ $num_args -ne 3 ]]; then _return_with_message "Expected 3 binaries found $num_args"; fi
for binary in "${args[@]}"; do
local manifest_path
manifest_path="$binary"-manifest.txt
shasum -a 256 -c "$manifest_path"
_update_manifest "$MANIFEST_PATH" "$binary"
done
else
_exit_with_message "Can't update manifest for $PROJECT"
fi
}
}
function _main() {
CREATE_RELEASE=
DEV_FLAG=
OLD_ELASTICSEARCH=
OPENSEARCH_SUPPORT=
PRINT_SHA=
PRINT_VERSION=
PROJECT=
PROJECTS=
# Define sub projects here
PROJECTS=(
base
build_env
neo4j_app
neo4j_app_format
neo4j_extension
neo4j_graph_widget_plugin
neo4j_extension_format
neo4j_script
release_version
)
function _exit_with_message() {
echo "$1"
exit "${2:-1}"
}
function _return_with_message() {
echo "$1"
return "${2:-1}"
}
function _parse_project_flag() {
local project
project=$1
if [ -z "$project" ]; then
_exit_with_message "Empty project flag, please provide one !"
elif _array_contains "$project" "${PROJECTS[@]}"; then
PROJECT=$project
else
_exit_with_message "Unknown project \"$project\", available projects: $(_join_by "," "${PROJECTS[@]}")"
fi
}
function _parse_args() {
# Unless specified we run commands for all projects
PROJECT=ALL
if [[ "$#" -ge 2 ]]; then
for i in $(seq 2 $#); do
if [[ -z "${SKIP_NEXT_TYPE_ARG}" ]]; then
j=$((i + 1))
TYPE_ARG="${!i}"
VALUE_ARG="${!j}"
if [[ "$TYPE_ARG" == "-p" ]]; then
_parse_project_flag $VALUE_ARG
SKIP_NEXT_TYPE_ARG=true
elif [[ "$TYPE_ARG" == "--dev" ]]; then
DEV_FLAG=true
elif [[ "$TYPE_ARG" == "--opensearch-support" ]]; then
OPENSEARCH_SUPPORT=true
elif [[ "$TYPE_ARG" == "--old-elasticsearch" ]]; then
OLD_ELASTICSEARCH=true
elif [[ "$TYPE_ARG" == "--create-release" ]]; then
CREATE_RELEASE=true
elif [[ $TYPE_ARG = "--sha" ]]; then
PRINT_SHA=1
elif [[ $TYPE_ARG = "--port" ]]; then
SKIP_NEXT_TYPE_ARG=true
fi
else
unset SKIP_NEXT_TYPE_ARG
fi
done
elif [[ "$#" == 1 ]]; then
if [[ "$1" == "--version" ]]; then
PRINT_VERSION=1
fi
fi
}
set -e
set +o pipefail # This is for CircleCI
# Define helpers and commands
_helpers
_commands
# Parse user command
_parse_args "$@"
# Export variables
_export_global_variables
if [ "${BASH_SOURCE[0]}" -ef "$0" ]; then
if [[ $# == 0 ]]; then
printf "Error: No command specified\n\n" && exit 1
# If we manage to find a command previously declared with _commands, run it
elif [ -n "$PRINT_VERSION" ]; then
_print_version
elif declare -f "$1" >/dev/null; then
"$@"
else
printf "Error: Invalid command %s\n\n" "$1" && exit 1
fi
fi
}
_main "$@"