Skip to content

Instantly share code, notes, and snippets.

@hontas
Created December 1, 2017 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hontas/c2cb5bbab474a4e04ec9bcc146cef7d8 to your computer and use it in GitHub Desktop.
Save hontas/c2cb5bbab474a4e04ec9bcc146cef7d8 to your computer and use it in GitHub Desktop.
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