From 9a909c5d1d0da0ad4ca7ceec371d10e1e90a871c Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 6 Jul 2020 18:06:58 +0100 Subject: [PATCH] Output transformation (with error messages or simpler) (#1) * Output transformation (with error messages or simpler) * colon causes issues when transforming TAP to XUnit --- Dockerfile | 3 ++- README.md | 6 ++++-- lib/linter.sh | 30 ++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ce1ee696..9b8e748b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -186,7 +186,8 @@ ENV GITHUB_SHA=${GITHUB_SHA} \ ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ DISABLE_ERRORS=${DISABLE_ERRORS} \ OUTPUT_FORMAT=${OUTPUT_FORMAT} \ - OUTPUT_FOLDER=${OUTPUT_FOLDER} + OUTPUT_FOLDER=${OUTPUT_FOLDER} \ + OUTPUT_DETAILS=${OUTPUT_DETAILS} ############################# # Copy scripts to container # diff --git a/README.md b/README.md index 6f790344..ad1a1961 100644 --- a/README.md +++ b/README.md @@ -171,8 +171,10 @@ and won't run anything unexpected. | **ACTIONS_RUNNER_DEBUG** | `false` | Flag to enable additional information about the linter, versions, and additional output. | | **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. | | **DEFAULT_WORKSPACE** | `/tmp/lint` | The location containing files to lint if you are running locally. | -| **OUTPUT_FORMAT** | `` | The report format to be generated, besides the stdout one. Supported formats: tap | -| **OUTPUT_FOLDER** | `super-linter.report` | The location where the output reporting will be generated to. | +| **OUTPUT_FORMAT** | `` | The report format to be generated, besides the stdout one. Supported formats: tap | +| **OUTPUT_FOLDER** | `super-linter.report` | The location where the output reporting will be generated to. | +| **OUTPUT_DETAILS** | `simpler` | What level of details to be reported. Supported formats: simpler or detailed. | + ### Template rules files You can use the **GitHub** **Super-Linter** *with* or *without* your own personal rules sets. This allows for greater flexibility for each individual code base. The Template rules all try to follow the standards we believe should be enabled at the basic level. diff --git a/lib/linter.sh b/lib/linter.sh index 87cdffeb..d5576f9c 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -139,6 +139,7 @@ DEFAULT_IFS="$IFS" # Get the Default IFS for updating ############## OUTPUT_FORMAT="${OUTPUT_FORMAT}" # Output format to be generated. Default none OUTPUT_FOLDER="${OUTPUT_FOLDER:-super-linter.report}" # Folder where the reports are generated. Default super-linter.report +OUTPUT_DETAILS="${OUTPUT_DETAILS:-simpler}" # What level of details. (simpler or detailed). Default simpler REPORT_OUTPUT_FOLDER="${DEFAULT_WORKSPACE}/${OUTPUT_FOLDER}" ########################## @@ -577,7 +578,13 @@ LintAnsibleFiles() ####################################################### if IsTAP ; then echo "not ok ${INDEX} - ${FILE}" >> "${TMPFILE}" - printf " ---\n message:[%s]\n ..." "$LINT_CMD" >> "${TMPFILE}" + ########################################## + # Report the detailed message if enabled # + ########################################## + DETAILED_MSG=$(TransformTAPDetails "$LINT_CMD") + if [ -n "${DETAILED_MSG}" ] ; then + printf " ---\n message: %s\n ..." "$DETAILED_MSG" >> "${TMPFILE}" + fi fi else ########### @@ -2034,7 +2041,13 @@ LintCodebase() ####################################################### if IsTAP ; then echo "not ok ${INDEX} - ${FILE}" >> "${TMPFILE}" - printf " ---\n message:[%s]\n ..." "$LINT_CMD" >> "${TMPFILE}" + ########################################## + # Report the detailed message if enabled # + ########################################## + DETAILED_MSG=$(TransformTAPDetails "$LINT_CMD") + if [ -n "${DETAILED_MSG}" ] ; then + printf " ---\n message: %s\n ..." "$DETAILED_MSG" >> "${TMPFILE}" + fi fi else @@ -2430,6 +2443,19 @@ IsTAP() return 1 fi } +################################################################################ +#### Function TransformTAPDetails ############################################## +TransformTAPDetails() +{ + DATA=$1 + if [ -n "${DATA}" ] && [ "${OUTPUT_DETAILS}" == "detailed" ] ; then + ######################################################### + # Transform new lines to \\n, remove colours and colons # + ######################################################### + echo "${DATA}" | awk 'BEGIN{RS="\n";ORS="\\n"}1' | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" | tr ':' ' ' + fi +} + ################################################################################ ############################### MAIN ########################################### ################################################################################