diff --git a/.husky/commit-msg b/.husky/commit-msg index f7607656..4ef70454 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash . "$(dirname $0)/_/husky.sh" @@ -22,75 +22,4 @@ if [[ -z "$STAGED" && -z "$MERGE" ]] ; then fi ## Lint commit message -echo "[COMMIT-MSG Hook] Linting commit message" && ./node_modules/.bin/commitlint --edit $1 - -## Check for WIP mention -if (grep -qe "WIP" $1); then - - ## If WIP, skip tests - echo "[COMMIT-MSG Hook] Found WIP mention => Skipping tests" - -else - - ## If no WIP, run tests - echo "[COMMIT-MSG Hook] No WIP mention found" - - if [[ -n "$MERGE" ]] ; then - echo "[COMMIT-MSG Hook] Saved ongoing merge status" - fi - - if [[ -n "$STAGED" ]] ; then - echo "[COMMIT-MSG Hook] Stashing working tree" - STASH="pre-commit hook test on $(date '+%F %T')" && git stash push -qukm "$STASH" - fi - - echo "[COMMIT-MSG Hook] Running tests" - - ## Build list of previous WIP changes - LIST="" - NEW=$(git rev-parse HEAD) - while [[ -n "$NEW" ]] ; do - LIST=$(echo "$LIST" ; echo "$NEW") - NEW=$(echo "$NEW" | sed -e 's/^\(.*\)$/\1\^@/g' | xargs git rev-list --no-walk -E --grep="WIP") - done - - RELEVANT="$(echo "$LIST" | xargs -L1 git diff-tree --no-commit-id --name-only -r | sort -u ; echo "$STAGED")" - - ## Install root dependencies if package.json changed - echo "$RELEVANT" | grep -q "^package.json$" && npm i - - ## Bootstrap packages with changed package.json - PACKAGES=$(echo "$RELEVANT" | grep "package.json$" | grep -v "^package.json$" | xargs cat | grep name - echo "$PACKAGES" | sed 's/.*"name": "\(.*\)".*/--scope "\1"/g') | xargs ./node_modules/.bin/lerna bootstrap --since HEAD - - ## Run tests related to staged files - echo "$RELEVANT" | xargs ./node_modules/.bin/jest --bail --coverage --silent --passWithNoTests --findRelatedTests - - if [[ $? -ne 0 ]] ; then - echo "[COMMIT-MSG Hook] You tried to commit changes without a WIP mention," - echo "[COMMIT-MSG Hook] but tests related to staged files or yet untested WIP commits are failing." - echo "[COMMIT-MSG Hook] Resolve the remaining issues or commit current changes as WIP." - fi - - echo "[COMMIT-MSG Hook] Resetting the stage" - - ## Reset tracked files & clean untracked files - git reset --hard - git clean -df - - if [[ -n "$STAGED" ]] ; then - echo "[COMMIT-MSG Hook] Restoring working tree" - git stash list | grep -q "$STASH" && git stash pop -q --index - fi - - if [[ -n "$MERGE" ]] ; then - echo "[COMMIT-MSG Hook] Restoring ongoing merge status" - git update-ref MERGE_HEAD "$MERGE" - if [[ -n "$M_MSG" ]] ; then - echo "$M_MSG" > .git/MERGE_MSG - fi - fi - - exit $TESTS - -fi +echo "[COMMIT-MSG Hook] Linting commit message" && pnpm commitlint --edit $1 diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100755 index 8482424b..00000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. "$(dirname $0)/_/husky.sh" - -## Run specified linters on staged files, automatically adding fixes -npm run lint:staged \ No newline at end of file diff --git a/.husky/pre-push b/.husky/pre-push old mode 100644 new mode 100755 index 3b20658a..998aadb0 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,8 +1,8 @@ -#!/bin/sh +#!/bin/bash . "$(dirname $0)/_/husky.sh" -REGEX="^(main|next|release(release|feat|fix|test|chore|build|docs)\/[a-zA-Z0-9\-]+)$" +REGEX="^((master|develop|release|(release|feat|fix|docs|test|chore|build|docs)\/|snyk-)[a-zA-Z0-9\.\-]+)$" REMOTE="$1" URL="$2" @@ -12,7 +12,7 @@ do BRANCH=$(git rev-parse --abbrev-ref "$L_REF") - if [[ "$R_SHA" = "$(printf "%040d")" ]] ; then + if [ "$R_SHA" = "$(printf "%040d")" ] ; then # Check branch name convention if ! (echo "$BRANCH" | grep -qE "$REGEX") ; then @@ -24,4 +24,4 @@ do fi -done \ No newline at end of file +done