Skip to content

Commit e98b159

Browse files
authored
Add a precommit script (#372)
Add a script to run before the commit to make sure that the correct formatting is applied, the unit tests are successful and the dist is building successfully.
1 parent 12f432c commit e98b159

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

precommit.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
STEP_FORMAT=false
6+
STEP_TEST=false
7+
STEP_BUILD=false
8+
9+
if [[ $# -eq 0 ]] ; then
10+
STEP_FORMAT=true
11+
STEP_TEST=true
12+
STEP_BUILD=true
13+
else
14+
while [[ $# -gt 0 ]]; do
15+
case $1 in
16+
-f)
17+
STEP_FORMAT=true
18+
shift
19+
;;
20+
-t)
21+
STEP_TEST=true
22+
shift
23+
;;
24+
-b)
25+
STEP_BUILD=true
26+
shift
27+
;;
28+
-h)
29+
echo "Command to perform precommit actions."
30+
echo
31+
echo "Usage: precommit.sh [-f] [-t] [-b]"
32+
echo
33+
echo "If no option is specified, then all actions are executed."
34+
echo
35+
echo "Options:"
36+
echo " -f format the files"
37+
echo " -t run unit tests"
38+
echo " -b build the dist"
39+
exit
40+
;;
41+
*)
42+
echo "ERROR: Unknown option '$1'."
43+
exit 1
44+
;;
45+
esac
46+
done
47+
fi
48+
49+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
50+
GRADLE_CMD="$SCRIPT_DIR/gradlew"
51+
52+
if [[ "$STEP_FORMAT" == "true" ]] ; then
53+
"$GRADLE_CMD" spotlessApply
54+
fi
55+
56+
if [[ "$STEP_TEST" == "true" ]] ; then
57+
"$GRADLE_CMD" :dumper:app:test
58+
fi
59+
60+
if [[ "$STEP_BUILD" == "true" ]] ; then
61+
"$GRADLE_CMD" --parallel :dumper:app:installDist
62+
fi

0 commit comments

Comments
 (0)