2022-10-27 13:15:56 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
function error_handler() {
|
2024-01-16 19:47:25 +00:00
|
|
|
echo >&2 "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
|
2022-10-27 13:15:56 +00:00
|
|
|
exit "$2"
|
|
|
|
}
|
|
|
|
trap 'error_handler ${LINENO} $?' ERR
|
|
|
|
set -o errtrace -o errexit -o nounset -o pipefail
|
|
|
|
|
|
|
|
python_projects=(
|
|
|
|
spiffworkflow-backend
|
|
|
|
)
|
|
|
|
|
2022-11-16 18:03:59 +00:00
|
|
|
react_projects=(
|
|
|
|
spiffworkflow-frontend
|
|
|
|
)
|
|
|
|
|
2022-12-18 04:43:47 +00:00
|
|
|
subcommand="${1:-}"
|
|
|
|
|
2022-11-16 16:42:56 +00:00
|
|
|
function get_python_dirs() {
|
|
|
|
(git ls-tree -r HEAD --name-only | grep -E '\.py$' | awk -F '/' '{print $1}' | sort | uniq | grep -v '\.' | grep -Ev '^(bin|migrations)$') || echo ''
|
|
|
|
}
|
|
|
|
|
2023-05-30 11:15:49 +00:00
|
|
|
function run_autofixers() {
|
2023-08-10 12:54:49 +00:00
|
|
|
python_dirs="$(get_python_dirs) bin"
|
2023-09-07 14:10:44 +00:00
|
|
|
# shellcheck disable=2086
|
2024-04-10 16:44:13 +00:00
|
|
|
poetry run ruff check --fix $python_dirs || echo ''
|
2022-10-27 13:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_pre_commmit() {
|
|
|
|
poetry run pre-commit run --verbose --all-files
|
|
|
|
}
|
|
|
|
|
2024-01-16 19:47:25 +00:00
|
|
|
for react_project in "${react_projects[@]}"; do
|
2022-12-18 04:43:47 +00:00
|
|
|
# if pre, only do stuff when there are changes
|
2023-05-31 20:28:56 +00:00
|
|
|
if [[ -n "$(git status --porcelain "$react_project")" ]]; then
|
2022-12-18 04:43:47 +00:00
|
|
|
pushd "$react_project"
|
|
|
|
npm run lint:fix
|
|
|
|
popd
|
|
|
|
fi
|
2022-11-16 18:03:59 +00:00
|
|
|
done
|
|
|
|
|
2024-01-16 19:47:25 +00:00
|
|
|
for python_project in "${python_projects[@]}"; do
|
2023-05-31 20:28:56 +00:00
|
|
|
# if pre, only do stuff when there are changes
|
2022-12-18 04:43:47 +00:00
|
|
|
if [[ "$subcommand" != "pre" ]] || [[ -n "$(git status --porcelain "$python_project")" ]]; then
|
|
|
|
pushd "$python_project"
|
2023-05-30 11:15:49 +00:00
|
|
|
run_autofixers || run_autofixers
|
2022-12-18 04:43:47 +00:00
|
|
|
popd
|
|
|
|
fi
|
2022-10-27 13:15:56 +00:00
|
|
|
done
|
2022-12-18 04:43:47 +00:00
|
|
|
|
|
|
|
if [[ "$subcommand" != "pre" ]] || [[ -n "$(git status --porcelain "spiffworkflow-backend")" ]]; then
|
|
|
|
# rune_pre_commit only applies to spiffworkflow-backend at the moment
|
|
|
|
run_pre_commmit || run_pre_commmit
|
|
|
|
fi
|
|
|
|
|
2023-09-21 21:47:18 +00:00
|
|
|
function clear_log_file() {
|
|
|
|
unit_testing_log_file="./log/unit_testing.log"
|
|
|
|
if [[ -f "$unit_testing_log_file" ]]; then
|
2024-01-16 19:47:25 +00:00
|
|
|
>"$unit_testing_log_file"
|
2023-09-21 21:47:18 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-12-18 04:43:47 +00:00
|
|
|
for python_project in "${python_projects[@]}"; do
|
|
|
|
if [[ "$subcommand" != "pre" ]] || [[ -n "$(git status --porcelain "$python_project")" ]]; then
|
|
|
|
pushd "$python_project"
|
|
|
|
poetry install
|
|
|
|
poetry run mypy $(get_python_dirs)
|
2023-09-21 21:47:18 +00:00
|
|
|
clear_log_file
|
2023-07-12 14:14:49 +00:00
|
|
|
./bin/tests-par
|
2022-12-18 04:43:47 +00:00
|
|
|
popd
|
|
|
|
fi
|
2022-10-27 13:15:56 +00:00
|
|
|
done
|