diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0cfbfda2d1..6e6e2910b6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,6 +27,9 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- + - name: Linter (gradle) + run: ./gradlew ktlintCheck + - name: Test (gradle) run: ./gradlew test --no-daemon diff --git a/README.md b/README.md index 233343f0d8..76b8e74433 100644 --- a/README.md +++ b/README.md @@ -97,11 +97,25 @@ Build the app: ./gradlew connectedAndroidTest ``` +## Linting +```bash +./gradlew ktlintCheck +./gradlew ktlintFormat +``` + ## Installing on device ```bash ./gradlew installDebug ``` +## Git Hooks + +You can add the git hook running the following bash script: + +```bash +./tools/git-hooks/init.sh +``` + ## How to Deploy 1. Generate a new signing key diff --git a/app/build.gradle b/app/build.gradle index a0a49dda44..32ab8260ab 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -167,3 +167,7 @@ dependencies { debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version" debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version" } + +ktlint { + disabledRules.set(["no-wildcard-imports"]) +} diff --git a/build.gradle b/build.gradle index 2e35222a9c..6c6032c6ad 100644 --- a/build.gradle +++ b/build.gradle @@ -13,4 +13,11 @@ plugins { id 'com.android.library' version '7.4.1' apply false id 'org.jetbrains.kotlin.android' version '1.8.10' apply false id 'org.jetbrains.kotlin.jvm' version '1.8.10' apply false -} \ No newline at end of file +} + +task installGitHook(type: Copy) { + from new File(rootProject.rootDir, 'pre-commit') + into { new File(rootProject.rootDir, '.git/hooks') } + fileMode 0777 +} +tasks.getByPath(':app:preBuild').dependsOn installGitHook \ No newline at end of file diff --git a/pre-commit b/pre-commit new file mode 100755 index 0000000000..c913761ba4 --- /dev/null +++ b/pre-commit @@ -0,0 +1,23 @@ +#!/bin/bash + +GREEN='\033[0;32m' +NO_COLOR='\033[0m' + +echo "*********************************************************" +echo "Running git pre-commit hook. Running Static analysis... " +echo "*********************************************************" + +./gradlew ktlintCheck + +status=$? + +if [ "$status" = 0 ] ; then + echo "Static analysis found no problems." + exit 0 +else + echo "*********************************************************" + echo 1>&2 "Static analysis found violations it could not fix." + printf "Run ${GREEN}./gradlew ktlintFormat${NO_COLOR} to fix formatting related issues...\n" + echo "*********************************************************" + exit 1 +fi