forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·92 lines (83 loc) · 2.54 KB
/
build.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
#!/usr/bin/env bash
function run_tests {
local rest_args=
local ws_args=
if [ $# -eq 2 ]; then
rest_args="$1"
ws_args="$2"
if [ -z "$rest_args" ]; then
: &
local rest_pid=$!
fi
if [ -z "$ws_args" ]; then
: &
local ws_pid=$!
fi
fi
if [ -z "$rest_pid" && $rest_args != "skip" ]; then
# shellcheck disable=SC2086
node test-commonjs.cjs && node run-tests --js --python-async --php-async $rest_args &
local rest_pid=$!
fi
if [ -z "$ws_pid" && $ws_args != "skip" ]; then
# shellcheck disable=SC2086
node run-tests-ws --js --python-async --php-async $ws_args &
local ws_pid=$!
fi
wait $rest_pid && wait $ws_pid
}
build_and_test_all () {
npm run force-build
npm run test-base
npm run test-base-ws
run_tests
exit
}
### CHECK IF THIS IS A PR ###
if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
echo "not a PR, will build everything"
build_and_test_all
fi
##### DETECT CHANGES #####
diff=$(git diff upstream/master --name-only)
diff=$(echo "$diff" | sed -e "s/^build.sh//") # temporarily remove this script from diff
echo "$diff"
critical_pattern='Client(Trait)?\.php|Exchange\.php|\/test|\/base|^build|static_dependencies|^run-tests|package(-lock)?\.json|ccxt\.ts|__init__.py'
if [[ "$diff" =~ $critical_pattern ]]; then
echo "detected critical change, will build/test everything"
build_and_test_all
fi
echo "detected non-critical change, will build/test specific exchanges"
readarray -t y <<<"$diff"
rest_pattern='ts\/src\/([A-Za-z0-9_-]+).ts' # \w not working for some reason
ws_pattern='ts\/src\/pro\/([A-Za-z0-9_-]+)\.ts'
REST_EXCHANGES=()
WS_EXCHANGES=()
for file in "${y[@]}"; do
if [[ "$file" =~ $rest_pattern ]]; then
modified_exchange="${BASH_REMATCH[1]}"
REST_EXCHANGES+=($modified_exchange)
elif [[ "$file" =~ $ws_pattern ]]; then
modified_exchange="${BASH_REMATCH[1]}"
WS_EXCHANGES+=($modified_exchange)
fi
done
### BUILD SPECIFIC EXCHANGES ###
# npm run pre-transpile
echo "REST_EXCHANGES TO BE TRANSPILED: ${REST_EXCHANGES[@]}"
for exchange in "${REST_EXCHANGES[@]}"; do
node build/transpile.js $exchange --force --child
done
echo "WS_EXCHANGES TO BE TRANSPILED: ${WS_EXCHANGES[@]}"
for exchange in "${WS_EXCHANGES[@]}"; do
node build/transpileWS.js $exchange --force --child
done
npm run post-transpile
### RUN SPECIFIC TESTS ###
if [![${REST_EXCHANGES[@]}] && ![${REST_EXCHANGES[@]}] ]; then
echo "no exchanges to test, exiting"
exit
fi
rest_args=${REST_EXCHANGES[*]} || "skip"
ws_args=${WS_EXCHANGES[*]} || "skip"
run_tests "$rest_args" "$ws_args"