diff --git a/.githooks/commit-msg b/.githooks/commit-msg index 24cd55c6b6..48a347456b 100755 --- a/.githooks/commit-msg +++ b/.githooks/commit-msg @@ -6,7 +6,24 @@ # status after issuing an appropriate message if it wants to stop the # commit. The hook is allowed to edit the commit message file. -echo "Running the AppFlowy commit-msg hook." +YELLOW="\e[93m" +GREEN="\e[32m" +RED="\e[31m" +ENDCOLOR="\e[0m" + +printMessage() { + printf "${YELLOW}AppFlowy : $1${ENDCOLOR}\n" +} + +printSuccess() { + printf "${GREEN}AppFlowy : $1${ENDCOLOR}\n" +} + +printError() { + printf "${RED}AppFlowy : $1${ENDCOLOR}\n" +} + +printMessage "Running the AppFlowy commit-msg hook." # This example catches duplicate Signed-off-by lines. @@ -16,11 +33,19 @@ test "" = "$(grep '^Signed-off-by: ' "$1" | exit 1 } -npx --no -- commitlint --edit $1 +.githooks/gitlint \ + --msg-file=$1 \ + --subject-regex="^(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|test)(.*)?:\s?.*" \ + --subject-maxlen=100 \ + --subject-minlen=10 \ + --body-regex=".*" \ + --body-maxlen=200 \ + --max-parents=1 if [ $? -ne 0 ] then - echo "Please fix your commit message to match AppFlowy coding standards" + printError "Please fix your commit message to match AppFlowy coding standards" + printError "https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/software-contributions/submitting-code/style-guides" exit 1 fi diff --git a/.githooks/pre-commit b/.githooks/pre-commit index d27345fe71..be42c93834 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,6 +1,23 @@ #!/usr/bin/env bash -echo "Running local AppFlowy pre-commit hook." +YELLOW="\e[93m" +GREEN="\e[32m" +RED="\e[31m" +ENDCOLOR="\e[0m" + +printMessage() { + printf "${YELLOW}AppFlowy : $1${ENDCOLOR}\n" +} + +printSuccess() { + printf "${GREEN}AppFlowy : $1${ENDCOLOR}\n" +} + +printError() { + printf "${RED}AppFlowy : $1${ENDCOLOR}\n" +} + +printMessage "Running local AppFlowy pre-commit hook." #flutter format . ##https://gist.github.com/benmccallum/28e4f216d9d72f5965133e6c43aaff6e diff --git a/.githooks/pre-push b/.githooks/pre-push index ad7d19a16e..7b6eeb8bc1 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -1,23 +1,41 @@ #!/usr/bin/env bash -echo "Running local AppFlowy pre-push hook." +YELLOW="\e[93m" +GREEN="\e[32m" +RED="\e[31m" +ENDCOLOR="\e[0m" + +printMessage() { + printf "${YELLOW}AppFlowy : $1${ENDCOLOR}\n" +} + +printSuccess() { + printf "${GREEN}AppFlowy : $1${ENDCOLOR}\n" +} + +printError() { + printf "${RED}AppFlowy : $1${ENDCOLOR}\n" +} + +printMessage "Running local AppFlowy pre-push hook." if [[ `git status --porcelain` ]]; then - printf "\e[31;1m%s\e[0m\n" 'This script needs to run against committed code only. Please commit or stash you changes.' + printError "This script needs to run against committed code only. Please commit or stash you changes." exit 1 fi -printf "\e[33;1m%s\e[0m\n" 'Running the Flutter analyzer' +printMessage "Running the Flutter analyzer" flutter analyze if [ $? -ne 0 ]; then - printf "\e[31;1m%s\e[0m\n" 'Flutter analyzer error' + printError "Flutter analyzer error" exit 1 fi -printf "\e[33;1m%s\e[0m\n" 'Finished running the Flutter analyzer' -printf "\e[33;1m%s\e[0m\n" 'Running unit tests' +printMessage "Finished running the Flutter analyzer" + +#printMessage "Running unit tests" #flutter test #if [ $? -ne 0 ]; then # printf "\e[31;1m%s\e[0m\n" 'Unit tests error' diff --git a/.gitignore b/.gitignore index c956a0ad13..b4bd54c6be 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ frontend/.vscode/* # Commit the highest level pubspec.lock, but ignore the others pubspec.lock !frontend/app_flowy/pubspec.lock + +# ignore tool used for commit linting +.githooks/gitlint diff --git a/commitlint.config.js b/commitlint.config.js index c59a378e48..1e1af55752 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -22,3 +22,4 @@ module.exports = { 'footer-max-line-length': [2, 'always', 100] }, }; + diff --git a/frontend/Makefile.toml b/frontend/Makefile.toml index 7449bfeef3..337b9efd76 100644 --- a/frontend/Makefile.toml +++ b/frontend/Makefile.toml @@ -8,7 +8,6 @@ extend = [ { path = "scripts/makefile/env.toml" }, { path = "scripts/makefile/flutter.toml" }, { path = "scripts/makefile/tool.toml" }, - { path = "scripts/makefile/githooks.toml" }, ] [config] diff --git a/frontend/scripts/install_dev_env/install_linux.sh b/frontend/scripts/install_dev_env/install_linux.sh index a580c22b19..396a66cd63 100755 --- a/frontend/scripts/install_dev_env/install_linux.sh +++ b/frontend/scripts/install_dev_env/install_linux.sh @@ -50,6 +50,13 @@ flutter doctor printMessage "Setting up githooks." git config core.hooksPath .githooks +# Install go-gitlint +printMessage "Installing go-gitlint." +GOLINT_FILENAME="go-gitlint_1.1.0_linux_x86_64.tar.gz" +wget https://github.com/llorllale/go-gitlint/releases/download/1.1.0/${GOLINT_FILENAME} +tar -zxv --directory .githooks/. -f ${GOLINT_FILENAME} gitlint +rm ${GOLINT_FILENAME} + # Change to the frontend directory cd frontend @@ -61,10 +68,6 @@ cargo install --force cargo-make printMessage "Installing duckscript." cargo install --force duckscript_cli -# Install CommitLint -printMessage "Installing CommitLint." -npm install @commitlint/cli @commitlint/config-conventional --save-dev - # Check prerequisites printMessage "Checking prerequisites." cargo make flowy_dev diff --git a/frontend/scripts/install_dev_env/install_macos.sh b/frontend/scripts/install_dev_env/install_macos.sh index edc0c40b26..26a2e5da02 100755 --- a/frontend/scripts/install_dev_env/install_macos.sh +++ b/frontend/scripts/install_dev_env/install_macos.sh @@ -50,6 +50,13 @@ flutter doctor printMessage "Setting up githooks." git config core.hooksPath .githooks +# Install go-gitlint +printMessage "Installing go-gitlint." +GOLINT_FILENAME="go-gitlint_1.1.0_osx_x86_64.tar.gz" +wget https://github.com/llorllale/go-gitlint/releases/download/1.1.0/${GOLINT_FILENAME} +tar -zxv --directory .githooks/. -f ${GOLINT_FILENAME} gitlint +rm ${GOLINT_FILENAME} + # Change to the frontend directory cd frontend @@ -61,10 +68,6 @@ cargo install --force cargo-make printMessage "Installing duckscript." cargo install --force duckscript_cli -# Install CommitLint -printMessagae "Installing CommitLint." -npm install @commitlint/cli @commitlint/config-conventional --save-dev - # Check prerequisites printMessage "Checking prerequisites." cargo make flowy_dev diff --git a/frontend/scripts/makefile/githooks.toml b/frontend/scripts/makefile/githooks.toml deleted file mode 100644 index f6b066ec49..0000000000 --- a/frontend/scripts/makefile/githooks.toml +++ /dev/null @@ -1,39 +0,0 @@ -[tasks.install-commitlint.mac] -script = [ - """ - brew install npm - npm install @commitlint/cli @commitlint/config-conventional --save-dev - - git config core.hooksPath .githooks - """, -] -script_runner = "@shell" - -[tasks.install-commitlint.windows] -script = [ - """ - echo "WIP" - - git config core.hooksPath .githooks - """, -] -script_runner = "@duckscript" - -[tasks.install-commitlint.linux] -script = [ - """ - if command -v apt &> /dev/null - then - echo "Installing node.js (sudo apt install nodejs)" - sudo apt install nodejs - else - echo "Installing node.js (sudo pacman -S nodejs)" - sudo pacman -S nodejs - fi - - npm install @commitlint/cli @commitlint/config-conventional --save-dev - - git config core.hooksPath .githooks - """, -] -script_runner = "@shell" diff --git a/package.json b/package.json deleted file mode 100644 index 0f6a7fcafe..0000000000 --- a/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "devDependencies": { - "@commitlint/cli": "^16.1.0", - "@commitlint/config-conventional": "^16.0.0" - } -}