From 0c1a1cd0d745c44c8e24b14f21c7dcaab64fa795 Mon Sep 17 00:00:00 2001 From: burnettk Date: Sat, 17 Dec 2022 23:43:47 -0500 Subject: [PATCH] give run_pyl a pre-commit type mode where it checks to see what you changed before running checks --- bin/pre | 11 +++++++++++ bin/run_pyl | 50 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 14 deletions(-) create mode 100755 bin/pre diff --git a/bin/pre b/bin/pre new file mode 100755 index 000000000..fa89ecc79 --- /dev/null +++ b/bin/pre @@ -0,0 +1,11 @@ +#!/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 + +script_dir="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +"${script_dir}/run_pyl" pre diff --git a/bin/run_pyl b/bin/run_pyl index d3abd7fc6..64446662a 100755 --- a/bin/run_pyl +++ b/bin/run_pyl @@ -16,6 +16,17 @@ react_projects=( spiffworkflow-frontend ) +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 + 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 '' } @@ -50,23 +61,34 @@ function run_pre_commmit() { } for react_project in "${react_projects[@]}" ; do - pushd "$react_project" - npm run lint:fix - popd + # 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 done for python_project in "${python_projects[@]}" ; do - pushd "$python_project" - run_fix_docstrings || run_fix_docstrings - run_autoflake || run_autoflake - popd + 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 done -run_pre_commmit || run_pre_commmit -for python_project in "${python_projects[@]}"; do - pushd "$python_project" - poetry install - poetry run mypy $(get_python_dirs) - poetry run coverage run --parallel -m pytest - popd +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 done