Skip to content

Commit 071497f

Browse files
author
Hugo Rialan
committed
Improve hooks
1 parent 9511d7f commit 071497f

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

hooks/dataform_compile.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44
if ! command -v dataform >/dev/null 2>&1; then
55
echo "Dataform is not installed."
66
echo "Trying to install Dataform..."
7-
npm i -g @dataform/cli@latest
8-
echo "Dataform installed successfully."
7+
if npm i -g @dataform/cli@latest; then
8+
echo "Dataform installed successfully."
9+
else
10+
echo "Failed to install Dataform."
11+
exit 1
12+
fi
913
fi
1014

1115
dataform compile
1216

13-
exit 0
17+
if [[ $? -ne 0 ]]; then
18+
exit 1
19+
else
20+
exit 0
21+
fi

hooks/dataform_format.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@
44
if ! command -v dataform >/dev/null 2>&1; then
55
echo "Dataform is not installed."
66
echo "Trying to install Dataform..."
7-
npm i -g @dataform/cli@latest
8-
echo "Dataform installed successfully."
7+
if npm i -g @dataform/cli@latest; then
8+
echo "Dataform installed successfully."
9+
else
10+
echo "Failed to install Dataform."
11+
exit 1
12+
fi
913
fi
1014

11-
# Run Dataform formatting for SQLX files
15+
# Compute hash of all files in the project before and after formatting to detect changes
16+
17+
hash_before_format=$(find . -type f -exec md5sum {} \; | awk '{print $1}' | sort | md5sum | awk '{print $1}')
18+
1219
dataform format
1320

14-
exit 0
21+
hash_after_format=$(find . -type f -exec md5sum {} \; | awk '{print $1}' | sort | md5sum | awk '{print $1}')
22+
23+
if [ "$hash_before_format" != "$hash_after_format" ]; then
24+
exit 1
25+
else
26+
exit 0
27+
fi

0 commit comments

Comments
 (0)