forked from Aiven-Open/klaw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·64 lines (57 loc) · 2.14 KB
/
pre-commit
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
#!/bin/bash
FRONTEND_ROOT="coral"
PROXY_ROOT="coral/proxy"
E2E_ROOT="e2e"
GIT_ROOT=$(git rev-parse --show-toplevel)
STAGED_FILES=$(git diff --staged --name-only)
for file in $STAGED_FILES; do
if echo "$file" | grep -q -e "$E2E_ROOT"; then
CHANGED_FILE_IN_E2E_DIR=true
fi
if echo "$file" | grep -q -e "$FRONTEND_ROOT"; then
CHANGED_FILE_IN_CORAL_DIR=true
if ! echo "$file" | grep -q -e "$PROXY_ROOT"; then
# If a file is found in the coral directory but not in the proxy directory,
# we set CHANGED_FILES_ONLY_IN_PROXY_DIR to true and break the loop
CHANGED_FILES_ONLY_IN_PROXY_DIR=false
break
fi
fi
done
# Execute lint-staged for changes in e2e director
if [ "$CHANGED_FILE_IN_E2E_DIR" = true ]; then
pnpm --prefix="$GIT_ROOT"/"$E2E_ROOT" lint-staged
if [ $? -ne 0 ]; then
echo -e '\n\n🙋 Check "lint-staged" in /e2e failed.'
echo -e ' Canceling the commit process.'
echo -e ' Please fix and try again!\n\n'
exit 1
fi
fi
# Execute lint-staged and tsc jobs regardless of the files' location
if [ "$CHANGED_FILE_IN_CORAL_DIR" = true ]; then
pnpm --prefix="$GIT_ROOT"/"$FRONTEND_ROOT" lint-staged
if [ $? -ne 0 ]; then
echo -e '\n\n🙋 Check "lint-staged" in /coral failed.'
echo -e ' Canceling the commit process.'
echo -e ' Please fix and try again!\n\n'
exit 1
fi
fi
# Execute the test job only if there are files in the "coral" directory that are not in the "coral/proxy" directory
if [ "$CHANGED_FILE_IN_CORAL_DIR" = true ] && [ "$CHANGED_FILES_ONLY_IN_PROXY_DIR" = false ]; then
pnpm --prefix="$GIT_ROOT"/"$FRONTEND_ROOT" tsc
if [ $? -ne 0 ]; then
echo -e '\n\n🙋 Check "tsc" failed.'
echo -e ' Canceling the commit process.'
echo -e ' Please fix and try again!\n\n'
exit 1
fi
pnpm --prefix="$GIT_ROOT"/"$FRONTEND_ROOT" test --bail
if [ $? -ne 0 ]; then
echo -e '\n\n🙋 Check "test" failed.'
echo -e ' Canceling the commit process.'
echo -e ' Please fix and try again!\n\n'
exit 1
fi
fi