Skip to content

Instantly share code, notes, and snippets.

@hontas hontas/pre-push

Created Dec 1, 2017
Embed
What would you like to do?
pre-push hook linting changed files and running test + checkstyle
#!/usr/bin/env bash
printf "<pre-push>\n";
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" = "master" ]]; then
cd frontend;
FRONTEND_DIFF=`git diff-index --name-only --relative origin/master`;
if [ "$FRONTEND_DIFF" ];
then
printf "Frontend files changed: \n$FRONTEND_DIFF\n";
printf "************* ESLINT *************\n"
node_modules/.bin/eslint $FRONTEND_DIFF;
printf "************* MOCHA TESTS *************\n"
node_modules/.bin/mocha "src/{comhem/test/**/*.*,**/*.spec.*}" --reporter progress
else
printf 'No frontend changes\n';
fi;
cd ..
JAVA_DIFF=`git diff-index --name-only --relative origin/master | grep .java | sed 's/.*\/java/**/g' | tr '\n' ',' | sed 's/,$//'`
if [ "$JAVA_DIFF" ];
then
printf "Java files changed\n$JAVA_DIFF\n"
printf "************* CHECKSTYLE *************\n"
mvn checkstyle:check -f src/pom.xml -Dcheckstyle.includes="$JAVA_DIFF" -q
else
printf "No java changes\n";
fi;
fi;
printf "</pre-push>\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.