Skip to content

Instantly share code, notes, and snippets.

@polbins
Last active October 3, 2018 18:40
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 polbins/9c4e113e9ebb08ed17ee3c2349293109 to your computer and use it in GitHub Desktop.
Save polbins/9c4e113e9ebb08ed17ee3c2349293109 to your computer and use it in GitHub Desktop.
Pre-push to run your lint and tests
#!/bin/bash
# Installation
# ============
# 1. Add this snippet to: `<REPO>/.git/hooks/pre-push`
# 2. Make sure to `chmod a+x <REPO>/.git/hooks/pre-push` to make the code executable
# Check if we actually have commits to push
commits=`git log @{u}..`
if [ -z "$commits" ]; then
echo "no commits to push. aborting check..."
exit 0
fi
LINT_CMD="gradle ktlint" # Command that runs your lint
$LINT_CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "failed lint check '$LINT_CMD'"
exit 1
fi
TEST_CMD="gradle app:testAlphaDebug" # Command that runs your tests
$TEST_CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "failed tests check '$TEST_CMD'"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment