From 6a7743d99d6c7247b64f2d5c76855fa87a7db26b Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Sun, 8 Dec 2024 15:38:59 +0600 Subject: [PATCH 01/16] feat(frontend) added pre-commit hook for format check --- agenta-web/.husky/pre-commit | 15 ++++ agenta-web/package-lock.json | 136 +++++++++++++++++++++++++++++++++++ agenta-web/package.json | 4 +- 3 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 agenta-web/.husky/pre-commit diff --git a/agenta-web/.husky/pre-commit b/agenta-web/.husky/pre-commit new file mode 100644 index 0000000000..c4f2dca4cc --- /dev/null +++ b/agenta-web/.husky/pre-commit @@ -0,0 +1,15 @@ +# Navigate to the frontend directory +cd agenta-web || exit + +# Run Prettier check +if ! npm run format; then + echo '⚠️ Formatting issues detected. Running Prettier to fix them...' + npm run format-fix + + # Stage the fixed files + git add . + + echo '✅ Formatting issues fixed and changes staged. Proceeding with commit...' +else + echo '✅ Prettier check passed. Everything looks good!' +fi diff --git a/agenta-web/package-lock.json b/agenta-web/package-lock.json index 38c3616a2a..0ba557b382 100644 --- a/agenta-web/package-lock.json +++ b/agenta-web/package-lock.json @@ -84,6 +84,7 @@ "@swc/core": "^1.4.15", "@types/node": "^20.8.10", "cypress": "^13.15.0", + "husky": "^9.1.7", "node-mocks-http": "^1.12.2", "prettier": "^3.2.5" }, @@ -1797,6 +1798,21 @@ } } }, + "node_modules/@next/swc-darwin-arm64": { + "version": "14.2.17", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.17.tgz", + "integrity": "sha512-WiOf5nElPknrhRMTipXYTJcUz7+8IAjOYw3vXzj3BYRcVY0hRHKWgTgQ5439EvzQyHEko77XK+yN9x9OJ0oOog==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@next/swc-darwin-x64": { "version": "14.2.17", "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.17.tgz", @@ -1813,6 +1829,111 @@ "node": ">= 10" } }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.2.17", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.17.tgz", + "integrity": "sha512-SSHLZls3ZwNEHsc+d0ynKS+7Af0Nr8+KTUBAy9pm6xz9SHkJ/TeuEg6W3cbbcMSh6j4ITvrjv3Oi8n27VR+IPw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "14.2.17", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.17.tgz", + "integrity": "sha512-VFge37us5LNPatB4F7iYeuGs9Dprqe4ZkW7lOEJM91r+Wf8EIdViWHLpIwfdDXinvCdLl6b4VyLpEBwpkctJHA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "14.2.17", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.17.tgz", + "integrity": "sha512-aaQlpxUVb9RZ41adlTYVQ3xvYEfBPUC8+6rDgmQ/0l7SvK8S1YNJzPmDPX6a4t0jLtIoNk7j+nroS/pB4nx7vQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "14.2.17", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.17.tgz", + "integrity": "sha512-HSyEiFaEY3ay5iATDqEup5WAfrhMATNJm8dYx3ZxL+e9eKv10XKZCwtZByDoLST7CyBmyDz+OFJL1wigyXeaoA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.2.17", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.17.tgz", + "integrity": "sha512-h5qM9Btqv87eYH8ArrnLoAHLyi79oPTP2vlGNSg4CDvUiXgi7l0+5KuEGp5pJoMhjuv9ChRdm7mRlUUACeBt4w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.17", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.17.tgz", + "integrity": "sha512-BD/G++GKSLexQjdyoEUgyo5nClU7er5rK0sE+HlEqnldJSm96CIr/+YOTT063LVTT/dUOeQsNgp5DXr86/K7/A==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-x64-msvc": { + "version": "14.2.17", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.17.tgz", + "integrity": "sha512-vkQfN1+4V4KqDibkW2q0sJ6CxQuXq5l2ma3z0BRcfIqkAMZiiW67T9yCpwqJKP68QghBtPEFjPAlaqe38O6frw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -10882,6 +11003,21 @@ "node": ">=10.17.0" } }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/hyphenate-style-name": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/hyphenate-style-name/-/hyphenate-style-name-1.1.0.tgz", diff --git a/agenta-web/package.json b/agenta-web/package.json index eda51d6a65..9fc04c5dfd 100644 --- a/agenta-web/package.json +++ b/agenta-web/package.json @@ -18,7 +18,8 @@ "format": "prettier --check .", "format-fix": "prettier --write .", "types:check": "tsc", - "types:watch": "tsc -w" + "types:watch": "tsc -w", + "prepare": "cd .. && husky agenta-web/.husky" }, "dependencies": { "@ant-design/colors": "^7.0.0", @@ -97,6 +98,7 @@ "@swc/core": "^1.4.15", "@types/node": "^20.8.10", "cypress": "^13.15.0", + "husky": "^9.1.7", "node-mocks-http": "^1.12.2", "prettier": "^3.2.5" } From 47570250c9beb2a922174ec26c62bcb803cd475e Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Sun, 8 Dec 2024 15:56:55 +0600 Subject: [PATCH 02/16] feat(frontend): added lint and tsc check on pre-commit hook --- agenta-web/.husky/pre-commit | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/agenta-web/.husky/pre-commit b/agenta-web/.husky/pre-commit index c4f2dca4cc..fe7f05b232 100644 --- a/agenta-web/.husky/pre-commit +++ b/agenta-web/.husky/pre-commit @@ -1,6 +1,22 @@ # 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...' @@ -9,7 +25,9 @@ if ! npm run format; then # Stage the fixed files git add . - echo '✅ Formatting issues fixed and changes staged. Proceeding with commit...' + echo '✅ Formatting issues fixed and changes staged. Proceeding with further checks...' else - echo '✅ Prettier check passed. Everything looks good!' + echo '✅ Prettier check passed. Proceeding with further checks...' fi + +echo '🎉 All checks passed. Ready to commit!' \ No newline at end of file From 8c80a3231a47647a56f649bd08b3f689b19f7b6e Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Sun, 8 Dec 2024 16:50:45 +0600 Subject: [PATCH 03/16] enhance(frontend): added condition to run hooks efficiantly --- agenta-web/.husky/pre-commit | 59 ++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/agenta-web/.husky/pre-commit b/agenta-web/.husky/pre-commit index fe7f05b232..f01b0d9404 100644 --- a/agenta-web/.husky/pre-commit +++ b/agenta-web/.husky/pre-commit @@ -1,33 +1,40 @@ -# Navigate to the frontend directory -cd agenta-web || exit +# 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...' -# 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 + # Navigate to the frontend directory + cd agenta-web || exit -# 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 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 Prettier check -if ! npm run format; then - echo '⚠️ Formatting issues detected. Running Prettier to fix them...' - npm run format-fix + # 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 - # Stage the fixed files - git add . + # Run Prettier check + if ! npm run format; then + echo '⚠️ Formatting issues detected. Running Prettier to fix them...' + npm run format-fix - echo '✅ Formatting issues fixed and changes staged. Proceeding with further checks...' + # Stage the fixed files + git add . + + echo '✅ Formatting issues fixed and changes staged. Proceeding with further checks...' + else + echo '✅ Prettier check passed.' + fi + + echo '🎉 All checks passed. Ready to commit!' else - echo '✅ Prettier check passed. Proceeding with further checks...' + echo '✅ No changes in the agenta-web directory. Skipping frontend checks.' fi - -echo '🎉 All checks passed. Ready to commit!' \ No newline at end of file From 2eb926a0e42fa793028f536cfe2f5bf907a1fb78 Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Sun, 8 Dec 2024 17:11:54 +0600 Subject: [PATCH 04/16] feat(bacckend): added pre-commit checks for backend --- agenta-web/.husky/pre-commit | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/agenta-web/.husky/pre-commit b/agenta-web/.husky/pre-commit index f01b0d9404..4b792fb3b2 100644 --- a/agenta-web/.husky/pre-commit +++ b/agenta-web/.husky/pre-commit @@ -38,3 +38,38 @@ if git diff --cached --name-only | grep -q '^agenta-web/'; then 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 . + + # Stage the fixed files + git add . + + echo '✅ Formatting issues fixed and changes staged. Proceeding with further checks...' + else + echo '✅ black formatting check passed.' + 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 From 143587c76ceca51c22991c0898c02e5fd0cd97d3 Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Mon, 9 Dec 2024 18:28:27 +0600 Subject: [PATCH 05/16] refactor(frontend): moved .husky folder in the root directory --- {agenta-web/.husky => .husky}/pre-commit | 0 agenta-web/package.json | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename {agenta-web/.husky => .husky}/pre-commit (100%) diff --git a/agenta-web/.husky/pre-commit b/.husky/pre-commit similarity index 100% rename from agenta-web/.husky/pre-commit rename to .husky/pre-commit diff --git a/agenta-web/package.json b/agenta-web/package.json index 9fc04c5dfd..b5c2478cab 100644 --- a/agenta-web/package.json +++ b/agenta-web/package.json @@ -19,7 +19,7 @@ "format-fix": "prettier --write .", "types:check": "tsc", "types:watch": "tsc -w", - "prepare": "cd .. && husky agenta-web/.husky" + "prepare": "cd .. && husky" }, "dependencies": { "@ant-design/colors": "^7.0.0", From a03962af1717544f44422e68a320b29d755a74eb Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Tue, 10 Dec 2024 20:53:04 +0600 Subject: [PATCH 06/16] 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 From f1f3548083802de64d18e1cb8cb6c4f6602542a4 Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Tue, 10 Dec 2024 21:12:47 +0600 Subject: [PATCH 07/16] enhane(workflow): added cli directory --- .husky/pre-commit | 18 +++++++++++++++++- .husky/pre-push | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 885c1d5d1d..ed9f5f7348 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ -# Check if there are staged changes in the frontend directory +# Check for changes in frontend directory if git diff --cached --name-only | grep -q '^agenta-web/'; then cd agenta-web || exit @@ -18,6 +18,22 @@ fi if git diff --cached --name-only | grep -q '^agenta-backend/'; then cd agenta-backend || exit + # Run black for formatting + if ! black --check .; then + echo '⚠️ Formatting issues detected. Running black to fix them...' + black . + + # Stage the fixed files + git add . + + echo '✅ Formatting issues fixed and changes staged.' + fi +fi + +# Check for changes in cli directory +if git diff --cached --name-only | grep -q '^agenta-cli/'; then + cd agenta-cli || exit + # Run black for formatting if ! black --check .; then echo '⚠️ Formatting issues detected. Running black to fix them...' diff --git a/.husky/pre-push b/.husky/pre-push index a8370a917f..8eeb110f10 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -22,7 +22,20 @@ if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | gre cd agenta-backend || exit # Run backend checks - if ! pylint $(git diff --cached --name-only | grep '\.py$'); then + if ! pylint --recursive=y --errors-only .; then + echo '❌ pylint issues detected. Please fix them before pushing the code.' + exit 1 + fi + + echo '🎉 Backend checks passed. Ready to push!' +fi + +# Check cli changes +if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | grep -q '^agenta-cli/'; then + cd agenta-cli || exit + + # Run backend checks + if ! pylint --recursive=y --errors-only .; then echo '❌ pylint issues detected. Please fix them before pushing the code.' exit 1 fi From a1abe95f3812b440c7e775f045a4d8743aa3c1ed Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Wed, 11 Dec 2024 19:37:27 +0600 Subject: [PATCH 08/16] refactor(workflow): removed duplicate code --- .husky/pre-commit | 44 +++---- .husky/pre-push | 37 +++--- agenta-web/package-lock.json | 120 ------------------ agenta-web/package.json | 2 +- .../components/Playground/Views/TestView.tsx | 2 +- 5 files changed, 37 insertions(+), 168 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index ed9f5f7348..31338ad6d7 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,7 @@ +# Define the directories to check +DIRECTORIES=("agenta-backend" "agenta-cli") +ORIGINAL_DIR=$(pwd) + # Check for changes in frontend directory if git diff --cached --name-only | grep -q '^agenta-web/'; then cd agenta-web || exit @@ -12,36 +16,26 @@ if git diff --cached --name-only | grep -q '^agenta-web/'; then echo '✅ Formatting issues fixed and changes staged.' fi + + cd "$ORIGINAL_DIR" || exit fi # Check for changes in backend directory -if git diff --cached --name-only | grep -q '^agenta-backend/'; then - cd agenta-backend || exit +for DIR in "${DIRECTORIES[@]}"; do + if git diff --cached --name-only | grep -q "^$DIR/"; then + cd "$DIR" || exit - # Run black for formatting - if ! black --check .; then - echo '⚠️ Formatting issues detected. Running black to fix them...' - black . + # Run black for formatting + if ! black --check .; then + echo "⚠️ Formatting issues detected in $DIR. Running black to fix them..." + black . - # Stage the fixed files - git add . + # Stage the fixed files + git add . - echo '✅ Formatting issues fixed and changes staged.' - fi -fi + echo "✅ Formatting issues fixed and changes staged in $DIR." + fi -# Check for changes in cli directory -if git diff --cached --name-only | grep -q '^agenta-cli/'; then - cd agenta-cli || exit - - # Run black for formatting - if ! black --check .; then - echo '⚠️ Formatting issues detected. Running black to fix them...' - black . - - # Stage the fixed files - git add . - - echo '✅ Formatting issues fixed and changes staged.' + cd "$ORIGINAL_DIR" || exit fi -fi \ No newline at end of file +done diff --git a/.husky/pre-push b/.husky/pre-push index 8eeb110f10..024d26b608 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,3 +1,7 @@ +# Define the directories to check +DIRECTORIES=("agenta-backend" "agenta-cli") +ORIGINAL_DIR=$(pwd) + # 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 @@ -17,28 +21,19 @@ if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | gre 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 +# Check for changes in backend directory +for DIR in "${DIRECTORIES[@]}"; do + if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | grep -q "^$DIR/"; then + cd "$DIR" || exit - # Run backend checks - if ! pylint --recursive=y --errors-only .; then - echo '❌ pylint issues detected. Please fix them before pushing the code.' - exit 1 - fi + # Run pylint checks + if ! pylint --recursive=y --errors-only .; then + echo "❌ pylint issues detected in $DIR. Please fix them before pushing the code." + exit 1 + fi - echo '🎉 Backend checks passed. Ready to push!' -fi + echo '🎉 Backend checks passed. Ready to push!' -# Check cli changes -if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | grep -q '^agenta-cli/'; then - cd agenta-cli || exit - - # Run backend checks - if ! pylint --recursive=y --errors-only .; then - echo '❌ pylint issues detected. Please fix them before pushing the code.' - exit 1 + cd "$ORIGINAL_DIR" || exit fi - - echo '🎉 Backend checks passed. Ready to push!' -fi \ No newline at end of file +done diff --git a/agenta-web/package-lock.json b/agenta-web/package-lock.json index c9dc205802..7e16e89cd2 100644 --- a/agenta-web/package-lock.json +++ b/agenta-web/package-lock.json @@ -20493,126 +20493,6 @@ "type": "github", "url": "https://github.com/sponsors/wooorm" } - }, - "node_modules/@next/swc-darwin-arm64": { - "version": "14.2.17", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.17.tgz", - "integrity": "sha512-WiOf5nElPknrhRMTipXYTJcUz7+8IAjOYw3vXzj3BYRcVY0hRHKWgTgQ5439EvzQyHEko77XK+yN9x9OJ0oOog==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.2.17", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.17.tgz", - "integrity": "sha512-SSHLZls3ZwNEHsc+d0ynKS+7Af0Nr8+KTUBAy9pm6xz9SHkJ/TeuEg6W3cbbcMSh6j4ITvrjv3Oi8n27VR+IPw==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.2.17", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.17.tgz", - "integrity": "sha512-VFge37us5LNPatB4F7iYeuGs9Dprqe4ZkW7lOEJM91r+Wf8EIdViWHLpIwfdDXinvCdLl6b4VyLpEBwpkctJHA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.2.17", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.17.tgz", - "integrity": "sha512-aaQlpxUVb9RZ41adlTYVQ3xvYEfBPUC8+6rDgmQ/0l7SvK8S1YNJzPmDPX6a4t0jLtIoNk7j+nroS/pB4nx7vQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-x64-musl": { - "version": "14.2.17", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.17.tgz", - "integrity": "sha512-HSyEiFaEY3ay5iATDqEup5WAfrhMATNJm8dYx3ZxL+e9eKv10XKZCwtZByDoLST7CyBmyDz+OFJL1wigyXeaoA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.2.17", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.17.tgz", - "integrity": "sha512-h5qM9Btqv87eYH8ArrnLoAHLyi79oPTP2vlGNSg4CDvUiXgi7l0+5KuEGp5pJoMhjuv9ChRdm7mRlUUACeBt4w==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.2.17", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.17.tgz", - "integrity": "sha512-BD/G++GKSLexQjdyoEUgyo5nClU7er5rK0sE+HlEqnldJSm96CIr/+YOTT063LVTT/dUOeQsNgp5DXr86/K7/A==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.2.17", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.17.tgz", - "integrity": "sha512-vkQfN1+4V4KqDibkW2q0sJ6CxQuXq5l2ma3z0BRcfIqkAMZiiW67T9yCpwqJKP68QghBtPEFjPAlaqe38O6frw==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } } } } diff --git a/agenta-web/package.json b/agenta-web/package.json index 09285b283a..f0e54a5246 100644 --- a/agenta-web/package.json +++ b/agenta-web/package.json @@ -19,7 +19,7 @@ "format-fix": "prettier --write .", "types:check": "tsc", "types:watch": "tsc -w", - "prepare": "cd .. && husky" + "prepare": "cd .. && husky && if [ \"$FEATURE_FLAG\" = \"cloud-dev\" ]; then cd .. && husky; fi" }, "dependencies": { "@ant-design/colors": "^7.0.0", diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index 3015c8819e..afb9977405 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -219,7 +219,7 @@ const BoxComponent: React.FC = ({ } }, [traceSpans]) - const activeTrace = useMemo(() => (traces ? traces[0] ?? null : null), [traces]) + const activeTrace = useMemo(() => (traces ? (traces[0] ?? null) : null), [traces]) const [selected, setSelected] = useState("") useEffect(() => { From 8cf5173ac66e11171108e25ed365d7f985372305 Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Wed, 11 Dec 2024 19:52:00 +0600 Subject: [PATCH 09/16] fix(workflow): pre-push hook failed --- .husky/pre-push | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.husky/pre-push b/.husky/pre-push index 024d26b608..2840b5ae59 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -19,6 +19,8 @@ if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | gre fi echo '🎉 All checks passed. Ready to push!' + + cd "$ORIGINAL_DIR" || exit fi # Check for changes in backend directory From 114652e381da96550a24ad7530e0ea2279d7506a Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Wed, 11 Dec 2024 20:08:04 +0600 Subject: [PATCH 10/16] temp(workflow): temporarily commented out the pylint checks --- .husky/pre-push | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.husky/pre-push b/.husky/pre-push index 2840b5ae59..cd3dde93e5 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -23,19 +23,19 @@ if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | gre cd "$ORIGINAL_DIR" || exit fi -# Check for changes in backend directory -for DIR in "${DIRECTORIES[@]}"; do - if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | grep -q "^$DIR/"; then - cd "$DIR" || exit - - # Run pylint checks - if ! pylint --recursive=y --errors-only .; then - echo "❌ pylint issues detected in $DIR. Please fix them before pushing the code." - exit 1 - fi - - echo '🎉 Backend checks passed. Ready to push!' - - cd "$ORIGINAL_DIR" || exit - fi -done +# # Check for changes in backend directory +# for DIR in "${DIRECTORIES[@]}"; do +# if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | grep -q "^$DIR/"; then +# cd "$DIR" || exit + +# # Run pylint checks +# if ! pylint --recursive=y --errors-only .; then +# echo "❌ pylint issues detected in $DIR. Please fix them before pushing the code." +# exit 1 +# fi + +# echo '🎉 Backend checks passed. Ready to push!' + +# cd "$ORIGINAL_DIR" || exit +# fi +# done From a809830c0698abe02adc688c8e42f810f2e0f2e1 Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Wed, 11 Dec 2024 21:13:28 +0600 Subject: [PATCH 11/16] fix(workflow): eslint build faile --- agenta-web/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-web/package.json b/agenta-web/package.json index 544785bece..75a559faae 100644 --- a/agenta-web/package.json +++ b/agenta-web/package.json @@ -19,7 +19,7 @@ "format-fix": "prettier --write .", "types:check": "tsc", "types:watch": "tsc -w", - "prepare": "cd .. && husky && if [ \"$FEATURE_FLAG\" = \"cloud-dev\" ]; then cd .. && husky; fi" + "prepare": "cd .. && husky && if [ \"$FEATURE_FLAG\" = \"cloud-dev\" ]; then cd .. && husky; fi || true" }, "dependencies": { "@ant-design/colors": "^7.0.0", From 467aa78e9744415b57b7f624c133e6e11819193a Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Wed, 11 Dec 2024 21:55:26 +0600 Subject: [PATCH 12/16] fix(prettire): format From cf2a9a68d49f55a524444d13fecd33065be0e46e Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Wed, 11 Dec 2024 22:41:39 +0600 Subject: [PATCH 13/16] fix(prettier): my system prettier lib version --- agenta-web/src/components/Playground/Views/TestView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index afb9977405..3015c8819e 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -219,7 +219,7 @@ const BoxComponent: React.FC = ({ } }, [traceSpans]) - const activeTrace = useMemo(() => (traces ? (traces[0] ?? null) : null), [traces]) + const activeTrace = useMemo(() => (traces ? traces[0] ?? null : null), [traces]) const [selected, setSelected] = useState("") useEffect(() => { From 114a6c3b306b547671b78c67197ad23d3d03fcce Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Wed, 11 Dec 2024 23:47:38 +0600 Subject: [PATCH 14/16] fix(workflow): pre-push hook for first time push --- .husky/pre-push | 74 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/.husky/pre-push b/.husky/pre-push index cd3dde93e5..ce77c6c27e 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,41 +1,77 @@ # Define the directories to check DIRECTORIES=("agenta-backend" "agenta-cli") ORIGINAL_DIR=$(pwd) +BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) +FIRST_PUSH_FILE=".git/first_push_detected" -# Check frontend changes -if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | grep -q '^agenta-web/'; then +# Function to run frontend checks +run_frontend_checks() { cd agenta-web || exit # Run ESLint check if ! npm run lint; then - echo '❌ ESLint issues detected. Please fix them before pushing the code.' + echo '❌ ESLint issues detected. Please fix them before pushing.' exit 1 fi # Run TypeScript type check if ! npm run types:check; then - echo '❌ Frontend type check failed.' + echo '❌ TypeScript type check failed.' exit 1 fi - echo '🎉 All checks passed. Ready to push!' + echo '🎉 Frontend checks passed!' + cd "$ORIGINAL_DIR" || exit +} + +# Function to run backend checks +run_backend_checks() { + local DIR=$1 + cd "$DIR" || exit + + # Run pylint checks + if ! pylint --recursive=y --errors-only .; then + echo "❌ pylint issues detected in $DIR. Please fix them before pushing." + exit 1 + fi + echo "🎉 Backend checks passed for $DIR." cd "$ORIGINAL_DIR" || exit -fi +} -# # Check for changes in backend directory -# for DIR in "${DIRECTORIES[@]}"; do -# if git diff --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | grep -q "^$DIR/"; then -# cd "$DIR" || exit +# Check if this is the first push +is_first_push() { + # Check if the branch exists locally + if ! git rev-parse --verify "$BRANCH_NAME" >/dev/null 2>&1; then + return 0 # First push, since the branch doesn't exist locally + fi + + # Check if the branch exists remotely + if ! git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then + return 0 # First push, since the branch doesn't exist remotely + fi -# # Run pylint checks -# if ! pylint --recursive=y --errors-only .; then -# echo "❌ pylint issues detected in $DIR. Please fix them before pushing the code." -# exit 1 -# fi + return 1 # Not the first push +} -# echo '🎉 Backend checks passed. Ready to push!' +# If: First-time push: Run all checks +# Else: Check directory-specific changes for existing branch +if is_first_push; then + echo "🚀 First-time push detected for branch: $BRANCH_NAME" + run_frontend_checks -# cd "$ORIGINAL_DIR" || exit -# fi -# done + for DIR in "${DIRECTORIES[@]}"; do + run_backend_checks "$DIR" + done +else + echo "🔍 Checking directory changes for existing branch: $BRANCH_NAME" + if git diff --name-only --cached origin/"$BRANCH_NAME" | grep -q '^agenta-web/'; then + run_frontend_checks + fi + + for DIR in "${DIRECTORIES[@]}"; do + if git diff --name-only --cached origin/"$BRANCH_NAME" | grep -q "^$DIR/"; then + run_backend_checks "$DIR" + fi + done +fi From 986b959de79b44942571dda51ea6bb8111cae619 Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Fri, 13 Dec 2024 15:11:34 +0600 Subject: [PATCH 15/16] fix(workflow): temporarily disabled pylint check --- .husky/pre-push | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.husky/pre-push b/.husky/pre-push index ce77c6c27e..7780c3ac7a 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -60,18 +60,18 @@ if is_first_push; then echo "🚀 First-time push detected for branch: $BRANCH_NAME" run_frontend_checks - for DIR in "${DIRECTORIES[@]}"; do - run_backend_checks "$DIR" - done + # for DIR in "${DIRECTORIES[@]}"; do + # run_backend_checks "$DIR" + # done else echo "🔍 Checking directory changes for existing branch: $BRANCH_NAME" if git diff --name-only --cached origin/"$BRANCH_NAME" | grep -q '^agenta-web/'; then run_frontend_checks fi - for DIR in "${DIRECTORIES[@]}"; do - if git diff --name-only --cached origin/"$BRANCH_NAME" | grep -q "^$DIR/"; then - run_backend_checks "$DIR" - fi - done + # for DIR in "${DIRECTORIES[@]}"; do + # if git diff --name-only --cached origin/"$BRANCH_NAME" | grep -q "^$DIR/"; then + # run_backend_checks "$DIR" + # fi + # done fi From 1ddcf2e6bea3330d0d1b6a32dd9edf9f5716eb70 Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Fri, 13 Dec 2024 15:43:33 +0600 Subject: [PATCH 16/16] fix(workflow): temporarily disabled auto commit --- .husky/pre-commit | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 31338ad6d7..f0481db762 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -11,10 +11,8 @@ if git diff --cached --name-only | grep -q '^agenta-web/'; then echo '⚠️ Formatting issues detected. Running Prettier to fix them...' npm run format-fix - # Stage the fixed files - git add . - - echo '✅ Formatting issues fixed and changes staged.' + echo '✅ Formatting issues fixed. Please stage the changes and commit the code again' + exit 1 fi cd "$ORIGINAL_DIR" || exit @@ -30,10 +28,8 @@ for DIR in "${DIRECTORIES[@]}"; do echo "⚠️ Formatting issues detected in $DIR. Running black to fix them..." black . - # Stage the fixed files - git add . - - echo "✅ Formatting issues fixed and changes staged in $DIR." + echo "✅ Formatting issues fixed Please stage the changes and commit the code again $DIR." + exit 1 fi cd "$ORIGINAL_DIR" || exit