mirror of
https://github.com/super-linter/super-linter.git
synced 2024-12-01 13:10:57 -05:00
Merge pull request #941 from github/streamline-linter-versions
Use the already-defined linter names array to print linter versions
This commit is contained in:
commit
a3d5b373be
4 changed files with 32 additions and 73 deletions
|
@ -340,7 +340,7 @@ COPY TEMPLATES /action/lib/.automation
|
||||||
###################################
|
###################################
|
||||||
# Run to build file with versions #
|
# 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
|
##################################4
|
||||||
# Run validations of built image #
|
# Run validations of built image #
|
||||||
|
|
|
@ -324,6 +324,18 @@ GetLinterVersions() {
|
||||||
debug "---------------------------------------------"
|
debug "---------------------------------------------"
|
||||||
debug "Linter Version Info:"
|
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 #
|
# Cat the linter versions file #
|
||||||
################################
|
################################
|
||||||
|
@ -339,7 +351,7 @@ GetLinterVersions() {
|
||||||
##############################
|
##############################
|
||||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||||
# Failure
|
# Failure
|
||||||
warn "Failed to view version file:[${VERSION_FILE}]"
|
fatal "Failed to view version file:[${VERSION_FILE}]"
|
||||||
else
|
else
|
||||||
# Success
|
# Success
|
||||||
debug "${CAT_CMD}"
|
debug "${CAT_CMD}"
|
||||||
|
@ -1162,6 +1174,11 @@ if [ -n "${OUTPUT_FORMAT}" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Get and print all version info #
|
||||||
|
##################################
|
||||||
|
GetLinterVersions
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
# Get GitHub Env Vars #
|
# Get GitHub Env Vars #
|
||||||
#######################
|
#######################
|
||||||
|
@ -1262,11 +1279,6 @@ for i in "${!LINTER_COMMANDS_ARRAY[@]}"; do
|
||||||
done
|
done
|
||||||
debug "---------------------------------------------"
|
debug "---------------------------------------------"
|
||||||
|
|
||||||
##################################
|
|
||||||
# Get and print all version info #
|
|
||||||
##################################
|
|
||||||
GetLinterVersions
|
|
||||||
|
|
||||||
###########################################
|
###########################################
|
||||||
# Build the list of files for each linter #
|
# Build the list of files for each linter #
|
||||||
###########################################
|
###########################################
|
||||||
|
|
|
@ -1,49 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/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() {
|
BuildLinterVersions() {
|
||||||
#########################
|
VERSION_FILE="${1}" && shift
|
||||||
# Print version headers #
|
LINTER_ARRAY=("$@")
|
||||||
#########################
|
|
||||||
info "---------------------------------------------"
|
debug "Building linter version file ${VERSION_FILE} for the following linters: ${LINTER_ARRAY[*]}..."
|
||||||
info "Linter Version Info:"
|
|
||||||
|
|
||||||
##########################################################
|
##########################################################
|
||||||
# Go through the array of linters and print version info #
|
# Go through the array of linters and print version info #
|
||||||
|
@ -55,7 +16,7 @@ BuildLinterVersions() {
|
||||||
####################
|
####################
|
||||||
if [[ ${LINTER} == "arm-ttk" ]]; then
|
if [[ ${LINTER} == "arm-ttk" ]]; then
|
||||||
# Need specific command for ARM
|
# 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
|
elif [[ ${LINTER} == "protolint" ]] || [[ ${LINTER} == "editorconfig-checker" ]] || [[ ${LINTER} == "bash-exec" ]]; then
|
||||||
# Need specific command for Protolint and editorconfig-checker
|
# Need specific command for Protolint and editorconfig-checker
|
||||||
GET_VERSION_CMD="$(echo "--version not supported")"
|
GET_VERSION_CMD="$(echo "--version not supported")"
|
||||||
|
@ -90,31 +51,25 @@ BuildLinterVersions() {
|
||||||
##############################
|
##############################
|
||||||
debug "Linter version for ${LINTER}: ${GET_VERSION_CMD}. Error code: ${ERROR_CODE}"
|
debug "Linter version for ${LINTER}: ${GET_VERSION_CMD}. Error code: ${ERROR_CODE}"
|
||||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
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}"
|
fatal "[${LINTER}]: Failed to get version info: ${GET_VERSION_CMD}"
|
||||||
else
|
else
|
||||||
##########################
|
##########################
|
||||||
# Print the version info #
|
# Print the version info #
|
||||||
##########################
|
##########################
|
||||||
info "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD}"
|
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
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
#########################
|
|
||||||
# Print version footers #
|
|
||||||
#########################
|
|
||||||
info "---------------------------------------------"
|
|
||||||
}
|
}
|
||||||
################################################################################
|
|
||||||
#### Function WriteFile ########################################################
|
|
||||||
WriteFile() {
|
WriteFile() {
|
||||||
##############
|
##############
|
||||||
# Read Input #
|
# Read Input #
|
||||||
##############
|
##############
|
||||||
LINTER="$1" # Name of the linter
|
LINTER="$1" # Name of the linter
|
||||||
VERSION="$2" # Version returned from check
|
VERSION="$2" # Version returned from check
|
||||||
|
VERSION_FILE=$3 # Version file path
|
||||||
|
|
||||||
#################################
|
#################################
|
||||||
# Write the data to output file #
|
# Write the data to output file #
|
||||||
|
@ -133,11 +88,3 @@ WriteFile() {
|
||||||
fatal "Failed to write data to file!"
|
fatal "Failed to write data to file!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
################################################################################
|
|
||||||
############################### MAIN ###########################################
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
#######################
|
|
||||||
# BuildLinterVersions #
|
|
||||||
#######################
|
|
||||||
BuildLinterVersions
|
|
||||||
|
|
|
@ -281,7 +281,7 @@ function LintCodebase() {
|
||||||
# Error #
|
# Error #
|
||||||
#########
|
#########
|
||||||
error "Found errors in [${LINTER_NAME}] linter!"
|
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
|
# Increment the error count
|
||||||
(("ERRORS_FOUND_${FILE_TYPE}++"))
|
(("ERRORS_FOUND_${FILE_TYPE}++"))
|
||||||
fi
|
fi
|
||||||
|
@ -319,7 +319,7 @@ function LintCodebase() {
|
||||||
#########
|
#########
|
||||||
error "Found errors in [${LINTER_NAME}] linter!"
|
error "Found errors in [${LINTER_NAME}] linter!"
|
||||||
error "This file should have failed test case!"
|
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
|
# Increment the error count
|
||||||
(("ERRORS_FOUND_${FILE_TYPE}++"))
|
(("ERRORS_FOUND_${FILE_TYPE}++"))
|
||||||
else
|
else
|
||||||
|
@ -337,7 +337,7 @@ function LintCodebase() {
|
||||||
AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}"
|
AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
debug "Error code: ${ERROR_CODE}. Command run:${NC}[\$${LINT_CMD}]."
|
debug "Error code: ${ERROR_CODE}. Command output:${NC}[${LINT_CMD}]."
|
||||||
done
|
done
|
||||||
|
|
||||||
#################################
|
#################################
|
||||||
|
|
Loading…
Reference in a new issue