diff --git a/build.gradle b/build.gradle index 11ce7ff09..fa27ac8ff 100644 --- a/build.gradle +++ b/build.gradle @@ -64,7 +64,14 @@ allprojects { } } +task installGitHook(type: Copy) { + from new File(rootProject.rootDir, 'pre-commit') + into { new File(rootProject.rootDir, '.git/hooks') } + fileMode 0777 +} + task clean(type: Delete) { + dependsOn(installGitHook) delete rootProject.buildDir } diff --git a/pre-commit b/pre-commit new file mode 100644 index 000000000..55708e1dc --- /dev/null +++ b/pre-commit @@ -0,0 +1,20 @@ +#!/bin/bash +echo "Running pre-commit checks..." + +OUTPUT="/tmp/analysis-result" +./gradlew detekt ktlintCheck > ${OUTPUT} +EXIT_CODE=$? +if [ ${EXIT_CODE} -ne 0 ]; then + cat ${OUTPUT} + rm ${OUTPUT} + echo "*********************************************" + echo " Checks Failed! " + echo " Resolve found issues before committing " + echo "*********************************************" + exit ${EXIT_CODE} +else + rm ${OUTPUT} + echo "*********************************************" + echo " Checks Passed Successfully! " + echo "*********************************************" +fi