potiuk commented on a change in pull request #10368:
URL: https://github.com/apache/airflow/pull/10368#discussion_r472953178
##########
File path: scripts/ci/libraries/_verbosity.sh
##########
@@ -28,58 +27,87 @@ function check_verbose_setup {
# In case "VERBOSE" is set to "true" (--verbose flag in Breeze) all docker
commands run will be
# printed before execution
function verbose_docker {
- if [[ ${VERBOSE:="false"} == "true" && ${VERBOSE_COMMANDS:=} != "true" ]];
then
- # do not print echo if VERBOSE_COMMAND is set (set -x does it already)
- echo "docker" "${@}"
+ if [[ ${VERBOSE:="false"} == "true" && \
+ # do not print echo if VERBOSE_COMMAND is set (set -x does it already)
+ ${VERBOSE_COMMANDS:=} != "true" && \
+ # And when generally printing info is disabled
+ ${PRINT_INFO_FROM_SCRIPTS} == "true" ]]; then
+ >&2 echo "docker" "${@}"
+ fi
+ if [[ ${PRINT_INFO_FROM_SCRIPTS} == "false" ]]; then
+ docker "${@}" >>"${OUTPUT_LOG}" 2>&1
+ else
+ docker "${@}" 2>&1 | tee -a "${OUTPUT_LOG}"
+ fi
+ EXIT_CODE="$?"
+ if [[ ${EXIT_CODE} == "0" ]]; then
+ # No matter if "set -e" is used the log will be removed on success.
+ # This way in the output log we only see the most recent failed
command and what was echoed before
+ rm -f "${OUTPUT_LOG}"
fi
- docker "${@}"
+ return "${EXIT_CODE}"
}
# In case "VERBOSE" is set to "true" (--verbose flag in Breeze) all helm
commands run will be
# printed before execution
function verbose_helm {
if [[ ${VERBOSE:="false"} == "true" && ${VERBOSE_COMMANDS:=} != "true" ]];
then
# do not print echo if VERBOSE_COMMAND is set (set -x does it already)
- echo "helm" "${@}"
+ >&2 echo "helm" "${@}"
+ fi
+ helm "${@}" | tee -a "${OUTPUT_LOG}"
+ if [[ ${EXIT_CODE} == "0" ]]; then
+ # No matter if "set -e" is used the log will be removed on success.
+ rm -f "${OUTPUT_LOG}"
fi
- helm "${@}"
}
# In case "VERBOSE" is set to "true" (--verbose flag in Breeze) all kubectl
commands run will be
# printed before execution
function verbose_kubectl {
if [[ ${VERBOSE:="false"} == "true" && ${VERBOSE_COMMANDS:=} != "true" ]];
then
# do not print echo if VERBOSE_COMMAND is set (set -x does it already)
- echo "kubectl" "${@}"
+ >&2 echo "kubectl" "${@}"
+ fi
+ kubectl "${@}" | tee -a "${OUTPUT_LOG}"
+ if [[ ${EXIT_CODE} == "0" ]]; then
+ # No matter if "set -e" is used the log will be removed on success.
+ rm -f "${OUTPUT_LOG}"
fi
- kubectl "${@}"
}
# In case "VERBOSE" is set to "true" (--verbose flag in Breeze) all kind
commands run will be
# printed before execution
function verbose_kind {
if [[ ${VERBOSE:="false"} == "true" && ${VERBOSE_COMMANDS:=} != "true" ]];
then
# do not print echo if VERBOSE_COMMAND is set (set -x does it already)
- echo "kind" "${@}"
+ >&2 echo "kind" "${@}"
fi
+ # kind outputs nice output on terminal.
kind "${@}"
}
-
-# In case "VERBOSE" is set to "true" (--verbose flag in Breeze) all docker
commands run will be
-# printed before execution
-function verbose_docker_hide_output_on_success {
- if [[ ${VERBOSE:="false"} == "true" && ${VERBOSE_COMMANDS:=} != "true" ]];
then
- # do not print echo if VERBOSE_COMMAND is set (set -x does it already)
- echo "docker" "${@}"
- fi
- docker "${@}" >>"${OUTPUT_LOG}" 2>&1
-}
-
-
# Prints verbose information in case VERBOSE variable is set
function print_info() {
- if [[ ${VERBOSE:="false"} == "true" ]]; then
+ if [[ ${VERBOSE:="false"} == "true" && ${PRINT_INFO_FROM_SCRIPTS} ==
"true" ]]; then
echo "$@"
fi
}
+
+function set_verbosity() {
+ # whether verbose output should be produced
+ export VERBOSE=${VERBOSE:="false"}
+
+ # whether every bash statement should be printed as they are executed
+ export VERBOSE_COMMANDS=${VERBOSE_COMMANDS:="false"}
+
+ # whether the output from script should be printed at all
+ export PRINT_INFO_FROM_SCRIPTS=${PRINT_INFO_FROM_SCRIPTS:="true"}
+}
+
+set_verbosity
+
+alias docker=verbose_docker
+alias kubectl=verbose_kubectl
+alias helm=verbose_helm
+alias kind=verbose_kind
Review comment:
Alias exists only until the script ends. Hoever I read a bit more about
aliases and I think I will get rid of those and replace with functions. They
provide much the same functionality and there are no special exceptions to them
when it comes to "pre-commit" non-interactive bash scripts.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]