From ce70dd26be13f05782d542ac5c63ac1e19f3f246 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Wed, 8 Mar 2023 19:17:04 +0000 Subject: [PATCH] Add pre-push git hook to run tests --- build.gradle | 3 ++- pre-commit => git-hooks/pre-commit | 0 git-hooks/pre-push | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) rename pre-commit => git-hooks/pre-commit (100%) create mode 100755 git-hooks/pre-push diff --git a/build.gradle b/build.gradle index 6c6032c6..526aca84 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,8 @@ plugins { } task installGitHook(type: Copy) { - from new File(rootProject.rootDir, 'pre-commit') + from new File(rootProject.rootDir, 'git-hooks/pre-commit') + from new File(rootProject.rootDir, 'git-hooks/pre-push') into { new File(rootProject.rootDir, '.git/hooks') } fileMode 0777 } diff --git a/pre-commit b/git-hooks/pre-commit similarity index 100% rename from pre-commit rename to git-hooks/pre-commit diff --git a/git-hooks/pre-push b/git-hooks/pre-push new file mode 100755 index 00000000..19c523c3 --- /dev/null +++ b/git-hooks/pre-push @@ -0,0 +1,23 @@ +#!/bin/bash + +GREEN='\033[0;32m' +NO_COLOR='\033[0m' + +echo "*********************************************************" +echo "Running git pre-push hook. Running test... " +echo "*********************************************************" + +./gradlew test + +status=$? + +if [ "$status" = 0 ] ; then + echo "All test passed." + exit 0 +else + echo "*********************************************************" + echo 1>&2 "Failing test" + printf "Run ${GREEN}./gradlew test${NO_COLOR} to make sure you have all tests green before pushing...\n" + echo "*********************************************************" + exit 1 +fi