Skip to content

Commit b23274a

Browse files
committed
added precommit hook
1 parent be72e60 commit b23274a

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

scripts/install-hooks.bash

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
GIT_DIR=$(git rev-parse --git-dir)
4+
5+
echo "Installing hooks..."
6+
# this command creates symlink to our pre-commit script
7+
ln -s ../../scripts/pre-commit.bash $GIT_DIR/hooks/pre-commit
8+
echo "Done!

scripts/pre-commit.bash

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# save the file as <git_directory>/.git/hooks/pre-commit
4+
5+
echo "Running Maven clean installl for build errors"
6+
# retrieving current working directory
7+
CWD=`pwd`
8+
MAIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9+
# go to main project dir
10+
cd $MAIN_DIR/../../
11+
# running maven clean install
12+
mvn clean install
13+
if [ $? -ne 0 ]; then
14+
"Error while testing the code"
15+
# go back to current working dir
16+
cd $CWD
17+
exit 1
18+
fi
19+
# go back to current working dir
20+
cd $CWD

scripts/run-tests.bash

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# if any command inside script returns error, exit and return that error
4+
set -e
5+
6+
# magic line to ensure that we're always inside the root of our application,
7+
# no matter from which directory we'll run script
8+
# thanks to it we can just enter `./scripts/run-tests.bash`
9+
cd "${0%/*}/.."
10+
11+
# let's fake failing test for now
12+
echo "Running tests"
13+
echo "............................"
14+
echo "Failed!" && exit 1

0 commit comments

Comments
 (0)