From 2b59f40a0b1e0678a24a517b6fac370734c107bf Mon Sep 17 00:00:00 2001 From: Valera Melnikov Date: Wed, 12 Jul 2023 10:12:28 +0300 Subject: [PATCH] fix: fixes for running checks on pre-commit for BE and FE separately (#25319) ## Description Fixes for running checks on pre-commit for BE and FE separately #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [ ] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag Co-authored-by: Valera Melnikov --- app/client/.husky/check-staged-files.sh | 19 +++++++++++++++++++ app/client/.husky/pre-commit | 6 +----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 app/client/.husky/check-staged-files.sh diff --git a/app/client/.husky/check-staged-files.sh b/app/client/.husky/check-staged-files.sh new file mode 100644 index 0000000000..a0c3b1eaec --- /dev/null +++ b/app/client/.husky/check-staged-files.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +is_server_change=$(git diff --cached --name-only | grep -c "app/server") +is_client_change=$(git diff --cached --name-only | grep -c "app/client") + +if [ "$is_server_change" -ge 1 ]; then + echo "Running Spotless check ..." + pushd app/server > /dev/null + (mvn spotless:check 1> /dev/null && popd > /dev/null) || (echo "Spotless check failed, please run mvn spotless:apply" && exit 1) +else + echo "Skipping server side check..." +fi + +if [ "$is_client_change" -ge 1 ]; then + echo "Running client check ..." + npx lint-staged --cwd app/client && git-secrets --scan --untracked && git-secrets --scan -r +else + echo "Skipping client side check..." +fi diff --git a/app/client/.husky/pre-commit b/app/client/.husky/pre-commit index c754342b0c..df1168865b 100755 --- a/app/client/.husky/pre-commit +++ b/app/client/.husky/pre-commit @@ -1,8 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npx lint-staged --cwd app/client && git-secrets --scan --untracked && git-secrets --scan -r - -echo "Running Spotless check ..." -pushd app/server > /dev/null -(mvn spotless:check 1> /dev/null && popd > /dev/null) || (echo "Spotless check failed, please run mvn spotless:apply" && exit 1) +sh app/client/.husky/check-staged-files.sh