From c0441b2844b5daf655b739a0c61b8154ee1370c9 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Mon, 2 Nov 2020 22:39:34 +0100 Subject: [PATCH 1/3] Use the already-defined linter names array to print linter versions --- Dockerfile | 2 +- lib/linter.sh | 24 ++++++++++---- lib/linterVersions.sh | 73 ++++++------------------------------------- 3 files changed, 29 insertions(+), 70 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9a2f7585..dc79a68f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -340,7 +340,7 @@ COPY TEMPLATES /action/lib/.automation ################################### # Run to build file with versions # ################################### -RUN /action/lib/linterVersions.sh +RUN ACTIONS_RUNNER_DEBUG=true WRITE_LINTER_VERSIONS_FILE=true /action/lib/linter.sh ##################################4 # Run validations of built image # diff --git a/lib/linter.sh b/lib/linter.sh index 58f35c97..a11a79e8 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -324,6 +324,18 @@ GetLinterVersions() { debug "---------------------------------------------" debug "Linter Version Info:" + if ! [ -e "${VERSION_FILE}" ] && [ "${WRITE_LINTER_VERSIONS_FILE}" = "true" ]; then + debug "Building linter version file..." + # shellcheck source=/dev/null + source /action/lib/linterVersions.sh # Source the function script(s) + if BuildLinterVersions "${VERSION_FILE}" "${LINTER_NAMES_ARRAY[@]}"; then + info "Linter version file built correctly." + exit + else + fatal "Error while building the versions file." + fi + fi + ################################ # Cat the linter versions file # ################################ @@ -339,7 +351,7 @@ GetLinterVersions() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Failure - warn "Failed to view version file:[${VERSION_FILE}]" + fatal "Failed to view version file:[${VERSION_FILE}]" else # Success debug "${CAT_CMD}" @@ -1162,6 +1174,11 @@ if [ -n "${OUTPUT_FORMAT}" ]; then fi fi +################################## +# Get and print all version info # +################################## +GetLinterVersions + ####################### # Get GitHub Env Vars # ####################### @@ -1262,11 +1279,6 @@ for i in "${!LINTER_COMMANDS_ARRAY[@]}"; do done debug "---------------------------------------------" -################################## -# Get and print all version info # -################################## -GetLinterVersions - ########################################### # Build the list of files for each linter # ########################################### diff --git a/lib/linterVersions.sh b/lib/linterVersions.sh index 562a6dd0..2148ba42 100755 --- a/lib/linterVersions.sh +++ b/lib/linterVersions.sh @@ -1,49 +1,10 @@ #!/usr/bin/env bash -################################################################################ -################################################################################ -########### Super-Linter (Get the linter versions) @admiralawkbar ############## -################################################################################ -################################################################################ - -########### -# Globals # -########### -(( LOG_TRACE=LOG_DEBUG=LOG_VERBOSE=LOG_NOTICE=LOG_WARN=LOG_ERROR="true" )) # Enable all loging -export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR - -######################### -# Source Function Files # -######################### -# shellcheck source=/dev/null -source /action/lib/log.sh # Source the function script(s) - -########### -# GLOBALS # -########### -VERSION_FILE='/action/lib/linter-versions.txt' # File to store linter versions -ARM_TTK_PSD1='/usr/bin/arm-ttk' # Powershell var - -####################################### -# Linter array for information prints # -####################################### -LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'bash-exec' 'black' 'cfn-lint' 'checkstyle' 'chktex' 'clj-kondo' 'coffeelint' - 'dotnet-format' 'dart' 'dockerfilelint' 'dotenv-linter' 'editorconfig-checker' 'eslint' 'flake8' 'golangci-lint' - 'hadolint' 'htmlhint' 'isort' 'jsonlint' 'kubeval' 'ktlint' 'lintr' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' - 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'shfmt' 'spectral' 'standard' 'stylelint' 'sql-lint' - 'tekton-lint' 'terrascan' 'tflint' 'xmllint' 'yamllint') - -################################################################################ -########################## FUNCTIONS BELOW ##################################### -################################################################################ -################################################################################ -#### Function BuildLinterVersions ############################################## BuildLinterVersions() { - ######################### - # Print version headers # - ######################### - info "---------------------------------------------" - info "Linter Version Info:" + VERSION_FILE="${1}" && shift + LINTER_ARRAY=("$@") + + debug "Building linter version file ${VERSION_FILE} for the following linters: ${LINTER_ARRAY}..." ########################################################## # Go through the array of linters and print version info # @@ -55,7 +16,7 @@ BuildLinterVersions() { #################### if [[ ${LINTER} == "arm-ttk" ]]; then # Need specific command for ARM - GET_VERSION_CMD="$(grep -iE 'version' "${ARM_TTK_PSD1}" | xargs 2>&1)" + GET_VERSION_CMD="$(grep -iE 'version' "/usr/bin/arm-ttk" | xargs 2>&1)" elif [[ ${LINTER} == "protolint" ]] || [[ ${LINTER} == "editorconfig-checker" ]] || [[ ${LINTER} == "bash-exec" ]]; then # Need specific command for Protolint and editorconfig-checker GET_VERSION_CMD="$(echo "--version not supported")" @@ -90,31 +51,25 @@ BuildLinterVersions() { ############################## debug "Linter version for ${LINTER}: ${GET_VERSION_CMD}. Error code: ${ERROR_CODE}" if [ ${ERROR_CODE} -ne 0 ]; then - WriteFile "${LINTER}" "Failed to get version info: ${GET_VERSION_CMD}" fatal "[${LINTER}]: Failed to get version info: ${GET_VERSION_CMD}" else ########################## # Print the version info # ########################## info "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD}" - WriteFile "${LINTER}" "${GET_VERSION_CMD}" + WriteFile "${LINTER}" "${GET_VERSION_CMD}" "${VERSION_FILE}" fi fi done - - ######################### - # Print version footers # - ######################### - info "---------------------------------------------" } -################################################################################ -#### Function WriteFile ######################################################## + WriteFile() { ############## # Read Input # ############## - LINTER="$1" # Name of the linter - VERSION="$2" # Version returned from check + LINTER="$1" # Name of the linter + VERSION="$2" # Version returned from check + VERSION_FILE=$3 # Version file path ################################# # Write the data to output file # @@ -133,11 +88,3 @@ WriteFile() { fatal "Failed to write data to file!" fi } -################################################################################ -############################### MAIN ########################################### -################################################################################ - -####################### -# BuildLinterVersions # -####################### -BuildLinterVersions From aca43d0206d230ca7bf4fe2566bb0927cb16eea4 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Mon, 2 Nov 2020 22:51:07 +0100 Subject: [PATCH 2/3] Fix SC2128 --- lib/linterVersions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linterVersions.sh b/lib/linterVersions.sh index 2148ba42..a9d2eddd 100755 --- a/lib/linterVersions.sh +++ b/lib/linterVersions.sh @@ -4,7 +4,7 @@ BuildLinterVersions() { VERSION_FILE="${1}" && shift LINTER_ARRAY=("$@") - debug "Building linter version file ${VERSION_FILE} for the following linters: ${LINTER_ARRAY}..." + debug "Building linter version file ${VERSION_FILE} for the following linters: ${LINTER_ARRAY[*]}..." ########################################################## # Go through the array of linters and print version info # From 301afc458a65681e97133306c5a72a189341f449 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Wed, 4 Nov 2020 14:18:45 +0100 Subject: [PATCH 3/3] Fix command output echo text --- lib/worker.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/worker.sh b/lib/worker.sh index e5f25755..fe30472d 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -281,7 +281,7 @@ function LintCodebase() { # Error # ######### error "Found errors in [${LINTER_NAME}] linter!" - error "Error code: ${ERROR_CODE}. Command run:${NC}[\$${LINT_CMD}]" + error "Error code: ${ERROR_CODE}. Command output:${NC}[${LINT_CMD}]" # Increment the error count (("ERRORS_FOUND_${FILE_TYPE}++")) fi @@ -319,7 +319,7 @@ function LintCodebase() { ######### error "Found errors in [${LINTER_NAME}] linter!" error "This file should have failed test case!" - error "Error code: ${ERROR_CODE}. Command run:${NC}[\$${LINT_CMD}]." + error "Error code: ${ERROR_CODE}. Command output:${NC}[${LINT_CMD}]." # Increment the error count (("ERRORS_FOUND_${FILE_TYPE}++")) else @@ -337,7 +337,7 @@ function LintCodebase() { AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" fi fi - debug "Error code: ${ERROR_CODE}. Command run:${NC}[\$${LINT_CMD}]." + debug "Error code: ${ERROR_CODE}. Command output:${NC}[${LINT_CMD}]." done #################################