From ddbc96bd23afb1333eacb0005555323adde8973d Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 23 Jun 2020 15:25:12 +0100 Subject: [PATCH] Support TAP reporting format --- .gitignore | 3 +++ Dockerfile | 4 +++- README.md | 2 ++ lib/linter.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ad46b308..26f92ccf 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ typings/ # next.js build output .next + +# default output report +super-linter.report \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 78f9aea8..50b13f30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -171,7 +171,9 @@ ENV GITHUB_SHA=${GITHUB_SHA} \ RUN_LOCAL=${RUN_LOCAL} \ TEST_CASE_RUN=${TEST_CASE_RUN} \ ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ - DISABLE_ERRORS=${DISABLE_ERRORS} + DISABLE_ERRORS=${DISABLE_ERRORS} \ + OUTPUT_FORMAT=${OUTPUT_FORMAT} \ + OUTPUT_FOLDER=${OUTPUT_FOLDER} ############################# # Copy scripts to container # diff --git a/README.md b/README.md index 5cc133b3..db767737 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,8 @@ 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. | ### 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 862adf9a..12826889 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -125,6 +125,13 @@ READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files c TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors +############## +# Format # +############## +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 +REPORT_OUTPUT_FOLDER="${DEFAULT_WORKSPACE}/${OUTPUT_FOLDER}" + ########################## # Array of changed files # ########################## @@ -1782,6 +1789,16 @@ LintCodebase() echo "$LINE" done + #################################### + # Prepare context if OUTPUT_FORMAT # + #################################### + if [ -n "${OUTPUT_FORMAT}" ] ; then + TMPFILE=$(mktemp -q /tmp/super-linter.XXXXXX) + INDEX=0 + mkdir -p "${REPORT_OUTPUT_FOLDER}" + REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" + fi + ################## # Lint the files # ################## @@ -1803,6 +1820,8 @@ LintCodebase() continue fi + (("INDEX++")) + ############## # File print # ############## @@ -1846,13 +1865,37 @@ LintCodebase() echo "ERROR:[$LINT_CMD]" # Increment the error count (("ERRORS_FOUND_$FILE_TYPE++")) + + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if [ -n "${OUTPUT_FORMAT}" ] ; then + echo "nok ok ${INDEX} - ${FILE}" >> "${TMPFILE}" + echo " ERROR:[$LINT_CMD]" >> "${TMPFILE}" + fi + else ########### # Success # ########### echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" + + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if [ -n "${OUTPUT_FORMAT}" ] ; then + echo "ok ${INDEX} - ${FILE}" >> "${TMPFILE}" + fi fi done + + ################################# + # Generate report in TAP format # + ################################# + if [ -n "${OUTPUT_FORMAT}" ] && [ ${INDEX} -gt 0 ] ; then + echo "1..${INDEX}" > "${REPORT_OUTPUT_FILE}" + cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" + fi fi } ################################################################################ @@ -2073,6 +2116,14 @@ Footer() echo "----------------------------------------------" echo "" + + ################################### + # Prints output report if enabled # + ################################### + if [ -z "${FORMAT_REPORT}" ] ; then + echo "Reports generated in folder ${REPORT_OUTPUT_FOLDER}" + fi + ############################## # Prints for errors if found # ############################## @@ -2201,6 +2252,17 @@ RunTestCases() ########## Header +############################################################## +# check flag for validating the report folder does not exist # +############################################################## +if [ -n "${OUTPUT_FORMAT}" ]; then + if [ -d "${REPORT_OUTPUT_FOLDER}" ] ; then + echo "ERROR! Found ${REPORT_OUTPUT_FOLDER}" + echo "Please remove the folder and try again." + exit 1 + fi +fi + ####################### # Get GitHub Env Vars # #######################