mirror of
https://github.com/super-linter/super-linter.git
synced 2024-12-25 06:02:29 -05:00
break out: (#990)
* break out: * fix it * fix source * add them exports * more path * more path
This commit is contained in:
parent
496ec0cb1d
commit
7943ce1f54
16 changed files with 746 additions and 704 deletions
|
@ -18,7 +18,7 @@ export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR
|
|||
# Source additonal scripts #
|
||||
############################
|
||||
# shellcheck source=/dev/null
|
||||
source "${GITHUB_WORKSPACE}/lib/log.sh" # Source the function script(s)
|
||||
source "${GITHUB_WORKSPACE}/lib/functions/log.sh" # Source the function script(s)
|
||||
|
||||
################################################################################
|
||||
############################ FUNCTIONS BELOW ###################################
|
||||
|
|
|
@ -29,7 +29,7 @@ export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR
|
|||
# Source Function Files #
|
||||
#########################
|
||||
# shellcheck source=/dev/null
|
||||
source "${GITHUB_WORKSPACE}/lib/log.sh" # Source the function script(s)
|
||||
source "${GITHUB_WORKSPACE}/lib/functions/log.sh" # Source the function script(s)
|
||||
|
||||
################################################################################
|
||||
############################ FUNCTIONS BELOW ###################################
|
||||
|
|
|
@ -48,7 +48,7 @@ export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR
|
|||
# Source Function Files #
|
||||
#########################
|
||||
# shellcheck source=/dev/null
|
||||
source "${GITHUB_WORKSPACE}/lib/log.sh" # Source the function script(s)
|
||||
source "${GITHUB_WORKSPACE}/lib/functions/log.sh" # Source the function script(s)
|
||||
|
||||
################################################################################
|
||||
############################ FUNCTIONS BELOW ###################################
|
||||
|
|
|
@ -21,7 +21,7 @@ export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR
|
|||
# Source Function Files #
|
||||
#########################
|
||||
# shellcheck source=/dev/null
|
||||
source "${GITHUB_WORKSPACE}/lib/log.sh" # Source the function script(s)
|
||||
source "${GITHUB_WORKSPACE}/lib/functions/log.sh" # Source the function script(s)
|
||||
|
||||
################################################################################
|
||||
############################ FUNCTIONS BELOW ###################################
|
||||
|
|
|
@ -345,7 +345,7 @@ RUN ACTIONS_RUNNER_DEBUG=true WRITE_LINTER_VERSIONS_FILE=true /action/lib/linter
|
|||
##################################4
|
||||
# Run validations of built image #
|
||||
##################################
|
||||
RUN /action/lib/validate-docker.sh
|
||||
RUN /action/lib/functions/validateDocker.sh
|
||||
|
||||
######################
|
||||
# Set the entrypoint #
|
||||
|
|
|
@ -617,114 +617,3 @@ function BuildFileList() {
|
|||
info "----------------------------------------------"
|
||||
info "Successfully gathered list of files..."
|
||||
}
|
||||
################################################################################
|
||||
#### Function GetFileType ######################################################
|
||||
function GetFileType() {
|
||||
# Need to run the file through the 'file' exec to help determine
|
||||
# The type of file being parsed
|
||||
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="$1"
|
||||
|
||||
##################
|
||||
# Check the file #
|
||||
##################
|
||||
GET_FILE_TYPE_CMD=$(file "${FILE}" 2>&1)
|
||||
|
||||
echo "${GET_FILE_TYPE_CMD}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function CheckFileType ####################################################
|
||||
function CheckFileType() {
|
||||
# Need to run the file through the 'file' exec to help determine
|
||||
# The type of file being parsed
|
||||
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="$1"
|
||||
|
||||
#################
|
||||
# Get file type #
|
||||
#################
|
||||
GET_FILE_TYPE_CMD="$(GetFileType "$FILE")"
|
||||
|
||||
if [[ ${GET_FILE_TYPE_CMD} == *"Ruby script"* ]]; then
|
||||
#######################
|
||||
# It is a Ruby script #
|
||||
#######################
|
||||
warn "Found ruby script without extension:[.rb]"
|
||||
info "Please update file with proper extensions."
|
||||
################################
|
||||
# Append the file to the array #
|
||||
################################
|
||||
FILE_ARRAY_RUBY+=("${FILE}")
|
||||
else
|
||||
############################
|
||||
# Extension was not found! #
|
||||
############################
|
||||
warn "Failed to get filetype for:[${FILE}]!"
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function GetFileExtension ###############################################
|
||||
function GetFileExtension() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="$1"
|
||||
|
||||
###########################
|
||||
# Get the files extension #
|
||||
###########################
|
||||
# Extract just the file extension
|
||||
FILE_TYPE=${FILE##*.}
|
||||
# To lowercase
|
||||
FILE_TYPE=${FILE_TYPE,,}
|
||||
|
||||
echo "$FILE_TYPE"
|
||||
}
|
||||
################################################################################
|
||||
#### Function IsValidShellScript ###############################################
|
||||
function IsValidShellScript() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="$1"
|
||||
|
||||
#################
|
||||
# Get file type #
|
||||
#################
|
||||
FILE_EXTENSION="$(GetFileExtension "$FILE")"
|
||||
GET_FILE_TYPE_CMD="$(GetFileType "$FILE")"
|
||||
|
||||
trace "File:[${FILE}], File extension:[${FILE_EXTENSION}], File type: [${GET_FILE_TYPE_CMD}]"
|
||||
|
||||
if [[ "${FILE_EXTENSION}" == "zsh" ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"zsh script"* ]]; then
|
||||
warn "$FILE is a ZSH script. Skipping..."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${FILE_EXTENSION}" == "sh" ] ||
|
||||
[ "${FILE_EXTENSION}" == "bash" ] ||
|
||||
[ "${FILE_EXTENSION}" == "dash" ] ||
|
||||
[ "${FILE_EXTENSION}" == "ksh" ]; then
|
||||
debug "$FILE is a valid shell script (has a valid extension: ${FILE_EXTENSION})"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "${GET_FILE_TYPE_CMD}" == *"POSIX shell script"* ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"Bourne-Again shell script"* ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"dash script"* ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"ksh script"* ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"/usr/bin/env sh script"* ]]; then
|
||||
debug "$FILE is a valid shell script (has a valid file type: ${GET_FILE_TYPE_CMD})"
|
||||
return 0
|
||||
fi
|
||||
|
||||
trace "$FILE is NOT a supported shell script. Skipping"
|
||||
return 1
|
||||
}
|
319
lib/functions/detectFiles.sh
Executable file
319
lib/functions/detectFiles.sh
Executable file
|
@ -0,0 +1,319 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
########### Super-Linter linting Functions @admiralawkbar ######################
|
||||
################################################################################
|
||||
################################################################################
|
||||
########################## FUNCTION CALLS BELOW ################################
|
||||
################################################################################
|
||||
################################################################################
|
||||
#### Function DetectOpenAPIFile ################################################
|
||||
DetectOpenAPIFile() {
|
||||
################
|
||||
# Pull in vars #
|
||||
################
|
||||
FILE="${1}"
|
||||
debug "Checking if ${FILE} is an OpenAPI file..."
|
||||
|
||||
###############################
|
||||
# Check the file for keywords #
|
||||
###############################
|
||||
grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "${FILE}" >/dev/null
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -eq 0 ]; then
|
||||
########################
|
||||
# Found string in file #
|
||||
########################
|
||||
return 0
|
||||
else
|
||||
###################
|
||||
# No string match #
|
||||
###################
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectTektonFile #################################################
|
||||
DetectTektonFile() {
|
||||
################
|
||||
# Pull in vars #
|
||||
################
|
||||
FILE="${1}"
|
||||
debug "Checking if ${FILE} is a Tekton file..."
|
||||
|
||||
###############################
|
||||
# Check the file for keywords #
|
||||
###############################
|
||||
grep -q -E 'apiVersion: tekton' "${FILE}" >/dev/null
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -eq 0 ]; then
|
||||
########################
|
||||
# Found string in file #
|
||||
########################
|
||||
return 0
|
||||
else
|
||||
###################
|
||||
# No string match #
|
||||
###################
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectARMFile ####################################################
|
||||
DetectARMFile() {
|
||||
################
|
||||
# Pull in vars #
|
||||
################
|
||||
FILE="${1}" # Name of the file/path we are validating
|
||||
debug "Checking if ${FILE} is an ARM file..."
|
||||
|
||||
###############################
|
||||
# Check the file for keywords #
|
||||
###############################
|
||||
grep -E 'schema.management.azure.com' "${FILE}" >/dev/null
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -eq 0 ]; then
|
||||
########################
|
||||
# Found string in file #
|
||||
########################
|
||||
return 0
|
||||
else
|
||||
###################
|
||||
# No string match #
|
||||
###################
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectCloudFormationFile #########################################
|
||||
DetectCloudFormationFile() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="${1}" # File that we need to validate
|
||||
debug "Checking if ${FILE} is a Cloud Formation file..."
|
||||
|
||||
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-formats.html
|
||||
# AWSTemplateFormatVersion is optional
|
||||
#######################################
|
||||
# Check if file has AWS Template info #
|
||||
#######################################
|
||||
if grep -q 'AWSTemplateFormatVersion' "${FILE}" >/dev/null; then
|
||||
# Found it
|
||||
return 0
|
||||
fi
|
||||
|
||||
#####################################
|
||||
# See if it contains AWS References #
|
||||
#####################################
|
||||
if grep -q -E '(AWS|Alexa|Custom)::' "${FILE}" >/dev/null; then
|
||||
# Found it
|
||||
return 0
|
||||
fi
|
||||
|
||||
#####################################################
|
||||
# No identifiers of a CLOUDFORMATION template found #
|
||||
#####################################################
|
||||
return 1
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectKubernetesFile #########################################
|
||||
DetectKubernetesFile() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="${1}" # File that we need to validate
|
||||
debug "Checking if ${FILE} is a Kubernetes descriptor..."
|
||||
|
||||
if grep -v 'kustomize.config.k8s.io' "${FILE}" | grep -v tekton | grep -q -E '(apiVersion):'; then
|
||||
debug "${FILE} is a Kubernetes descriptor"
|
||||
return 0
|
||||
fi
|
||||
|
||||
debug "${FILE} is NOT a Kubernetes descriptor"
|
||||
return 1
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectAWSStatesFIle ##############################################
|
||||
DetectAWSStatesFIle() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="${1}" # File that we need to validate
|
||||
debug "Checking if ${FILE} is a AWS states descriptor..."
|
||||
|
||||
# https://states-language.net/spec.html#example
|
||||
###############################
|
||||
# check if file has resources #
|
||||
###############################
|
||||
if grep -q '"Resource": *"arn"*' "${FILE}"; then
|
||||
# Found it
|
||||
return 0
|
||||
fi
|
||||
|
||||
#################################################
|
||||
# No identifiers of a AWS States Language found #
|
||||
#################################################
|
||||
return 1
|
||||
}
|
||||
################################################################################
|
||||
#### Function CheckInArray #####################################################
|
||||
CheckInArray() {
|
||||
###############
|
||||
# Pull in Var #
|
||||
###############
|
||||
NEEDLE="$1" # Language we need to match
|
||||
|
||||
######################################
|
||||
# Check if Language was in the array #
|
||||
######################################
|
||||
for LANG in "${UNIQUE_LINTED_ARRAY[@]}"; do
|
||||
if [[ "${LANG}" == "${NEEDLE}" ]]; then
|
||||
############
|
||||
# Found it #
|
||||
############
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
###################
|
||||
# Did not find it #
|
||||
###################
|
||||
return 1
|
||||
}
|
||||
################################################################################
|
||||
#### Function GetFileType ######################################################
|
||||
function GetFileType() {
|
||||
# Need to run the file through the 'file' exec to help determine
|
||||
# The type of file being parsed
|
||||
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="$1"
|
||||
|
||||
##################
|
||||
# Check the file #
|
||||
##################
|
||||
GET_FILE_TYPE_CMD=$(file "${FILE}" 2>&1)
|
||||
|
||||
echo "${GET_FILE_TYPE_CMD}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function CheckFileType ####################################################
|
||||
function CheckFileType() {
|
||||
# Need to run the file through the 'file' exec to help determine
|
||||
# The type of file being parsed
|
||||
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="$1"
|
||||
|
||||
#################
|
||||
# Get file type #
|
||||
#################
|
||||
GET_FILE_TYPE_CMD="$(GetFileType "$FILE")"
|
||||
|
||||
if [[ ${GET_FILE_TYPE_CMD} == *"Ruby script"* ]]; then
|
||||
#######################
|
||||
# It is a Ruby script #
|
||||
#######################
|
||||
warn "Found ruby script without extension:[.rb]"
|
||||
info "Please update file with proper extensions."
|
||||
################################
|
||||
# Append the file to the array #
|
||||
################################
|
||||
FILE_ARRAY_RUBY+=("${FILE}")
|
||||
else
|
||||
############################
|
||||
# Extension was not found! #
|
||||
############################
|
||||
warn "Failed to get filetype for:[${FILE}]!"
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function GetFileExtension ###############################################
|
||||
function GetFileExtension() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="$1"
|
||||
|
||||
###########################
|
||||
# Get the files extension #
|
||||
###########################
|
||||
# Extract just the file extension
|
||||
FILE_TYPE=${FILE##*.}
|
||||
# To lowercase
|
||||
FILE_TYPE=${FILE_TYPE,,}
|
||||
|
||||
echo "$FILE_TYPE"
|
||||
}
|
||||
################################################################################
|
||||
#### Function IsValidShellScript ###############################################
|
||||
function IsValidShellScript() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="$1"
|
||||
|
||||
#################
|
||||
# Get file type #
|
||||
#################
|
||||
FILE_EXTENSION="$(GetFileExtension "$FILE")"
|
||||
GET_FILE_TYPE_CMD="$(GetFileType "$FILE")"
|
||||
|
||||
trace "File:[${FILE}], File extension:[${FILE_EXTENSION}], File type: [${GET_FILE_TYPE_CMD}]"
|
||||
|
||||
if [[ "${FILE_EXTENSION}" == "zsh" ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"zsh script"* ]]; then
|
||||
warn "$FILE is a ZSH script. Skipping..."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${FILE_EXTENSION}" == "sh" ] ||
|
||||
[ "${FILE_EXTENSION}" == "bash" ] ||
|
||||
[ "${FILE_EXTENSION}" == "dash" ] ||
|
||||
[ "${FILE_EXTENSION}" == "ksh" ]; then
|
||||
debug "$FILE is a valid shell script (has a valid extension: ${FILE_EXTENSION})"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "${GET_FILE_TYPE_CMD}" == *"POSIX shell script"* ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"Bourne-Again shell script"* ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"dash script"* ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"ksh script"* ]] ||
|
||||
[[ ${GET_FILE_TYPE_CMD} == *"/usr/bin/env sh script"* ]]; then
|
||||
debug "$FILE is a valid shell script (has a valid file type: ${GET_FILE_TYPE_CMD})"
|
||||
return 0
|
||||
fi
|
||||
|
||||
trace "$FILE is NOT a supported shell script. Skipping"
|
||||
return 1
|
||||
}
|
229
lib/functions/linterRules.sh
Executable file
229
lib/functions/linterRules.sh
Executable file
|
@ -0,0 +1,229 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
########### Super-Linter linting Functions @admiralawkbar ######################
|
||||
################################################################################
|
||||
################################################################################
|
||||
########################## FUNCTION CALLS BELOW ################################
|
||||
################################################################################
|
||||
################################################################################
|
||||
#### Function GetLinterRules ###################################################
|
||||
GetLinterRules() {
|
||||
# Need to validate the rules files exist
|
||||
|
||||
################
|
||||
# Pull in vars #
|
||||
################
|
||||
LANGUAGE_NAME="${1}" # Name of the language were looking for
|
||||
debug "Getting linter rules for ${LANGUAGE_NAME}..."
|
||||
|
||||
DEFAULT_RULES_LOCATION="${2}"
|
||||
debug "Default rules location: ${DEFAULT_RULES_LOCATION}..."
|
||||
|
||||
#######################################################
|
||||
# Need to create the variables for the real variables #
|
||||
#######################################################
|
||||
LANGUAGE_FILE_NAME="${LANGUAGE_NAME}_FILE_NAME"
|
||||
LANGUAGE_LINTER_RULES="${LANGUAGE_NAME}_LINTER_RULES"
|
||||
debug "Variable names for language file name: ${LANGUAGE_FILE_NAME}, language linter rules: ${LANGUAGE_LINTER_RULES}"
|
||||
|
||||
#####################################################
|
||||
# Check if the language rules variables are defined #
|
||||
#####################################################
|
||||
if [ -z "${!LANGUAGE_FILE_NAME+x}" ]; then
|
||||
debug "${LANGUAGE_FILE_NAME} is not set. Skipping loading rules for ${LANGUAGE_NAME}..."
|
||||
return
|
||||
fi
|
||||
|
||||
debug "Initializing LANGUAGE_LINTER_RULES value to an empty string..."
|
||||
eval "${LANGUAGE_LINTER_RULES}="
|
||||
|
||||
##########################
|
||||
# Get the file extension #
|
||||
##########################
|
||||
FILE_EXTENSION=$(echo "${!LANGUAGE_FILE_NAME}" | rev | cut -d'.' -f1 | rev)
|
||||
FILE_NAME=$(basename "${!LANGUAGE_FILE_NAME}" ".${FILE_EXTENSION}")
|
||||
debug "${LANGUAGE_NAME} language rule file (${!LANGUAGE_FILE_NAME}) has ${FILE_NAME} name and ${FILE_EXTENSION} extension"
|
||||
|
||||
########################################
|
||||
# Set the secondary file name and path #
|
||||
########################################
|
||||
debug "Initializing SECONDARY_FILE_NAME and SECONDARY_LANGUAGE_FILE_PATH..."
|
||||
SECONDARY_FILE_NAME=''
|
||||
SECONDARY_LANGUAGE_FILE_PATH=
|
||||
|
||||
#################################
|
||||
# Check for secondary file name #
|
||||
#################################
|
||||
if [[ $FILE_EXTENSION == 'yml' ]]; then
|
||||
# Need to see if yaml also exists
|
||||
SECONDARY_FILE_NAME="$FILE_NAME.yaml"
|
||||
elif [[ $FILE_EXTENSION == 'yaml' ]]; then
|
||||
# need to see if yml also exists
|
||||
SECONDARY_FILE_NAME="$FILE_NAME.yml"
|
||||
fi
|
||||
|
||||
###############################
|
||||
# Set Flag for set Rules File #
|
||||
###############################
|
||||
SET_RULES=0
|
||||
|
||||
#####################################
|
||||
# Validate we have the linter rules #
|
||||
#####################################
|
||||
LANGUAGE_FILE_PATH="${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}"
|
||||
debug "Checking if the user-provided:[${!LANGUAGE_FILE_NAME}] and exists at:[${LANGUAGE_FILE_PATH}]"
|
||||
if [ -f "${LANGUAGE_FILE_PATH}" ]; then
|
||||
info "----------------------------------------------"
|
||||
info "User provided file:[${LANGUAGE_FILE_PATH}] exists, setting rules file..."
|
||||
|
||||
########################################
|
||||
# Update the path to the file location #
|
||||
########################################
|
||||
eval "${LANGUAGE_LINTER_RULES}=${LANGUAGE_FILE_PATH}"
|
||||
######################
|
||||
# Set the rules flag #
|
||||
######################
|
||||
SET_RULES=1
|
||||
else
|
||||
# Failed to find the primary rules file
|
||||
debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}]."
|
||||
fi
|
||||
|
||||
####################################################
|
||||
# Check if we have secondary file name to look for #
|
||||
####################################################
|
||||
if [ -n "$SECONDARY_FILE_NAME" ] && [ "${SET_RULES}" -eq 0 ]; then
|
||||
# Set the path
|
||||
SECONDARY_LANGUAGE_FILE_PATH="${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${SECONDARY_FILE_NAME}"
|
||||
debug "${LANGUAGE_NAME} language rule file has a secondary rules file name to check (${SECONDARY_FILE_NAME}). Path:[${SECONDARY_LANGUAGE_FILE_PATH}]"
|
||||
|
||||
if [ -f "${SECONDARY_LANGUAGE_FILE_PATH}" ]; then
|
||||
info "----------------------------------------------"
|
||||
info "User provided file:[${SECONDARY_LANGUAGE_FILE_PATH}] exists, setting rules file..."
|
||||
|
||||
########################################
|
||||
# Update the path to the file location #
|
||||
########################################
|
||||
eval "${LANGUAGE_LINTER_RULES}=${SECONDARY_LANGUAGE_FILE_PATH}"
|
||||
######################
|
||||
# Set the rules flag #
|
||||
######################
|
||||
SET_RULES=1
|
||||
fi
|
||||
fi
|
||||
|
||||
##############################################################
|
||||
# We didnt find rules from user, setting to default template #
|
||||
##############################################################
|
||||
if [ "${SET_RULES}" -eq 0 ]; then
|
||||
########################################################
|
||||
# No user default provided, using the template default #
|
||||
########################################################
|
||||
eval "${LANGUAGE_LINTER_RULES}=${DEFAULT_RULES_LOCATION}/${!LANGUAGE_FILE_NAME}"
|
||||
debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}], nor the file:[${SECONDARY_LANGUAGE_FILE_PATH}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]"
|
||||
######################
|
||||
# Set the rules flag #
|
||||
######################
|
||||
SET_RULES=1
|
||||
fi
|
||||
|
||||
####################
|
||||
# Debug Print info #
|
||||
####################
|
||||
debug " -> Language rules file variable (${LANGUAGE_LINTER_RULES}) value is:[${!LANGUAGE_LINTER_RULES}]"
|
||||
|
||||
############################
|
||||
# Validate the file exists #
|
||||
############################
|
||||
if [ -e "${!LANGUAGE_LINTER_RULES}" ]; then
|
||||
# Found the rules file
|
||||
debug " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) exists."
|
||||
else
|
||||
# Here we expect a rules file, so fail if not available.
|
||||
fatal " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) doesn't exist. Terminating..."
|
||||
fi
|
||||
|
||||
######################
|
||||
# Export the results #
|
||||
######################
|
||||
eval "export ${LANGUAGE_LINTER_RULES}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function GetStandardRules #################################################
|
||||
GetStandardRules() {
|
||||
################
|
||||
# Pull In Vars #
|
||||
################
|
||||
LINTER="${1}" # Type: javascript | typescript
|
||||
|
||||
#########################################################################
|
||||
# Need to get the ENV vars from the linter rules to run in command line #
|
||||
#########################################################################
|
||||
# Copy orig IFS to var
|
||||
ORIG_IFS="${IFS}"
|
||||
# Set the IFS to newline
|
||||
IFS=$'\n'
|
||||
|
||||
#########################################
|
||||
# Get list of all environment variables #
|
||||
#########################################
|
||||
# Only env vars that are marked as true
|
||||
GET_ENV_ARRAY=()
|
||||
if [[ ${LINTER} == "javascript" ]]; then
|
||||
mapfile -t GET_ENV_ARRAY < <(yq .env "${JAVASCRIPT_STANDARD_LINTER_RULES}" | grep true)
|
||||
elif [[ ${LINTER} == "typescript" ]]; then
|
||||
mapfile -t GET_ENV_ARRAY < <(yq .env "${TYPESCRIPT_STANDARD_LINTER_RULES}" | grep true)
|
||||
fi
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||
# ERROR
|
||||
error "Failed to gain list of ENV vars to load!"
|
||||
fatal "[${GET_ENV_ARRAY[*]}]"
|
||||
fi
|
||||
|
||||
##########################
|
||||
# Set IFS back to normal #
|
||||
##########################
|
||||
# Set IFS back to Orig
|
||||
IFS="${ORIG_IFS}"
|
||||
|
||||
######################
|
||||
# Set the env string #
|
||||
######################
|
||||
ENV_STRING=''
|
||||
|
||||
#############################
|
||||
# Pull out the envs to load #
|
||||
#############################
|
||||
for ENV in "${GET_ENV_ARRAY[@]}"; do
|
||||
#############################
|
||||
# remove spaces from return #
|
||||
#############################
|
||||
ENV="$(echo -e "${ENV}" | tr -d '[:space:]')"
|
||||
################################
|
||||
# Get the env to add to string #
|
||||
################################
|
||||
ENV="$(echo "${ENV}" | cut -d'"' -f2)"
|
||||
debug "ENV:[${ENV}]"
|
||||
ENV_STRING+="--env ${ENV} "
|
||||
done
|
||||
|
||||
#########################################
|
||||
# Remove trailing and ending whitespace #
|
||||
#########################################
|
||||
if [[ ${LINTER} == "javascript" ]]; then
|
||||
JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
elif [[ ${LINTER} == "typescript" ]]; then
|
||||
TYPESCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
fi
|
||||
}
|
|
@ -1,5 +1,56 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
########### Super-Linter linting Functions @admiralawkbar ######################
|
||||
################################################################################
|
||||
################################################################################
|
||||
#### Function GetLinterVersions ################################################
|
||||
GetLinterVersions() {
|
||||
#########################
|
||||
# Print version headers #
|
||||
#########################
|
||||
debug "---------------------------------------------"
|
||||
debug "Linter Version Info:"
|
||||
|
||||
if ! [ -e "${VERSION_FILE}" ] && [ "${WRITE_LINTER_VERSIONS_FILE}" = "true" ]; then
|
||||
debug "Building linter version file..."
|
||||
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_CMD=$(cat "${VERSION_FILE}" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||
# Failure
|
||||
fatal "Failed to view version file:[${VERSION_FILE}]"
|
||||
else
|
||||
# Success
|
||||
debug "${CAT_CMD}"
|
||||
fi
|
||||
|
||||
#########################
|
||||
# Print version footers #
|
||||
#########################
|
||||
debug "---------------------------------------------"
|
||||
}
|
||||
################################################################################
|
||||
#### Function BuildLinterVersions ##############################################
|
||||
BuildLinterVersions() {
|
||||
VERSION_FILE="${1}" && shift
|
||||
LINTER_ARRAY=("$@")
|
||||
|
@ -62,7 +113,8 @@ BuildLinterVersions() {
|
|||
fi
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
#### Function WriteFile ########################################################
|
||||
WriteFile() {
|
||||
##############
|
||||
# Read Input #
|
0
lib/log.sh → lib/functions/log.sh
Normal file → Executable file
0
lib/log.sh → lib/functions/log.sh
Normal file → Executable file
123
lib/functions/tapLibrary.sh
Executable file
123
lib/functions/tapLibrary.sh
Executable file
|
@ -0,0 +1,123 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
########### Super-Linter linting Functions @admiralawkbar ######################
|
||||
################################################################################
|
||||
################################################################################
|
||||
########################## FUNCTION CALLS BELOW ################################
|
||||
################################################################################
|
||||
################################################################################
|
||||
#### Function IsTap ############################################################
|
||||
function IsTAP() {
|
||||
if [ "${OUTPUT_FORMAT}" == "tap" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function TransformTAPDetails ##############################################
|
||||
function 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
|
||||
}
|
||||
################################################################################
|
||||
#### Function HeaderTap ########################################################
|
||||
function HeaderTap() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
INDEX="${1}" # File being validated
|
||||
OUTPUT_FILE="${2}" # Output location
|
||||
|
||||
###################
|
||||
# Print the goods #
|
||||
###################
|
||||
printf "TAP version 13\n1..%s\n" "${INDEX}" >"${OUTPUT_FILE}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function OkTap ############################################################
|
||||
function OkTap() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
INDEX="${1}" # Location
|
||||
FILE="${2}" # File being validated
|
||||
TEMP_FILE="${3}" # Temp file location
|
||||
|
||||
###################
|
||||
# Print the goods #
|
||||
###################
|
||||
echo "ok ${INDEX} - ${FILE}" >>"${TEMP_FILE}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function NotOkTap #########################################################
|
||||
function NotOkTap() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
INDEX="${1}" # Location
|
||||
FILE="${2}" # File being validated
|
||||
TEMP_FILE="${3}" # Temp file location
|
||||
|
||||
###################
|
||||
# Print the goods #
|
||||
###################
|
||||
echo "not ok ${INDEX} - ${FILE}" >>"${TEMP_FILE}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function AddDetailedMessageIfEnabled ######################################
|
||||
function AddDetailedMessageIfEnabled() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
LINT_CMD="${1}" # Linter command
|
||||
TEMP_FILE="${2}" # Temp file
|
||||
|
||||
####################
|
||||
# Check the return #
|
||||
####################
|
||||
DETAILED_MSG=$(TransformTAPDetails "${LINT_CMD}")
|
||||
if [ -n "${DETAILED_MSG}" ]; then
|
||||
printf " ---\n message: %s\n ...\n" "${DETAILED_MSG}" >>"${TEMP_FILE}"
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function Reports ##########################################################
|
||||
Reports() {
|
||||
info "----------------------------------------------"
|
||||
info "----------------------------------------------"
|
||||
info "Generated reports:"
|
||||
info "----------------------------------------------"
|
||||
info "----------------------------------------------"
|
||||
|
||||
###################################
|
||||
# Prints output report if enabled #
|
||||
###################################
|
||||
if [ -z "${FORMAT_REPORT}" ]; then
|
||||
info "Reports generated in folder ${REPORT_OUTPUT_FOLDER}"
|
||||
#############################################
|
||||
# Print info on reports that were generated #
|
||||
#############################################
|
||||
if [ -d "${REPORT_OUTPUT_FOLDER}" ]; then
|
||||
info "Contents of report folder:"
|
||||
OUTPUT_CONTENTS_CMD=$(ls "${REPORT_OUTPUT_FOLDER}")
|
||||
info "$OUTPUT_CONTENTS_CMD"
|
||||
else
|
||||
warn "Report output folder (${REPORT_OUTPUT_FOLDER}) does NOT exist."
|
||||
fi
|
||||
fi
|
||||
|
||||
################################
|
||||
# Prints for warnings if found #
|
||||
################################
|
||||
for TEST in "${WARNING_ARRAY_TEST[@]}"; do
|
||||
warn "Expected file to compare with was not found for ${TEST}"
|
||||
done
|
||||
}
|
|
@ -16,7 +16,7 @@ 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 /action/lib/functions/log.sh
|
||||
|
||||
################################################################################
|
||||
############################ FUNCTIONS BELOW ###################################
|
|
@ -546,84 +546,3 @@ function LintAnsibleFiles() {
|
|||
debug "skipping ansible lint"
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function IsTap ############################################################
|
||||
function IsTAP() {
|
||||
if [ "${OUTPUT_FORMAT}" == "tap" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function TransformTAPDetails ##############################################
|
||||
function 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
|
||||
}
|
||||
################################################################################
|
||||
#### Function HeaderTap ########################################################
|
||||
function HeaderTap() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
INDEX="${1}" # File being validated
|
||||
OUTPUT_FILE="${2}" # Output location
|
||||
|
||||
###################
|
||||
# Print the goods #
|
||||
###################
|
||||
printf "TAP version 13\n1..%s\n" "${INDEX}" >"${OUTPUT_FILE}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function OkTap ############################################################
|
||||
function OkTap() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
INDEX="${1}" # Location
|
||||
FILE="${2}" # File being validated
|
||||
TEMP_FILE="${3}" # Temp file location
|
||||
|
||||
###################
|
||||
# Print the goods #
|
||||
###################
|
||||
echo "ok ${INDEX} - ${FILE}" >>"${TEMP_FILE}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function NotOkTap #########################################################
|
||||
function NotOkTap() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
INDEX="${1}" # Location
|
||||
FILE="${2}" # File being validated
|
||||
TEMP_FILE="${3}" # Temp file location
|
||||
|
||||
###################
|
||||
# Print the goods #
|
||||
###################
|
||||
echo "not ok ${INDEX} - ${FILE}" >>"${TEMP_FILE}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function AddDetailedMessageIfEnabled ######################################
|
||||
function AddDetailedMessageIfEnabled() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
LINT_CMD="${1}" # Linter command
|
||||
TEMP_FILE="${2}" # Temp file
|
||||
|
||||
####################
|
||||
# Check the return #
|
||||
####################
|
||||
DETAILED_MSG=$(TransformTAPDetails "${LINT_CMD}")
|
||||
if [ -n "${DETAILED_MSG}" ]; then
|
||||
printf " ---\n message: %s\n ...\n" "${DETAILED_MSG}" >>"${TEMP_FILE}"
|
||||
fi
|
||||
}
|
521
lib/linter.sh
521
lib/linter.sh
|
@ -44,13 +44,21 @@ export LOG_ERROR
|
|||
# Source Function Files #
|
||||
#########################
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/log.sh # Source the function script(s)
|
||||
source /action/lib/functions/log.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/buildFileList.sh # Source the function script(s)
|
||||
source /action/lib/functions/buildFileList.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/validation.sh # Source the function script(s)
|
||||
source /action/lib/functions/validation.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/worker.sh # Source the function script(s)
|
||||
source /action/lib/functions/worker.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/tapLibrary.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/linterRules.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/detectFiles.sh # Source the function script(s)
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/linterVersions.sh # Source the function script(s)
|
||||
|
||||
###########
|
||||
# GLOBALS #
|
||||
|
@ -59,7 +67,8 @@ source /action/lib/worker.sh # Source the function script(s)
|
|||
DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location
|
||||
LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory
|
||||
GITHUB_API_URL='https://api.github.com' # GitHub API root url
|
||||
VERSION_FILE='/action/lib/linter-versions.txt' # File to store linter versions
|
||||
VERSION_FILE='/action/lib/functions/linterVersions.txt' # File to store linter versions
|
||||
export VERSION_FILE # Workaround SC2034
|
||||
|
||||
###############
|
||||
# Rules files #
|
||||
|
@ -297,7 +306,7 @@ Header() {
|
|||
###############################
|
||||
# Give them the possum action #
|
||||
###############################
|
||||
/bin/bash /action/lib/possum.sh
|
||||
/bin/bash /action/lib/functions/possum.sh
|
||||
|
||||
##########
|
||||
# Prints #
|
||||
|
@ -314,447 +323,6 @@ Header() {
|
|||
info "---------------------------------------------"
|
||||
}
|
||||
################################################################################
|
||||
#### Function GetLinterVersions ################################################
|
||||
GetLinterVersions() {
|
||||
#########################
|
||||
# Print version headers #
|
||||
#########################
|
||||
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 #
|
||||
################################
|
||||
CAT_CMD=$(cat "${VERSION_FILE}" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||
# Failure
|
||||
fatal "Failed to view version file:[${VERSION_FILE}]"
|
||||
else
|
||||
# Success
|
||||
debug "${CAT_CMD}"
|
||||
fi
|
||||
|
||||
#########################
|
||||
# Print version footers #
|
||||
#########################
|
||||
debug "---------------------------------------------"
|
||||
}
|
||||
################################################################################
|
||||
#### Function GetLinterRules ###################################################
|
||||
GetLinterRules() {
|
||||
# Need to validate the rules files exist
|
||||
|
||||
################
|
||||
# Pull in vars #
|
||||
################
|
||||
LANGUAGE_NAME="${1}" # Name of the language were looking for
|
||||
debug "Getting linter rules for ${LANGUAGE_NAME}..."
|
||||
|
||||
DEFAULT_RULES_LOCATION="${2}"
|
||||
debug "Default rules location: ${DEFAULT_RULES_LOCATION}..."
|
||||
|
||||
#######################################################
|
||||
# Need to create the variables for the real variables #
|
||||
#######################################################
|
||||
LANGUAGE_FILE_NAME="${LANGUAGE_NAME}_FILE_NAME"
|
||||
LANGUAGE_LINTER_RULES="${LANGUAGE_NAME}_LINTER_RULES"
|
||||
debug "Variable names for language file name: ${LANGUAGE_FILE_NAME}, language linter rules: ${LANGUAGE_LINTER_RULES}"
|
||||
|
||||
#####################################################
|
||||
# Check if the language rules variables are defined #
|
||||
#####################################################
|
||||
if [ -z "${!LANGUAGE_FILE_NAME+x}" ]; then
|
||||
debug "${LANGUAGE_FILE_NAME} is not set. Skipping loading rules for ${LANGUAGE_NAME}..."
|
||||
return
|
||||
fi
|
||||
|
||||
debug "Initializing LANGUAGE_LINTER_RULES value to an empty string..."
|
||||
eval "${LANGUAGE_LINTER_RULES}="
|
||||
|
||||
##########################
|
||||
# Get the file extension #
|
||||
##########################
|
||||
FILE_EXTENSION=$(echo "${!LANGUAGE_FILE_NAME}" | rev | cut -d'.' -f1 | rev)
|
||||
FILE_NAME=$(basename "${!LANGUAGE_FILE_NAME}" ".${FILE_EXTENSION}")
|
||||
debug "${LANGUAGE_NAME} language rule file (${!LANGUAGE_FILE_NAME}) has ${FILE_NAME} name and ${FILE_EXTENSION} extension"
|
||||
|
||||
########################################
|
||||
# Set the secondary file name and path #
|
||||
########################################
|
||||
debug "Initializing SECONDARY_FILE_NAME and SECONDARY_LANGUAGE_FILE_PATH..."
|
||||
SECONDARY_FILE_NAME=''
|
||||
SECONDARY_LANGUAGE_FILE_PATH=
|
||||
|
||||
#################################
|
||||
# Check for secondary file name #
|
||||
#################################
|
||||
if [[ $FILE_EXTENSION == 'yml' ]]; then
|
||||
# Need to see if yaml also exists
|
||||
SECONDARY_FILE_NAME="$FILE_NAME.yaml"
|
||||
elif [[ $FILE_EXTENSION == 'yaml' ]]; then
|
||||
# need to see if yml also exists
|
||||
SECONDARY_FILE_NAME="$FILE_NAME.yml"
|
||||
fi
|
||||
|
||||
###############################
|
||||
# Set Flag for set Rules File #
|
||||
###############################
|
||||
SET_RULES=0
|
||||
|
||||
#####################################
|
||||
# Validate we have the linter rules #
|
||||
#####################################
|
||||
LANGUAGE_FILE_PATH="${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}"
|
||||
debug "Checking if the user-provided:[${!LANGUAGE_FILE_NAME}] and exists at:[${LANGUAGE_FILE_PATH}]"
|
||||
if [ -f "${LANGUAGE_FILE_PATH}" ]; then
|
||||
info "----------------------------------------------"
|
||||
info "User provided file:[${LANGUAGE_FILE_PATH}] exists, setting rules file..."
|
||||
|
||||
########################################
|
||||
# Update the path to the file location #
|
||||
########################################
|
||||
eval "${LANGUAGE_LINTER_RULES}=${LANGUAGE_FILE_PATH}"
|
||||
######################
|
||||
# Set the rules flag #
|
||||
######################
|
||||
SET_RULES=1
|
||||
else
|
||||
# Failed to find the primary rules file
|
||||
debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}]."
|
||||
fi
|
||||
|
||||
####################################################
|
||||
# Check if we have secondary file name to look for #
|
||||
####################################################
|
||||
if [ -n "$SECONDARY_FILE_NAME" ] && [ "${SET_RULES}" -eq 0 ]; then
|
||||
# Set the path
|
||||
SECONDARY_LANGUAGE_FILE_PATH="${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${SECONDARY_FILE_NAME}"
|
||||
debug "${LANGUAGE_NAME} language rule file has a secondary rules file name to check (${SECONDARY_FILE_NAME}). Path:[${SECONDARY_LANGUAGE_FILE_PATH}]"
|
||||
|
||||
if [ -f "${SECONDARY_LANGUAGE_FILE_PATH}" ]; then
|
||||
info "----------------------------------------------"
|
||||
info "User provided file:[${SECONDARY_LANGUAGE_FILE_PATH}] exists, setting rules file..."
|
||||
|
||||
########################################
|
||||
# Update the path to the file location #
|
||||
########################################
|
||||
eval "${LANGUAGE_LINTER_RULES}=${SECONDARY_LANGUAGE_FILE_PATH}"
|
||||
######################
|
||||
# Set the rules flag #
|
||||
######################
|
||||
SET_RULES=1
|
||||
fi
|
||||
fi
|
||||
|
||||
##############################################################
|
||||
# We didnt find rules from user, setting to default template #
|
||||
##############################################################
|
||||
if [ "${SET_RULES}" -eq 0 ]; then
|
||||
########################################################
|
||||
# No user default provided, using the template default #
|
||||
########################################################
|
||||
eval "${LANGUAGE_LINTER_RULES}=${DEFAULT_RULES_LOCATION}/${!LANGUAGE_FILE_NAME}"
|
||||
debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}], nor the file:[${SECONDARY_LANGUAGE_FILE_PATH}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]"
|
||||
######################
|
||||
# Set the rules flag #
|
||||
######################
|
||||
SET_RULES=1
|
||||
fi
|
||||
|
||||
####################
|
||||
# Debug Print info #
|
||||
####################
|
||||
debug " -> Language rules file variable (${LANGUAGE_LINTER_RULES}) value is:[${!LANGUAGE_LINTER_RULES}]"
|
||||
|
||||
############################
|
||||
# Validate the file exists #
|
||||
############################
|
||||
if [ -e "${!LANGUAGE_LINTER_RULES}" ]; then
|
||||
# Found the rules file
|
||||
debug " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) exists."
|
||||
else
|
||||
# Here we expect a rules file, so fail if not available.
|
||||
fatal " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) doesn't exist. Terminating..."
|
||||
fi
|
||||
|
||||
######################
|
||||
# Export the results #
|
||||
######################
|
||||
eval "export ${LANGUAGE_LINTER_RULES}"
|
||||
}
|
||||
################################################################################
|
||||
#### Function GetStandardRules #################################################
|
||||
GetStandardRules() {
|
||||
################
|
||||
# Pull In Vars #
|
||||
################
|
||||
LINTER="${1}" # Type: javascript | typescript
|
||||
|
||||
#########################################################################
|
||||
# Need to get the ENV vars from the linter rules to run in command line #
|
||||
#########################################################################
|
||||
# Copy orig IFS to var
|
||||
ORIG_IFS="${IFS}"
|
||||
# Set the IFS to newline
|
||||
IFS=$'\n'
|
||||
|
||||
#########################################
|
||||
# Get list of all environment variables #
|
||||
#########################################
|
||||
# Only env vars that are marked as true
|
||||
GET_ENV_ARRAY=()
|
||||
if [[ ${LINTER} == "javascript" ]]; then
|
||||
mapfile -t GET_ENV_ARRAY < <(yq .env "${JAVASCRIPT_STANDARD_LINTER_RULES}" | grep true)
|
||||
elif [[ ${LINTER} == "typescript" ]]; then
|
||||
mapfile -t GET_ENV_ARRAY < <(yq .env "${TYPESCRIPT_STANDARD_LINTER_RULES}" | grep true)
|
||||
fi
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||
# ERROR
|
||||
error "Failed to gain list of ENV vars to load!"
|
||||
fatal "[${GET_ENV_ARRAY[*]}]"
|
||||
fi
|
||||
|
||||
##########################
|
||||
# Set IFS back to normal #
|
||||
##########################
|
||||
# Set IFS back to Orig
|
||||
IFS="${ORIG_IFS}"
|
||||
|
||||
######################
|
||||
# Set the env string #
|
||||
######################
|
||||
ENV_STRING=''
|
||||
|
||||
#############################
|
||||
# Pull out the envs to load #
|
||||
#############################
|
||||
for ENV in "${GET_ENV_ARRAY[@]}"; do
|
||||
#############################
|
||||
# remove spaces from return #
|
||||
#############################
|
||||
ENV="$(echo -e "${ENV}" | tr -d '[:space:]')"
|
||||
################################
|
||||
# Get the env to add to string #
|
||||
################################
|
||||
ENV="$(echo "${ENV}" | cut -d'"' -f2)"
|
||||
debug "ENV:[${ENV}]"
|
||||
ENV_STRING+="--env ${ENV} "
|
||||
done
|
||||
|
||||
#########################################
|
||||
# Remove trailing and ending whitespace #
|
||||
#########################################
|
||||
if [[ ${LINTER} == "javascript" ]]; then
|
||||
JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
elif [[ ${LINTER} == "typescript" ]]; then
|
||||
TYPESCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectOpenAPIFile ################################################
|
||||
DetectOpenAPIFile() {
|
||||
################
|
||||
# Pull in vars #
|
||||
################
|
||||
FILE="${1}"
|
||||
debug "Checking if ${FILE} is an OpenAPI file..."
|
||||
|
||||
###############################
|
||||
# Check the file for keywords #
|
||||
###############################
|
||||
grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "${FILE}" >/dev/null
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -eq 0 ]; then
|
||||
########################
|
||||
# Found string in file #
|
||||
########################
|
||||
return 0
|
||||
else
|
||||
###################
|
||||
# No string match #
|
||||
###################
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectTektonFile #################################################
|
||||
DetectTektonFile() {
|
||||
################
|
||||
# Pull in vars #
|
||||
################
|
||||
FILE="${1}"
|
||||
debug "Checking if ${FILE} is a Tekton file..."
|
||||
|
||||
###############################
|
||||
# Check the file for keywords #
|
||||
###############################
|
||||
grep -q -E 'apiVersion: tekton' "${FILE}" >/dev/null
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -eq 0 ]; then
|
||||
########################
|
||||
# Found string in file #
|
||||
########################
|
||||
return 0
|
||||
else
|
||||
###################
|
||||
# No string match #
|
||||
###################
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectARMFile ####################################################
|
||||
DetectARMFile() {
|
||||
################
|
||||
# Pull in vars #
|
||||
################
|
||||
FILE="${1}" # Name of the file/path we are validating
|
||||
debug "Checking if ${FILE} is an ARM file..."
|
||||
|
||||
###############################
|
||||
# Check the file for keywords #
|
||||
###############################
|
||||
grep -E 'schema.management.azure.com' "${FILE}" >/dev/null
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -eq 0 ]; then
|
||||
########################
|
||||
# Found string in file #
|
||||
########################
|
||||
return 0
|
||||
else
|
||||
###################
|
||||
# No string match #
|
||||
###################
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectCloudFormationFile #########################################
|
||||
DetectCloudFormationFile() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="${1}" # File that we need to validate
|
||||
debug "Checking if ${FILE} is a Cloud Formation file..."
|
||||
|
||||
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-formats.html
|
||||
# AWSTemplateFormatVersion is optional
|
||||
#######################################
|
||||
# Check if file has AWS Template info #
|
||||
#######################################
|
||||
if grep -q 'AWSTemplateFormatVersion' "${FILE}" >/dev/null; then
|
||||
# Found it
|
||||
return 0
|
||||
fi
|
||||
|
||||
#####################################
|
||||
# See if it contains AWS References #
|
||||
#####################################
|
||||
if grep -q -E '(AWS|Alexa|Custom)::' "${FILE}" >/dev/null; then
|
||||
# Found it
|
||||
return 0
|
||||
fi
|
||||
|
||||
#####################################################
|
||||
# No identifiers of a CLOUDFORMATION template found #
|
||||
#####################################################
|
||||
return 1
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectKubernetesFile #########################################
|
||||
DetectKubernetesFile() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="${1}" # File that we need to validate
|
||||
debug "Checking if ${FILE} is a Kubernetes descriptor..."
|
||||
|
||||
if grep -v 'kustomize.config.k8s.io' "${FILE}" | grep -v tekton | grep -q -E '(apiVersion):'; then
|
||||
debug "${FILE} is a Kubernetes descriptor"
|
||||
return 0
|
||||
fi
|
||||
|
||||
debug "${FILE} is NOT a Kubernetes descriptor"
|
||||
return 1
|
||||
}
|
||||
################################################################################
|
||||
#### Function DetectAWSStatesFIle ##############################################
|
||||
DetectAWSStatesFIle() {
|
||||
################
|
||||
# Pull in Vars #
|
||||
################
|
||||
FILE="${1}" # File that we need to validate
|
||||
debug "Checking if ${FILE} is a AWS states descriptor..."
|
||||
|
||||
# https://states-language.net/spec.html#example
|
||||
###############################
|
||||
# check if file has resources #
|
||||
###############################
|
||||
if grep -q '"Resource": *"arn"*' "${FILE}"; then
|
||||
# Found it
|
||||
return 0
|
||||
fi
|
||||
|
||||
#################################################
|
||||
# No identifiers of a AWS States Language found #
|
||||
#################################################
|
||||
return 1
|
||||
}
|
||||
################################################################################
|
||||
#### Function GetGitHubVars ####################################################
|
||||
GetGitHubVars() {
|
||||
##########
|
||||
|
@ -1007,39 +575,6 @@ CallStatusAPI() {
|
|||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function Reports ##########################################################
|
||||
Reports() {
|
||||
info "----------------------------------------------"
|
||||
info "----------------------------------------------"
|
||||
info "Generated reports:"
|
||||
info "----------------------------------------------"
|
||||
info "----------------------------------------------"
|
||||
|
||||
###################################
|
||||
# Prints output report if enabled #
|
||||
###################################
|
||||
if [ -z "${FORMAT_REPORT}" ]; then
|
||||
info "Reports generated in folder ${REPORT_OUTPUT_FOLDER}"
|
||||
#############################################
|
||||
# Print info on reports that were generated #
|
||||
#############################################
|
||||
if [ -d "${REPORT_OUTPUT_FOLDER}" ]; then
|
||||
info "Contents of report folder:"
|
||||
OUTPUT_CONTENTS_CMD=$(ls "${REPORT_OUTPUT_FOLDER}")
|
||||
info "$OUTPUT_CONTENTS_CMD"
|
||||
else
|
||||
warn "Report output folder (${REPORT_OUTPUT_FOLDER}) does NOT exist."
|
||||
fi
|
||||
fi
|
||||
|
||||
################################
|
||||
# Prints for warnings if found #
|
||||
################################
|
||||
for TEST in "${WARNING_ARRAY_TEST[@]}"; do
|
||||
warn "Expected file to compare with was not found for ${TEST}"
|
||||
done
|
||||
}
|
||||
################################################################################
|
||||
#### Function Footer ###########################################################
|
||||
Footer() {
|
||||
info "----------------------------------------------"
|
||||
|
@ -1052,6 +587,7 @@ Footer() {
|
|||
# Need to clean up the lanuage array of duplicates #
|
||||
####################################################
|
||||
mapfile -t UNIQUE_LINTED_ARRAY < <(for LANG in "${LINTED_LANGUAGES_ARRAY[@]}"; do echo "${LANG}"; done | sort -u)
|
||||
export UNIQUE_LINTED_ARRAY # Workaround SC2034
|
||||
|
||||
##############################
|
||||
# Prints for errors if found #
|
||||
|
@ -1118,31 +654,6 @@ Footer() {
|
|||
exit 0
|
||||
}
|
||||
################################################################################
|
||||
#### Function CheckInArray #####################################################
|
||||
CheckInArray() {
|
||||
###############
|
||||
# Pull in Var #
|
||||
###############
|
||||
NEEDLE="$1" # Language we need to match
|
||||
|
||||
######################################
|
||||
# Check if Language was in the array #
|
||||
######################################
|
||||
for LANG in "${UNIQUE_LINTED_ARRAY[@]}"; do
|
||||
if [[ "${LANG}" == "${NEEDLE}" ]]; then
|
||||
############
|
||||
# Found it #
|
||||
############
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
###################
|
||||
# Did not find it #
|
||||
###################
|
||||
return 1
|
||||
}
|
||||
################################################################################
|
||||
#### Function Cleanup ##########################################################
|
||||
cleanup() {
|
||||
local -ri EXIT_CODE=$?
|
||||
|
|
Loading…
Reference in a new issue