2022-10-27 13:15:56 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
function error_handler() {
|
|
|
|
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
|
|
|
|
exit "$2"
|
|
|
|
}
|
|
|
|
trap 'error_handler ${LINENO} $?' ERR
|
|
|
|
set -o errtrace -o errexit -o nounset -o pipefail
|
|
|
|
|
|
|
|
python_projects=(
|
|
|
|
flask-bpmn
|
|
|
|
spiffworkflow-backend
|
|
|
|
)
|
|
|
|
|
2022-11-16 18:03:59 +00:00
|
|
|
react_projects=(
|
|
|
|
spiffworkflow-frontend
|
|
|
|
)
|
|
|
|
|
2022-12-18 04:43:47 +00:00
|
|
|
subcommand="${1:-}"
|
|
|
|
|
|
|
|
if [[ "$subcommand" == "pre" ]]; then
|
|
|
|
if [[ -n "$(git status --porcelain SpiffWorkflow)" ]]; then
|
|
|
|
echo "SpiffWorkflow has uncommitted changes. Running its test suite."
|
|
|
|
pushd SpiffWorkflow
|
|
|
|
make tests-par # run tests in parallel
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
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 ''
|
|
|
|
}
|
|
|
|
|
2022-11-28 20:26:50 +00:00
|
|
|
function run_fix_docstrings() {
|
|
|
|
if command -v fix_python_docstrings >/dev/null ; then
|
|
|
|
fix_python_docstrings $(get_top_level_directories_containing_python_files)
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-11-16 16:42:56 +00:00
|
|
|
function run_autoflake() {
|
2023-01-13 16:29:45 +00:00
|
|
|
# checking command -v autoflake8 is not good enough, since the asdf shim may be installed, which will make command -v succeed,
|
|
|
|
# but autoflake8 may not have been pip installed inside the correct version of python.
|
|
|
|
if ! autoflake8 --help >/dev/null ; then
|
2022-11-16 16:42:56 +00:00
|
|
|
pip install autoflake8
|
|
|
|
asdf reshim python
|
|
|
|
fi
|
|
|
|
|
2023-01-13 16:29:45 +00:00
|
|
|
if ! autoflake --help >/dev/null ; then
|
|
|
|
pip install autoflake
|
|
|
|
asdf reshim python
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! autopep8 --help >/dev/null ; then
|
2022-11-16 16:42:56 +00:00
|
|
|
pip install autopep8
|
|
|
|
asdf reshim python
|
|
|
|
fi
|
|
|
|
|
|
|
|
python_dirs=$(get_python_dirs)
|
|
|
|
python_files=$(find $python_dirs -type f -name "*.py" ! -name '.null-ls*' ! -name '_null-ls*')
|
|
|
|
|
|
|
|
autoflake8 --in-place --remove-unused-variables --remove-duplicate-keys --expand-star-imports --exit-zero-even-if-changed $python_files
|
|
|
|
autoflake --in-place --remove-all-unused-imports $python_files
|
|
|
|
autopep8 --in-place $python_files
|
2022-10-27 13:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_pre_commmit() {
|
|
|
|
poetry run pre-commit run --verbose --all-files
|
|
|
|
}
|
|
|
|
|
2022-11-16 18:03:59 +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
|
|
|
|
if [[ "$subcommand" != "pre" ]] || [[ -n "$(git status --porcelain "$react_project")" ]]; then
|
|
|
|
pushd "$react_project"
|
|
|
|
npm run lint:fix
|
|
|
|
popd
|
|
|
|
fi
|
2022-11-16 18:03:59 +00:00
|
|
|
done
|
|
|
|
|
2022-10-27 13:15:56 +00:00
|
|
|
for python_project in "${python_projects[@]}" ; do
|
2022-12-18 04:43:47 +00:00
|
|
|
if [[ "$subcommand" != "pre" ]] || [[ -n "$(git status --porcelain "$python_project")" ]]; then
|
|
|
|
pushd "$python_project"
|
|
|
|
run_fix_docstrings || run_fix_docstrings
|
|
|
|
run_autoflake || run_autoflake
|
|
|
|
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
|
|
|
|
|
|
|
|
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)
|
|
|
|
poetry run coverage run --parallel -m pytest
|
|
|
|
popd
|
|
|
|
fi
|
2022-10-27 13:15:56 +00:00
|
|
|
done
|