| | |
| | | #!/bin/sh |
| | | #!/usr/bin/env bash |
| | | . "$(dirname -- "$0")/_/husky.sh" |
| | | |
| | | # get the list of modified files |
| | | files=$(git diff --cached --name-only) |
| | | |
| | |
| | | |
| | | for file in $files |
| | | do |
| | | # Use POSIX compliant pattern matching |
| | | case "$file" in |
| | | api/*.py) |
| | | # set api_modified flag to true |
| | | api_modified=true |
| | | ;; |
| | | web/*) |
| | | # set web_modified flag to true |
| | | web_modified=true |
| | | ;; |
| | | esac |
| | | if [[ $file == "api/"* && $file == *.py ]]; then |
| | | # set api_modified flag to true |
| | | api_modified=true |
| | | elif [[ $file == "web/"* ]]; then |
| | | # set web_modified flag to true |
| | | web_modified=true |
| | | fi |
| | | done |
| | | |
| | | # run linters based on the modified modules |
| | |
| | | if $api_modified; then |
| | | echo "Running Ruff linter on api module" |
| | | |
| | | # python style checks rely on `ruff` in path |
| | | if ! command -v ruff &> /dev/null; then |
| | | echo "Installing linting tools (Ruff, dotenv-linter ...) ..." |
| | | poetry install -C api --only lint |
| | | fi |
| | | |
| | | # run Ruff linter auto-fixing |
| | | uv run --project api --dev ruff check --fix ./api |
| | | ruff check --fix ./api |
| | | |
| | | # run Ruff linter checks |
| | | uv run --project api --dev ruff check ./api || status=$? |
| | | ruff check --preview ./api || status=$? |
| | | |
| | | status=${status:-0} |
| | | |
| | |
| | | if $web_modified; then |
| | | echo "Running ESLint on web module" |
| | | cd ./web || exit 1 |
| | | lint-staged |
| | | npx lint-staged |
| | | |
| | | echo "Running unit tests check" |
| | | modified_files=$(git diff --cached --name-only -- utils | grep -v '\.spec\.ts$' || true) |
| | |
| | | # check if the test file exists |
| | | if [ -f "../$test_file" ]; then |
| | | echo "Detected changes in $file, running corresponding unit tests..." |
| | | pnpm run test "../$test_file" |
| | | npm run test "../$test_file" |
| | | |
| | | if [ $? -ne 0 ]; then |
| | | echo "Unit tests failed. Please fix the errors before committing." |