mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-24 17:50:58 -05:00
feat: show error output when info is disabled (#5251)
In case of linting errors, print stdout and stderr (if present) at the ERROR level if users set LOG_LEVEL to NOTICE to avoid failures without any explanation.
This commit is contained in:
parent
49320c834b
commit
091eaa71e3
5 changed files with 53 additions and 7 deletions
8
Makefile
8
Makefile
|
@ -4,7 +4,7 @@
|
||||||
all: info docker test ## Run all targets.
|
all: info docker test ## Run all targets.
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: info validate-container-image-labels test-lib inspec lint-codebase test-default-config-files test-find lint-subset-files test-custom-ssl-cert test-non-default-workdir test-git-flags test-non-default-home-directory test-log-level test-linters ## Run the test suite
|
test: info validate-container-image-labels test-lib inspec lint-codebase test-default-config-files test-find lint-subset-files test-custom-ssl-cert test-non-default-workdir test-git-flags test-non-default-home-directory test-log-level test-linters-expect-failure-log-level-notice test-linters ## Run the test suite
|
||||||
|
|
||||||
# if this session isn't interactive, then we don't want to allocate a
|
# if this session isn't interactive, then we don't want to allocate a
|
||||||
# TTY, which would fail, but if it is interactive, we do want to attach
|
# TTY, which would fail, but if it is interactive, we do want to attach
|
||||||
|
@ -316,6 +316,12 @@ test-log-level: ## Run a test to check if there are conflicts with the LOG_LEVEL
|
||||||
$(SUPER_LINTER_TEST_CONTAINER_URL) \
|
$(SUPER_LINTER_TEST_CONTAINER_URL) \
|
||||||
"run_test_cases_log_level"
|
"run_test_cases_log_level"
|
||||||
|
|
||||||
|
.phony: test-linters-expect-failure-log-level-notice
|
||||||
|
test-linters-expect-failure-log-level-notice: ## Run the linters test suite expecting failures with a LOG_LEVEL set to NOTICE
|
||||||
|
$(CURDIR)/test/run-super-linter-tests.sh \
|
||||||
|
$(SUPER_LINTER_TEST_CONTAINER_URL) \
|
||||||
|
"run_test_cases_expect_failure_notice_log"
|
||||||
|
|
||||||
.phony: build-dev-container-image
|
.phony: build-dev-container-image
|
||||||
build-dev-container-image: ## Build commit linter container image
|
build-dev-container-image: ## Build commit linter container image
|
||||||
DOCKER_BUILDKIT=1 docker buildx build --load \
|
DOCKER_BUILDKIT=1 docker buildx build --load \
|
||||||
|
|
|
@ -318,7 +318,7 @@ function RunAdditionalInstalls() {
|
||||||
local MYPY_CACHE_DIRECTORY_PATH
|
local MYPY_CACHE_DIRECTORY_PATH
|
||||||
MYPY_CACHE_DIRECTORY_PATH="${GITHUB_WORKSPACE}/.mypy_cache"
|
MYPY_CACHE_DIRECTORY_PATH="${GITHUB_WORKSPACE}/.mypy_cache"
|
||||||
debug "Create MyPy cache directory: ${MYPY_CACHE_DIRECTORY_PATH}"
|
debug "Create MyPy cache directory: ${MYPY_CACHE_DIRECTORY_PATH}"
|
||||||
mkdir -v "${MYPY_CACHE_DIRECTORY_PATH}"
|
mkdir -p "${MYPY_CACHE_DIRECTORY_PATH}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###############################
|
###############################
|
||||||
|
|
|
@ -193,7 +193,16 @@ function LintCodebase() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${STDOUT_LINTER}" ]; then
|
if [ -n "${STDOUT_LINTER}" ]; then
|
||||||
info "Command output for ${FILE_TYPE}:\n------\n${STDOUT_LINTER}\n------"
|
local STDOUT_LINTER_LOG_MESSAGE
|
||||||
|
STDOUT_LINTER_LOG_MESSAGE="Command output for ${FILE_TYPE}:\n------\n${STDOUT_LINTER}\n------"
|
||||||
|
info "${STDOUT_LINTER_LOG_MESSAGE}"
|
||||||
|
|
||||||
|
if [ ${PARALLEL_COMMAND_RETURN_CODE} -ne 0 ]; then
|
||||||
|
local STDOUT_LINTER_FILE_PATH
|
||||||
|
STDOUT_LINTER_FILE_PATH="/tmp/super-linter-parallel-stdout-${FILE_TYPE}"
|
||||||
|
debug "Saving stdout for ${FILE_TYPE} to ${STDOUT_LINTER_FILE_PATH} in case we need it later"
|
||||||
|
printf '%s\n' "${STDOUT_LINTER_LOG_MESSAGE}" >"${STDOUT_LINTER_FILE_PATH}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
debug "Stdout for ${FILE_TYPE} is empty"
|
debug "Stdout for ${FILE_TYPE} is empty"
|
||||||
fi
|
fi
|
||||||
|
@ -204,7 +213,15 @@ function LintCodebase() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${STDERR_LINTER}" ]; then
|
if [ -n "${STDERR_LINTER}" ]; then
|
||||||
info "Stderr contents for ${FILE_TYPE}:\n------\n${STDERR_LINTER}\n------"
|
local STDERR_LINTER_LOG_MESSAGE
|
||||||
|
STDERR_LINTER_LOG_MESSAGE="Stderr contents for ${FILE_TYPE}:\n------\n${STDERR_LINTER}\n------"
|
||||||
|
info "${STDERR_LINTER_LOG_MESSAGE}"
|
||||||
|
if [ ${PARALLEL_COMMAND_RETURN_CODE} -ne 0 ]; then
|
||||||
|
local STDERR_LINTER_FILE_PATH
|
||||||
|
STDERR_LINTER_FILE_PATH="/tmp/super-linter-parallel-stderr-${FILE_TYPE}"
|
||||||
|
debug "Saving stderr for ${FILE_TYPE} to ${STDERR_LINTER_FILE_PATH} in case we need it later"
|
||||||
|
printf '%s\n' "${STDERR_LINTER_LOG_MESSAGE}" >"${STDERR_LINTER_FILE_PATH}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
debug "Stderr for ${FILE_TYPE} is empty"
|
debug "Stderr for ${FILE_TYPE} is empty"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -626,6 +626,25 @@ Footer() {
|
||||||
|
|
||||||
if [[ ${ERROR_COUNTER} -ne 0 ]]; then
|
if [[ ${ERROR_COUNTER} -ne 0 ]]; then
|
||||||
error "Errors found in ${LANGUAGE}"
|
error "Errors found in ${LANGUAGE}"
|
||||||
|
# Print output as error in case users disabled the INFO level so they
|
||||||
|
# get feedback
|
||||||
|
if [[ "${LOG_VERBOSE}" != "true" ]]; then
|
||||||
|
local STDOUT_LINTER_FILE_PATH
|
||||||
|
STDOUT_LINTER_FILE_PATH="/tmp/super-linter-parallel-stdout-${LANGUAGE}"
|
||||||
|
if [[ -e "${STDOUT_LINTER_FILE_PATH}" ]]; then
|
||||||
|
error "$(cat "${STDOUT_LINTER_FILE_PATH}")"
|
||||||
|
else
|
||||||
|
debug "Stdout output file path for ${LANGUAGE} (${STDOUT_LINTER_FILE_PATH}) doesn't exist"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local STDERR_LINTER_FILE_PATH
|
||||||
|
STDERR_LINTER_FILE_PATH="/tmp/super-linter-parallel-stderr-${LANGUAGE}"
|
||||||
|
if [[ -e "${STDERR_LINTER_FILE_PATH}" ]]; then
|
||||||
|
error "$(cat "${STDERR_LINTER_FILE_PATH}")"
|
||||||
|
else
|
||||||
|
debug "Stderr output file path for ${LANGUAGE} (${STDERR_LINTER_FILE_PATH}) doesn't exist"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
CallStatusAPI "${LANGUAGE}" "error"
|
CallStatusAPI "${LANGUAGE}" "error"
|
||||||
SUPER_LINTER_EXIT_CODE=1
|
SUPER_LINTER_EXIT_CODE=1
|
||||||
debug "Setting super-linter exit code to ${SUPER_LINTER_EXIT_CODE} because there were errors for ${LANGUAGE}"
|
debug "Setting super-linter exit code to ${SUPER_LINTER_EXIT_CODE} because there were errors for ${LANGUAGE}"
|
||||||
|
@ -687,13 +706,13 @@ cleanup() {
|
||||||
local -ri EXIT_CODE=$?
|
local -ri EXIT_CODE=$?
|
||||||
|
|
||||||
debug "Removing temporary files and directories"
|
debug "Removing temporary files and directories"
|
||||||
rm -rfv \
|
rm -rf \
|
||||||
"${GITHUB_WORKSPACE}/.mypy_cache" \
|
"${GITHUB_WORKSPACE}/.mypy_cache" \
|
||||||
"${GITHUB_WORKSPACE}/logback.log"
|
"${GITHUB_WORKSPACE}/logback.log"
|
||||||
|
|
||||||
if [ "${SUPER_LINTER_COPIED_R_LINTER_RULES_FILE}" == "true" ]; then
|
if [ "${SUPER_LINTER_COPIED_R_LINTER_RULES_FILE}" == "true" ]; then
|
||||||
debug "Deleting ${R_RULES_FILE_PATH_IN_ROOT} because super-linter created it."
|
debug "Deleting ${R_RULES_FILE_PATH_IN_ROOT} because super-linter created it."
|
||||||
rm -rfv "${R_RULES_FILE_PATH_IN_ROOT}"
|
rm -rf "${R_RULES_FILE_PATH_IN_ROOT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Define this variable here so we can rely on it as soon as possible
|
# Define this variable here so we can rely on it as soon as possible
|
||||||
|
@ -703,7 +722,6 @@ cleanup() {
|
||||||
debug "Moving log file from ${LOG_TEMP} to ${LOG_FILE_PATH}"
|
debug "Moving log file from ${LOG_TEMP} to ${LOG_FILE_PATH}"
|
||||||
mv \
|
mv \
|
||||||
--force \
|
--force \
|
||||||
--verbose \
|
|
||||||
"${LOG_TEMP}" "${LOG_FILE_PATH}"
|
"${LOG_TEMP}" "${LOG_FILE_PATH}"
|
||||||
else
|
else
|
||||||
debug "Skipping the moving of the log file from ${LOG_TEMP} to ${LOG_FILE_PATH}"
|
debug "Skipping the moving of the log file from ${LOG_TEMP} to ${LOG_FILE_PATH}"
|
||||||
|
|
|
@ -23,6 +23,11 @@ run_test_cases_log_level() {
|
||||||
LOG_LEVEL="NOTICE"
|
LOG_LEVEL="NOTICE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_test_cases_expect_failure_notice_log() {
|
||||||
|
run_test_cases_expect_failure
|
||||||
|
LOG_LEVEL="NOTICE"
|
||||||
|
}
|
||||||
|
|
||||||
run_test_cases_non_default_home() {
|
run_test_cases_non_default_home() {
|
||||||
run_test_cases_expect_success
|
run_test_cases_expect_success
|
||||||
COMMAND_TO_RUN+=(-e HOME=/tmp)
|
COMMAND_TO_RUN+=(-e HOME=/tmp)
|
||||||
|
|
Loading…
Reference in a new issue