From a03962af1717544f44422e68a320b29d755a74eb Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Tue, 10 Dec 2024 20:53:04 +0600 Subject: [PATCH] enhance(workflow): added pre-push hooks to reduce time from pre-commit --- .husky/pre-commit | 48 ++--------------------------------------------- .husky/pre-push | 31 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 46 deletions(-) create mode 100644 .husky/pre-push diff --git a/.husky/pre-commit b/.husky/pre-commit index 4b792fb3b2..885c1d5d1d 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,26 +1,7 @@ # Check if there are staged changes in the frontend directory if git diff --cached --name-only | grep -q '^agenta-web/'; then - echo '🔍 Changes detected in the agenta-web directory. Running checks...' - - # Navigate to the frontend directory cd agenta-web || exit - # Run ESLint check - if ! npm run lint; then - echo '❌ ESLint issues detected. Please fix them before committing.' - exit 1 - else - echo '✅ ESLint check passed.' - fi - - # Run TypeScript type check - if ! npm run types:check; then - echo '❌ TypeScript type errors detected. Please fix them before committing.' - exit 1 - else - echo '✅ TypeScript type check passed.' - fi - # Run Prettier check if ! npm run format; then echo '⚠️ Formatting issues detected. Running Prettier to fix them...' @@ -29,34 +10,15 @@ if git diff --cached --name-only | grep -q '^agenta-web/'; then # Stage the fixed files git add . - echo '✅ Formatting issues fixed and changes staged. Proceeding with further checks...' - else - echo '✅ Prettier check passed.' + echo '✅ Formatting issues fixed and changes staged.' fi - - echo '🎉 All checks passed. Ready to commit!' -else - echo '✅ No changes in the agenta-web directory. Skipping frontend checks.' fi # Check for changes in backend directory if git diff --cached --name-only | grep -q '^agenta-backend/'; then - echo '🔍 Changes detected in the backend directory. Running checks...' - - # Navigate to the backend directory cd agenta-backend || exit - # Run pylint for linting - echo '🔍 Running pylint...' - if ! pylint $(git diff --cached --name-only | grep '\.py$'); then - echo '❌ pylint issues detected. Please fix them before committing.' - exit 1 - else - echo '✅ pylint check passed.' - fi - # Run black for formatting - echo '🔍 Running black...' if ! black --check .; then echo '⚠️ Formatting issues detected. Running black to fix them...' black . @@ -64,12 +26,6 @@ if git diff --cached --name-only | grep -q '^agenta-backend/'; then # Stage the fixed files git add . - echo '✅ Formatting issues fixed and changes staged. Proceeding with further checks...' - else - echo '✅ black formatting check passed.' + echo '✅ Formatting issues fixed and changes staged.' fi - - echo '🎉 Backend checks passed. Ready to commit!' -else - echo '✅ No changes in the backend directory. Skipping backend checks.' fi \ No newline at end of file diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000000..a8370a917f --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,31 @@ +# Check frontend changes +if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | grep -q '^agenta-web/'; then + cd agenta-web || exit + + # Run ESLint check + if ! npm run lint; then + echo '❌ ESLint issues detected. Please fix them before pushing the code.' + exit 1 + fi + + # Run TypeScript type check + if ! npm run types:check; then + echo '❌ Frontend type check failed.' + exit 1 + fi + + echo '🎉 All checks passed. Ready to push!' +fi + +# Check backend changes +if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | grep -q '^agenta-backend/'; then + cd agenta-backend || exit + + # Run backend checks + if ! pylint $(git diff --cached --name-only | grep '\.py$'); then + echo '❌ pylint issues detected. Please fix them before pushing the code.' + exit 1 + fi + + echo '🎉 Backend checks passed. Ready to push!' +fi \ No newline at end of file