From f8d6cf8dbae233d52f61af2c190b7793e78ec16d Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Tue, 7 Mar 2023 18:59:52 +0100 Subject: [PATCH 1/3] Add Linting section to README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 233343f0d8..d6fa1f3474 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,12 @@ Build the app: ./gradlew connectedAndroidTest ``` +## Linting +```bash +./gradlew ktlintCheck +./gradlew ktlintFormat +``` + ## Installing on device ```bash ./gradlew installDebug From c4c8c0fbf7e6f69fd93b0c8cce708c15b04b98c0 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Tue, 7 Mar 2023 19:08:11 +0100 Subject: [PATCH 2/3] Adding pre-commit git hook --- README.md | 8 ++++++++ tools/git-hooks/init.sh | 13 +++++++++++++ tools/git-hooks/pre-commit.sh | 23 +++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100755 tools/git-hooks/init.sh create mode 100755 tools/git-hooks/pre-commit.sh diff --git a/README.md b/README.md index d6fa1f3474..76b8e74433 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,14 @@ Build the app: ./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/tools/git-hooks/init.sh b/tools/git-hooks/init.sh new file mode 100755 index 0000000000..b6452533fd --- /dev/null +++ b/tools/git-hooks/init.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e + +function setup_git_hooks() +{ + echo "Initialising git hooks..." + ln -sf "$PWD/tools/git-hooks/pre-commit.sh" "$PWD/.git/hooks/pre-commit" + chmod +x "$PWD/.git/hooks/pre-commit" + echo "Done" +} + +setup_git_hooks \ No newline at end of file diff --git a/tools/git-hooks/pre-commit.sh b/tools/git-hooks/pre-commit.sh new file mode 100755 index 0000000000..c913761ba4 --- /dev/null +++ b/tools/git-hooks/pre-commit.sh @@ -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 From 2d92e1d44491d62005e45adcf3dc1c5a403c386f Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Tue, 7 Mar 2023 19:09:26 +0100 Subject: [PATCH 3/3] Add Linder to build CI --- .github/workflows/build.yml | 3 +++ app/build.gradle | 4 ++++ build.gradle | 9 ++++++++- tools/git-hooks/pre-commit.sh => pre-commit | 0 tools/git-hooks/init.sh | 13 ------------- 5 files changed, 15 insertions(+), 14 deletions(-) rename tools/git-hooks/pre-commit.sh => pre-commit (100%) delete mode 100755 tools/git-hooks/init.sh 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/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/tools/git-hooks/pre-commit.sh b/pre-commit similarity index 100% rename from tools/git-hooks/pre-commit.sh rename to pre-commit diff --git a/tools/git-hooks/init.sh b/tools/git-hooks/init.sh deleted file mode 100755 index b6452533fd..0000000000 --- a/tools/git-hooks/init.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -e - -function setup_git_hooks() -{ - echo "Initialising git hooks..." - ln -sf "$PWD/tools/git-hooks/pre-commit.sh" "$PWD/.git/hooks/pre-commit" - chmod +x "$PWD/.git/hooks/pre-commit" - echo "Done" -} - -setup_git_hooks \ No newline at end of file