From 6d318892f87cd27211b1c28d0ca4f2eda2721598 Mon Sep 17 00:00:00 2001 From: Axel Navarro Date: Wed, 15 Sep 2021 20:10:16 -0300 Subject: [PATCH] script/test: ignore python checks if not available (#6530) --- scripts/test.sh | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/scripts/test.sh b/scripts/test.sh index 1a244e587a..949a81b9db 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -9,6 +9,40 @@ # NOTE: must be run from the repository root directory to correctly work! # NOTE: `set -e` is applied conditionally only if needed. +# check if a command is available to run in the system +function exists { + command -v "$1" >/dev/null 2>&1 +} + +# Wrapper around black as it outputs everything to stderr, +# but we want to only print if there are actual errors, and not +# the "All done!" success message. +function run_black { + # skip black check if command is not available in the system. + if [ "$CI" != "true" ] && ! exists black; then + echo "Skipping black check, command not available." + return 0 + fi + + # we want to ignore the exit code from black on failure, so that we can + # do the conditional printing below + errs=$(black scripts --check 2>&1 || true) + if [[ ${errs} != "All done!"* ]]; then + echo -e "${errs}" >&2 + return 1 + fi +} + +function run_flake8 { + # skip flake8 check if command is not available in the system. + if [ "$CI" != "true" ] && ! exists flake8; then + echo "Skipping flake8 check, command not available." + return 0 + fi + + flake8 scripts +} + # Default test function, ran by `npm test`. function run_tests { markdownlint pages*/**/*.md @@ -17,20 +51,7 @@ function run_tests { tldr-lint --ignore "TLDR003,TLDR004,TLDR005,TLDR015,TLDR104" ${f} done run_black - flake8 scripts -} - -# Wrapper around black as it outputs everything to stderr, -# but we want to only print if there are actual errors, and not -# the "All done!" success message. -function run_black { - # we want to ignore the exit code from black on failure, so that we can - # do the conditional printing below - errs=$(black scripts --check 2>&1 || true) - if [[ ${errs} != "All done!"* ]]; then - echo -e "${errs}" >&2 - return 1 - fi + run_flake8 } # Special test function for GitHub Actions pull request builds.