superlint/lib/buildFileList.sh

728 lines
27 KiB
Bash
Raw Normal View History

2020-06-29 10:55:59 -04:00
#!/usr/bin/env bash
################################################################################
################################################################################
########### Super-Linter Build File List Functions @admiralawkbar ##############
################################################################################
################################################################################
########################## FUNCTION CALLS BELOW ################################
################################################################################
################################################################################
#### Function BuildFileList ####################################################
2020-07-01 17:40:40 -04:00
function BuildFileList() {
2020-06-29 10:55:59 -04:00
# Need to build a list of all files changed
# This can be pulled from the GITHUB_EVENT_PATH payload
################
# print header #
################
2020-07-30 16:39:05 -04:00
debug "----------------------------------------------"
debug "Pulling in code history and branches..."
2020-06-29 10:55:59 -04:00
#################################################################################
# Switch codebase back to the default branch to get a list of all files changed #
#################################################################################
2020-07-01 17:40:40 -04:00
SWITCH_CMD=$(
2020-07-21 13:09:07 -04:00
git -C "${GITHUB_WORKSPACE}" pull --quiet
git -C "${GITHUB_WORKSPACE}" checkout "${DEFAULT_BRANCH}" 2>&1
2020-07-01 17:40:40 -04:00
)
2020-06-29 10:55:59 -04:00
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
2020-07-21 13:09:07 -04:00
if [ ${ERROR_CODE} -ne 0 ]; then
2020-06-29 10:55:59 -04:00
# Error
2020-07-30 16:39:05 -04:00
info "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!"
fatal "[${SWITCH_CMD}]"
2020-06-29 10:55:59 -04:00
fi
################
# print header #
################
2020-07-30 16:39:05 -04:00
debug "----------------------------------------------"
2020-08-11 09:55:42 -04:00
debug "Generating Diff with:[git diff --name-only '${DEFAULT_BRANCH}...${GITHUB_SHA}' --diff-filter=d]"
2020-06-29 10:55:59 -04:00
#################################################
# Get the Array of files changed in the commits #
#################################################
2020-08-11 09:55:42 -04:00
mapfile -t RAW_FILE_ARRAY < <(git -C "${GITHUB_WORKSPACE}" diff --name-only "${DEFAULT_BRANCH}...${GITHUB_SHA}" --diff-filter=d 2>&1)
2020-06-29 10:55:59 -04:00
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
2020-07-21 13:09:07 -04:00
if [ ${ERROR_CODE} -ne 0 ]; then
2020-06-29 10:55:59 -04:00
# Error
2020-07-30 16:39:05 -04:00
error "Failed to gain a list of all files changed!"
fatal "[${RAW_FILE_ARRAY[*]}]"
2020-06-29 10:55:59 -04:00
fi
################################################
# Iterate through the array of all files found #
################################################
2020-07-30 16:39:05 -04:00
info "----------------------------------------------"
2020-08-27 15:26:05 -04:00
info "------ Files modified in the commit(s): ------"
info "----------------------------------------------"
2020-07-01 17:40:40 -04:00
for FILE in "${RAW_FILE_ARRAY[@]}"; do
2020-06-29 10:55:59 -04:00
###########################
# Get the files extension #
###########################
2020-07-22 13:27:45 -04:00
# Extract just the file extension
FILE_TYPE=${FILE##*.}
# To lowercase
FILE_TYPE=${FILE_TYPE,,}
2020-08-13 13:40:21 -04:00
# get the baseFile for additonal logic
BASE_FILE=$(basename "${FILE,,}")
2020-06-29 10:55:59 -04:00
2020-07-06 09:29:36 -04:00
##############
# Print file #
##############
2020-08-13 13:40:21 -04:00
info "File:[${FILE}], File_type:[${FILE_TYPE}], Base_file:[${BASE_FILE}]"
2020-07-06 09:29:36 -04:00
2020-06-29 10:55:59 -04:00
#########
# DEBUG #
#########
2020-07-30 16:39:05 -04:00
debug "FILE_TYPE:[${FILE_TYPE}]"
2020-06-29 10:55:59 -04:00
2020-08-31 12:51:03 -04:00
######################
# Get the BASH files #
######################
if [ "${FILE_TYPE}" == "sh" ] || [ "${FILE_TYPE}" == "bash" ] ||
[ "${FILE_TYPE}" == "dash" ] || [ "${FILE_TYPE}" == "ksh" ]; then
# Need to check if its a zsh file as we cannot parse it
if CheckZsh "${FILE}"; then
2020-08-31 13:47:05 -04:00
warn "Found [zsh] script: ${FILE}"
2020-08-31 12:51:03 -04:00
info "ShellCheck does NOT currently support zsh, skipping file"
else
2020-06-29 15:38:24 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_BASH+=("${FILE}")
2020-07-01 12:59:00 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-06-29 10:55:59 -04:00
fi
2020-08-31 12:51:03 -04:00
#########################
# Get the CLOJURE files #
#########################
elif [ "${FILE_TYPE}" == "clj" ] || [ "${FILE_TYPE}" == "cljs" ] ||
[ "${FILE_TYPE}" == "cljc" ] || [ "${FILE_TYPE}" == "edn" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_CLOJURE+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
########################
# Get the COFFEE files #
########################
elif [ "${FILE_TYPE}" == "coffee" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_COFFEESCRIPT+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
########################
# Get the CSHARP files #
########################
elif [ "${FILE_TYPE}" == "cs" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_CSHARP+=("${FILE}")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
#####################
# Get the CSS files #
#####################
elif [ "${FILE_TYPE}" == "css" ] || [ "${FILE_TYPE}" == "scss" ] ||
[ "${FILE_TYPE}" == "sass" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_CSS+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
2020-07-05 22:21:13 -04:00
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
2020-07-05 22:21:13 -04:00
######################
2020-08-31 12:51:03 -04:00
# Get the DART files #
2020-07-05 22:21:13 -04:00
######################
2020-08-31 12:51:03 -04:00
elif [ "${FILE_TYPE}" == "dart" ]; then
2020-07-05 22:21:13 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_DART+=("${FILE}")
2020-07-05 22:21:13 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
2020-06-29 10:55:59 -04:00
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
########################
# Get the DOCKER files #
########################
elif [ "${FILE_TYPE}" == "dockerfile" ] || [[ "${BASE_FILE}" == *"dockerfile."* ]]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_DOCKER+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
#####################
# Get the ENV files #
#####################
elif [ "${FILE_TYPE}" == "env" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_ENV+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
2020-06-29 10:55:59 -04:00
########################
2020-08-31 12:51:03 -04:00
# Get the Golang files #
2020-06-29 10:55:59 -04:00
########################
2020-08-31 12:51:03 -04:00
elif [ "${FILE_TYPE}" == "go" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_GO+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
2020-06-29 10:55:59 -04:00
########################
2020-08-31 12:51:03 -04:00
# Get the GROOVY files #
2020-06-29 10:55:59 -04:00
########################
2020-08-31 12:51:03 -04:00
elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ] ||
[ "$FILE_TYPE" == "gradle" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_GROOVY+=("$FILE")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
######################
# Get the HTML files #
######################
elif [ "${FILE_TYPE}" == "html" ]; then
################################
# Append the file to the array #
##############################p##
FILE_ARRAY_HTML+=("${FILE}")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-05 14:35:14 -04:00
######################
# Get the Java files #
######################
elif [ "${FILE_TYPE}" == "java" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_JAVA+=("${FILE}")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
2020-06-29 10:55:59 -04:00
############################
# Get the JavaScript files #
############################
2020-07-21 13:09:07 -04:00
elif [ "${FILE_TYPE}" == "js" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-07-21 13:09:07 -04:00
FILE_ARRAY_JAVASCRIPT_ES+=("${FILE}")
FILE_ARRAY_JAVASCRIPT_STANDARD+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
#####################
2020-07-07 11:02:56 -04:00
# Get the JSX files #
2020-08-31 12:51:03 -04:00
#####################
######################
# Get the JSON files #
######################
elif [ "${FILE_TYPE}" == "json" ]; then
2020-07-07 11:02:56 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_JSON+=("${FILE}")
############################
# Check if file is OpenAPI #
############################
if DetectOpenAPIFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_OPENAPI+=("${FILE}")
fi
############################
# Check if file is ARM #
############################
if DetectARMFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_ARM+=("${FILE}")
fi
#####################################
# Check if the file is CFN template #
#####################################
if DetectCloudFormationFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CLOUDFORMATION+=("${FILE}")
fi
############################################
# Check if the file is AWS States Language #
############################################
if DetectAWSStatesFIle "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_STATES+=("${FILE}")
fi
2020-07-07 11:02:56 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
elif [ "${FILE_TYPE}" == "jsx" ]; then
2020-07-07 11:02:56 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_JSX+=("${FILE}")
2020-07-07 11:02:56 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
########################
# Get the KOTLIN files #
########################
elif [ "${FILE_TYPE}" == "kt" ] || [ "${FILE_TYPE}" == "kts" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_KOTLIN+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
#####################
# Get the LUA files #
#####################
elif [ "$FILE_TYPE" == "lua" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_LUA+=("$FILE")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
2020-08-18 18:54:32 -04:00
#######################
# Get the LaTeX files #
#######################
elif [ "${FILE_TYPE}" == "tex" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_LATEX+=("${FILE}")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
##########################
# Get the MARKDOWN files #
##########################
elif [ "${FILE_TYPE}" == "md" ]; then
2020-08-15 18:53:08 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_MARKDOWN+=("${FILE}")
######################
# Get the PHP files #
######################
elif [ "${FILE_TYPE}" == "php" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_PHP_BUILTIN+=("${FILE}")
FILE_ARRAY_PHP_PHPCS+=("${FILE}")
FILE_ARRAY_PHP_PHPSTAN+=("${FILE}")
FILE_ARRAY_PHP_PSALM+=("${FILE}")
2020-08-15 18:53:08 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
######################
# Get the PERL files #
######################
elif [ "${FILE_TYPE}" == "pl" ] || [ "${FILE_TYPE}" == "pm" ] ||
[ "${FILE_TYPE}" == "t" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_PERL+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
############################
2020-06-29 10:55:59 -04:00
# Get the Powershell files #
2020-08-31 12:51:03 -04:00
############################
2020-07-21 13:09:07 -04:00
elif [ "${FILE_TYPE}" == "ps1" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-07-21 13:09:07 -04:00
FILE_ARRAY_POWERSHELL+=("${FILE}")
2020-08-25 15:21:22 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
#################################
# Get the PROTOCOL BUFFER files #
#################################
elif [ "${FILE_TYPE}" == "proto" ]; then
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_PROTOBUF+=("${FILE}")
2020-08-25 15:21:22 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
########################
# Get the PYTHON files #
########################
elif [ "${FILE_TYPE}" == "py" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_PYTHON_PYLINT+=("${FILE}")
FILE_ARRAY_PYTHON_FLAKE8+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
######################
# Get the RAKU files #
######################
elif [ "${FILE_TYPE}" == "raku" ] || [ "${FILE_TYPE}" == "rakumod" ] ||
[ "${FILE_TYPE}" == "rakutest" ] || [ "${FILE_TYPE}" == "pm6" ] ||
[ "${FILE_TYPE}" == "pl6" ] || [ "${FILE_TYPE}" == "p6" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_RAKU+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
####################
# Get the R files #
####################
elif [ "${FILE_TYPE}" == "r" ] || [ "${FILE_TYPE}" == "rmd" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_R+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
######################
# Get the RUBY files #
######################
elif [ "${FILE_TYPE}" == "rb" ]; then
2020-07-30 16:39:05 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_RUBY+=("${FILE}")
2020-07-30 16:39:05 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
#####################
# Get the SQL files #
#####################
elif [ "${FILE_TYPE}" == "sql" ]; then
2020-07-06 04:17:20 -04:00
################################
# Append the file to the array #
2020-08-31 12:51:03 -04:00
##############################p##
FILE_ARRAY_SQL+=("${FILE}")
2020-07-06 04:17:20 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
###########################
# Get the Terraform files #
###########################
elif [ "${FILE_TYPE}" == "tf" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_TERRAFORM+=("${FILE}")
FILE_ARRAY_TERRAFORM_TERRASCAN+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
############################
# Get the TypeScript files #
############################
elif [ "${FILE_TYPE}" == "ts" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_TYPESCRIPT_ES+=("${FILE}")
FILE_ARRAY_TYPESCRIPT_STANDARD+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
#####################
# Get the TSX files #
#####################
elif [ "${FILE_TYPE}" == "tsx" ]; then
2020-06-29 10:55:59 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_TSX+=("${FILE}")
2020-06-29 10:55:59 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
2020-07-04 18:14:27 -04:00
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
#####################
# Get the XML files #
#####################
elif [ "${FILE_TYPE}" == "xml" ]; then
2020-07-04 18:14:27 -04:00
################################
# Append the file to the array #
2020-08-06 13:01:36 -04:00
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_XML+=("${FILE}")
2020-08-06 13:01:36 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
################################
# Get the CLOUDFORMATION files #
################################
elif [ "${FILE_TYPE}" == "yml" ] || [ "${FILE_TYPE}" == "yaml" ]; then
2020-07-14 10:28:58 -04:00
################################
# Append the file to the array #
################################
2020-08-31 12:51:03 -04:00
FILE_ARRAY_YAML+=("${FILE}")
2020-07-14 10:28:58 -04:00
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
2020-06-29 10:55:59 -04:00
READ_ONLY_CHANGE_FLAG=1
2020-08-31 12:51:03 -04:00
#####################################
# Check if the file is CFN template #
#####################################
if DetectCloudFormationFile "${FILE}"; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CLOUDFORMATION+=("${FILE}")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
fi
########################################################################
# We have something that we need to try to check file type another way #
########################################################################
2020-06-29 10:55:59 -04:00
else
##############################################
# Use file to see if we can parse what it is #
##############################################
2020-08-24 12:11:10 -04:00
CheckFileType "${FILE}"
2020-08-24 12:16:22 -04:00
fi
2020-06-29 10:55:59 -04:00
done
2020-07-30 16:39:05 -04:00
export READ_ONLY_CHANGE_FLAG # Workaround SC2034
2020-06-29 10:55:59 -04:00
#########################################
# Need to switch back to branch of code #
#########################################
2020-07-21 13:09:07 -04:00
SWITCH2_CMD=$(git -C "${GITHUB_WORKSPACE}" checkout --progress --force "${GITHUB_SHA}" 2>&1)
2020-06-29 10:55:59 -04:00
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
2020-07-21 13:09:07 -04:00
if [ ${ERROR_CODE} -ne 0 ]; then
2020-06-29 10:55:59 -04:00
# Error
2020-07-30 16:39:05 -04:00
error "Failed to switch back to branch!"
fatal "[${SWITCH2_CMD}]"
2020-06-29 10:55:59 -04:00
fi
################
# Footer print #
################
2020-07-30 16:39:05 -04:00
info "----------------------------------------------"
info "Successfully gathered list of files..."
2020-06-29 10:55:59 -04:00
}
2020-08-24 12:11:10 -04:00
################################################################################
#### 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"
##################
# Check the file #
##################
GET_FILE_TYPE_CMD=$(file "${FILE}" 2>&1)
#################
# Check if bash #
#################
if [[ ${GET_FILE_TYPE_CMD} == *"Bourne-Again shell script"* ]]; then
#######################
# It is a bash script #
#######################
warn "Found bash script without extension:[.sh]"
info "Please update file with proper extensions."
################################
# Append the file to the array #
################################
FILE_ARRAY_BASH+=("${FILE}")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
elif [[ ${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}")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
elif [[ ${GET_FILE_TYPE_CMD} == *"zsh script"* ]]; then
######################
# It is a ZSH script #
######################
warn "Found [zsh] script"
info "ShellCheck does NOT currently support zsh, skipping file"
else
############################
# Extension was not found! #
############################
warn "Failed to get filetype for:[${FILE}]!"
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
fi
}
################################################################################
#### Function CheckZsh #########################################################
function CheckZsh() {
# Spagetti code to make sure were properly excluding zsh
# until we get a proper linter
################
# Pull in Vars #
################
FILE="$1"
##################
# Check the file #
##################
GET_FILE_TYPE_CMD=$(file "${FILE}" 2>&1)
if [[ ${GET_FILE_TYPE_CMD} == *"zsh script"* ]]; then
######################
# It is a ZSH script #
######################
warn "Found [zsh] script"
info "ShellCheck does NOT currently support zsh, skipping file"
###################################################
# We found zsh file and need to return with a hit #
###################################################
return 0
else
##################
# Not a zsh file #
##################
return 1
fi
}