script/test: ignore python checks if not available (#6530)

beep
Axel Navarro 2021-09-15 20:10:16 -03:00 committed by GitHub
parent 3447744e09
commit 6d318892f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 14 deletions

View File

@ -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.