Skip to content

Commit

Permalink
Husky hook fix. (#4469)
Browse files Browse the repository at this point in the history
* Modified pre-commit script to Posix-compilant.

Signed-off-by: aryan <[email protected]>

* Modified pre-push script to Posix-compilant.

Signed-off-by: aryan <[email protected]>

---------

Signed-off-by: aryan <[email protected]>
Co-authored-by: Sarthak Jain <[email protected]>
Co-authored-by: Saranya Jena <[email protected]>
  • Loading branch information
3 people authored Mar 5, 2024
1 parent da8ae75 commit b85a60d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions chaoscenter/web/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
"$(dirname "$0")/_/husky.sh"

declare MATCH_PATH='chaoscenter/web/'
MATCH_PATH='chaoscenter/web/'

declare BRANCH=$(git rev-parse --abbrev-ref HEAD)
BRANCH=$(git rev-parse --abbrev-ref HEAD)

if [[ "$BRANCH" == "main" ]]; then
if [ "$BRANCH" = "main" ]; then
echo "\033[0;31;1mYou can't commit directly to main branch\033[0m"
exit 1
fi

if [[ "$BRANCH" =~ ^release\/.* ]]; then
if expr "$BRANCH" : 'release\/.*' >/dev/null; then
echo "\033[0;31;1mYou cannot commit directly to release branch\033[0m"
exit 1
exit 1
fi

declare LITMUS_UI_FILE_CHANGES=$(git diff --name-only --cached | grep $MATCH_PATH -c)
LITMUS_UI_FILE_CHANGES=$(git diff --name-only --cached | grep "$MATCH_PATH" -c)

echo "\033[0;93mLITMUS_UI_FILE_CHANGES\033[0m ⟶ $LITMUS_UI_FILE_CHANGES"

if [[ $LITMUS_UI_FILE_CHANGES -gt 0 ]]
if [ "$LITMUS_UI_FILE_CHANGES" -gt 0 ];
then
cd ./chaoscenter/web && yarn lint-staged
else
Expand Down
26 changes: 13 additions & 13 deletions chaoscenter/web/.husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
"$(dirname "$0")/_/husky.sh"

declare MATCH_PATH='chaoscenter/web/'
MATCH_PATH='chaoscenter/web/'

declare BRANCH=$(git rev-parse --abbrev-ref HEAD)
BRANCH=$(git rev-parse --abbrev-ref HEAD)

echo "ON_BRANCH ⟶ $BRANCH"

declare REMOTE_EXISTS=$(git ls-remote --heads origin $BRANCH | wc -l)
REMOTE_EXISTS=$(git ls-remote --heads origin "$BRANCH" | wc -l)

declare CHECK_AGAINST_COMMIT
CHECK_AGAINST_COMMIT=""

if [[ $REMOTE_EXISTS -gt 0 ]]
if [ "$REMOTE_EXISTS" -gt 0 ];
then
# remote exists, compare changes from last pushed commit
declare LAST_PUSHED_COMMIT_ID=$(git rev-parse --short @{push})
LAST_PUSHED_COMMIT_ID=$(git rev-parse --short @{push})
echo "LAST_PUSHED_COMMIT ⟶ $LAST_PUSHED_COMMIT_ID"
CHECK_AGAINST_COMMIT=$LAST_PUSHED_COMMIT_ID
CHECK_AGAINST_COMMIT="$LAST_PUSHED_COMMIT_ID"
else
# remote doesn't exists, compare changes from branched off commit
declare BRANCHED_COMMIT_ID=$(git rev-parse --short $(git merge-base main $BRANCH))
BRANCHED_COMMIT_ID=$(git rev-parse --short "$(git merge-base main "$BRANCH")")
echo "BRANCHED_COMMIT_ID ⟶ $BRANCHED_COMMIT_ID"
CHECK_AGAINST_COMMIT=$BRANCHED_COMMIT_ID
CHECK_AGAINST_COMMIT="$BRANCHED_COMMIT_ID"
fi

declare CHAOS_UI_FILE_CHANGES=$(git diff --name-only -r --stat --oneline $CHECK_AGAINST_COMMIT HEAD | grep $MATCH_PATH -c)
CHAOS_UI_FILE_CHANGES=$(git diff --name-only -r --stat --oneline "$CHECK_AGAINST_COMMIT" HEAD | grep "$MATCH_PATH" -c)

echo "CHAOS_UI_FILE_CHANGES ⟶ $CHAOS_UI_FILE_CHANGES"

if [[ $CHAOS_UI_FILE_CHANGES -gt 0 ]]
if [ "$CHAOS_UI_FILE_CHANGES" -gt 0 ];
then
cd ./chaoscenter/web && yarn test:silent --changedSince=$CHECK_AGAINST_COMMIT
cd ./chaoscenter/web && yarn test:silent --changedSince="$CHECK_AGAINST_COMMIT"
else
echo "Skipping husky pre-push hook in $MATCH_PATH folder"
fi

0 comments on commit b85a60d

Please sign in to comment.