2020-06-29 10:55:59 -04:00
#!/usr/bin/env bash
2023-05-22 20:30:16 -04:00
function IssueHintForFullGitHistory( ) {
2024-01-04 16:54:47 -05:00
info "Check that the local repository has the full history and that the repository is not shallow."
info "See https://github.com/super-linter/super-linter#get-started"
2023-12-04 04:47:49 -05:00
info " Is shallow repository: $( git -C " ${ GITHUB_WORKSPACE } " rev-parse --is-shallow-repository) "
2023-05-22 20:30:16 -04:00
}
2021-03-02 09:29:12 -05:00
function GenerateFileDiff( ) {
2023-12-23 13:33:53 -05:00
DIFF_GIT_DEFAULT_BRANCH_CMD = " git -C \" ${ GITHUB_WORKSPACE } \" diff --diff-filter=d --name-only ${ DEFAULT_BRANCH } ... ${ GITHUB_SHA } | xargs -I % sh -c 'echo \" ${ GITHUB_WORKSPACE } /%\"' 2>&1 "
DIFF_TREE_CMD = " git -C \" ${ GITHUB_WORKSPACE } \" diff-tree --no-commit-id --name-only -r ${ GITHUB_SHA } ${ GITHUB_BEFORE_SHA } | xargs -I % sh -c 'echo \" ${ GITHUB_WORKSPACE } /%\"' 2>&1 "
if [ " ${ GITHUB_EVENT_NAME :- } " = = "push" ] ; then
RunFileDiffCommand " ${ DIFF_TREE_CMD } "
if [ ${# RAW_FILE_ARRAY [@] } -eq 0 ] ; then
debug "Generating the file array with diff-tree produced [0] items, trying with git diff against the default branch..."
RunFileDiffCommand " ${ DIFF_GIT_DEFAULT_BRANCH_CMD } "
fi
else
RunFileDiffCommand " ${ DIFF_GIT_DEFAULT_BRANCH_CMD } "
fi
}
function RunFileDiffCommand( ) {
2024-01-30 02:48:24 -05:00
local CMD
2021-03-02 09:29:12 -05:00
CMD = " ${ 1 } "
debug " Generating Diff with:[ $CMD ] "
#################################################
# Get the Array of files changed in the commits #
#################################################
2024-01-30 02:48:24 -05:00
if ! CMD_OUTPUT = $( eval " set -eo pipefail; $CMD ; set +eo pipefail " ) ; then
2023-12-04 04:47:49 -05:00
error " Failed to get Diff with:[ $CMD ] "
2023-05-22 20:30:16 -04:00
IssueHintForFullGitHistory
2024-01-30 02:48:24 -05:00
fatal " Diff command output: ${ CMD_OUTPUT } "
2021-03-02 09:29:12 -05:00
fi
2021-03-05 12:25:31 -05:00
mapfile -t RAW_FILE_ARRAY < <( echo -n " $CMD_OUTPUT " )
2021-03-02 09:29:12 -05:00
}
2020-07-01 17:40:40 -04:00
function BuildFileList( ) {
2020-10-03 06:55:34 -04:00
debug "Building file list..."
2020-06-29 10:55:59 -04:00
2020-10-03 06:55:34 -04:00
VALIDATE_ALL_CODEBASE = " ${ 1 } "
2021-12-08 15:28:30 -05:00
debug " VALIDATE_ALL_CODEBASE: ${ VALIDATE_ALL_CODEBASE } "
2020-10-03 06:55:34 -04:00
2020-10-14 04:59:34 -04:00
TEST_CASE_RUN = " ${ 2 } "
2021-12-08 15:28:30 -05:00
debug " TEST_CASE_RUN: ${ TEST_CASE_RUN } "
2020-10-14 04:59:34 -04:00
if [ " ${ VALIDATE_ALL_CODEBASE } " = = "false" ] && [ " ${ TEST_CASE_RUN } " != "true" ] ; then
2023-12-04 04:47:49 -05:00
debug "Build the list of all changed files"
2021-03-05 09:57:16 -05:00
2023-12-23 13:33:53 -05:00
GenerateFileDiff
2020-10-03 06:55:34 -04:00
else
2021-06-08 11:40:59 -04:00
if [ " ${ USE_FIND_ALGORITHM } " = = 'true' ] ; then
2024-01-30 14:24:55 -05:00
debug " Populating the file list with all the files in the ${ GITHUB_WORKSPACE } workspace using FIND algorithm "
if ! mapfile -t RAW_FILE_ARRAY < <( find " ${ GITHUB_WORKSPACE } " \
2021-06-08 11:40:59 -04:00
-not \( -path '*/\.git' -prune \) \
-not \( -path '*/\.pytest_cache' -prune \) \
-not \( -path '*/\.rbenv' -prune \) \
-not \( -path '*/\.terragrunt-cache' -prune \) \
-not \( -path '*/\.venv' -prune \) \
-not \( -path '*/\__pycache__' -prune \) \
-not \( -path '*/\node_modules' -prune \) \
-not -name ".DS_Store" \
-not -name "*.gif" \
-not -name "*.ico" \
-not -name "*.jpg" \
-not -name "*.jpeg" \
-not -name "*.pdf" \
-not -name "*.png" \
-not -name "*.webp" \
-not -name "*.woff" \
-not -name "*.woff2" \
-not -name "*.zip" \
-type f \
2024-01-30 02:48:24 -05:00
2>& 1 | sort) ; then
fatal " Failed to get a list of changed files. USE_FIND_ALGORITHM: ${ USE_FIND_ALGORITHM } "
fi
2021-06-08 11:40:59 -04:00
else
2024-01-30 14:24:55 -05:00
DIFF_GIT_VALIDATE_ALL_CODEBASE = " git -C \" ${ GITHUB_WORKSPACE } \" ls-tree -r --name-only HEAD | xargs -I % sh -c \"echo ${ GITHUB_WORKSPACE } /%\" 2>&1 "
2023-12-23 13:33:53 -05:00
debug " Populating the file list with: ${ DIFF_GIT_VALIDATE_ALL_CODEBASE } "
2024-01-30 02:48:24 -05:00
if ! mapfile -t RAW_FILE_ARRAY < <( eval " set -eo pipefail; ${ DIFF_GIT_VALIDATE_ALL_CODEBASE } ; set +eo pipefail " ) ; then
fatal " Failed to get a list of changed files. USE_FIND_ALGORITHM: ${ USE_FIND_ALGORITHM } "
fi
2021-06-08 11:40:59 -04:00
fi
2020-06-29 10:55:59 -04:00
fi
2024-01-30 02:48:24 -05:00
debug " RAW_FILE_ARRAY contents: ${ RAW_FILE_ARRAY [*] } "
2020-06-29 10:55:59 -04:00
2020-10-14 11:31:55 -04:00
if [ ${# RAW_FILE_ARRAY [@] } -eq 0 ] ; then
warn " No files were found in the GITHUB_WORKSPACE:[ ${ GITHUB_WORKSPACE } ] to lint! "
fi
2020-10-14 04:59:34 -04:00
2023-12-24 11:56:15 -05:00
####################################################
# Configure linters that scan the entire workspace #
####################################################
2024-01-30 14:24:55 -05:00
debug " Checking if we are in test mode before configuring the list of directories to lint. TEST_CASE_RUN: ${ TEST_CASE_RUN } "
2023-12-24 11:56:15 -05:00
if [ " ${ TEST_CASE_RUN } " = = "true" ] ; then
debug "We are running in test mode."
2024-01-30 14:24:55 -05:00
debug "Adding test case directories to the list of directories to analyze with JSCPD."
2023-12-24 11:56:15 -05:00
DEFAULT_JSCPD_TEST_CASE_DIRECTORY = " ${ GITHUB_WORKSPACE } / ${ TEST_CASE_FOLDER } /jscpd "
2024-01-30 14:24:55 -05:00
# We need this for parallel
export DEFAULT_JSCPD_TEST_CASE_DIRECTORY
2023-12-24 11:56:15 -05:00
debug " DEFAULT_JSCPD_TEST_CASE_DIRECTORY: ${ DEFAULT_JSCPD_TEST_CASE_DIRECTORY } "
2024-01-30 14:24:55 -05:00
RAW_FILE_ARRAY += ( " ${ DEFAULT_JSCPD_TEST_CASE_DIRECTORY } /bad " )
RAW_FILE_ARRAY += ( " ${ DEFAULT_JSCPD_TEST_CASE_DIRECTORY } /good " )
fi
debug " Add GITHUB_WORKSPACE ( ${ GITHUB_WORKSPACE } ) to the list of files to lint because we might need it for linters that lint the whole workspace "
RAW_FILE_ARRAY += ( " ${ GITHUB_WORKSPACE } " )
if [ -d " ${ ANSIBLE_DIRECTORY } " ] ; then
debug " Adding ANSIBLE_DIRECTORY ( ${ ANSIBLE_DIRECTORY } ) to the list of files and directories to lint. "
RAW_FILE_ARRAY += ( " ${ ANSIBLE_DIRECTORY } " )
2022-03-14 15:47:04 -04:00
else
2024-01-30 14:24:55 -05:00
debug " ANSIBLE_DIRECTORY ( ${ ANSIBLE_DIRECTORY } ) does NOT exist. "
fi
2023-12-24 11:56:15 -05:00
2024-01-30 14:24:55 -05:00
local PARALLEL_RESULTS_FILE_PATH
PARALLEL_RESULTS_FILE_PATH = "/tmp/super-linter-parallel-results-build-file-list.json"
debug " PARALLEL_RESULTS_FILE_PATH when building the file list: ${ PARALLEL_RESULTS_FILE_PATH } "
2023-12-24 11:56:15 -05:00
2024-01-30 14:24:55 -05:00
local -a PARALLEL_COMMAND
PARALLEL_COMMAND = ( parallel --will-cite --keep-order --max-procs " $(( $( nproc) * 1 )) " --results " ${ PARALLEL_RESULTS_FILE_PATH } " --xargs)
if [ " ${ LOG_DEBUG } " = = "true" ] ; then
debug "LOG_DEBUG is enabled. Enable verbose ouput for parallel"
PARALLEL_COMMAND += ( --verbose)
fi
2023-12-24 11:56:15 -05:00
2024-01-30 14:24:55 -05:00
# Max number of files to categorize per process
PARALLEL_COMMAND += ( --max-lines 10)
2023-12-24 11:56:15 -05:00
2024-01-30 14:24:55 -05:00
PARALLEL_COMMAND += ( "BuildFileArrays" )
debug " PARALLEL_COMMAND to build the list of files and directories to lint: ${ PARALLEL_COMMAND [*] } "
FILE_ARRAYS_DIRECTORY_PATH = " $( mktemp -d) "
export FILE_ARRAYS_DIRECTORY_PATH
debug " Created FILE_ARRAYS_DIRECTORY_PATH: ${ FILE_ARRAYS_DIRECTORY_PATH } "
info "Building the list of files and directories to check"
PARALLEL_COMMAND_OUTPUT = $( printf "%s\n" " ${ RAW_FILE_ARRAY [@] } " | " ${ PARALLEL_COMMAND [@] } " 2>& 1)
PARALLEL_COMMAND_RETURN_CODE = $?
debug " PARALLEL_COMMAND_OUTPUT to build the file list (exit code: ${ PARALLEL_COMMAND_RETURN_CODE } ):\n ${ PARALLEL_COMMAND_OUTPUT } "
debug " Parallel output file ( ${ PARALLEL_RESULTS_FILE_PATH } ) contents when building the file list:\n $( cat " ${ PARALLEL_RESULTS_FILE_PATH } " ) "
local RESULTS_OBJECT
RESULTS_OBJECT =
2024-02-05 05:49:22 -05:00
if ! RESULTS_OBJECT = $( jq --raw-output -n '[inputs]' " ${ PARALLEL_RESULTS_FILE_PATH } " ) ; then
2024-01-30 14:24:55 -05:00
fatal " Error loading results when building the file list: ${ RESULTS_OBJECT } "
fi
debug " RESULTS_OBJECT for ${ FILE_TYPE } :\n ${ RESULTS_OBJECT } "
local STDOUT_BUILD_FILE_LIST
# Get raw output so we can strip quotes from the data we load
2024-02-05 05:49:22 -05:00
if ! STDOUT_BUILD_FILE_LIST = " $( jq --raw-output '.[].Stdout[:-1]' <<< " ${ RESULTS_OBJECT } " ) " ; then
2024-01-30 14:24:55 -05:00
fatal " Error when loading stdout when building the file list: ${ STDOUT_BUILD_FILE_LIST } "
2022-03-14 15:47:04 -04:00
fi
2024-01-30 14:24:55 -05:00
if [ -n " ${ STDOUT_BUILD_FILE_LIST } " ] ; then
info " Command output when building the file list:\n------\n ${ STDOUT_BUILD_FILE_LIST } \n------ "
2023-12-22 07:22:15 -05:00
else
2024-01-30 14:24:55 -05:00
debug "Stdout when building the file list is empty"
fi
local STDERR_BUILD_FILE_LIST
2024-02-05 05:49:22 -05:00
if ! STDERR_BUILD_FILE_LIST = " $( jq --raw-output '.[].Stderr[:-1]' <<< " ${ RESULTS_OBJECT } " ) " ; then
2024-01-30 14:24:55 -05:00
fatal " Error when loading stderr when building the file list:\n ${ STDERR_BUILD_FILE_LIST } "
fi
if [ -n " ${ STDERR_BUILD_FILE_LIST } " ] ; then
2024-02-05 05:49:22 -05:00
info " Stderr when building the file list:\n------\n ${ STDERR_BUILD_FILE_LIST } \n------ "
2024-01-30 14:24:55 -05:00
else
debug "Stderr when building the file list is empty"
fi
if [ [ ${ PARALLEL_COMMAND_RETURN_CODE } -ne 0 ] ] ; then
fatal "Error when building the list of files and directories to lint."
2023-12-22 07:22:15 -05:00
fi
2024-01-30 14:24:55 -05:00
################
# Footer print #
################
info "Successfully gathered list of files..."
}
BuildFileArrays( ) {
local -a RAW_FILE_ARRAY
RAW_FILE_ARRAY = ( " $@ " )
debug " Categorizing the following files: ${ RAW_FILE_ARRAY [*] } "
debug " FILTER_REGEX_INCLUDE: ${ FILTER_REGEX_INCLUDE } , FILTER_REGEX_EXCLUDE: ${ FILTER_REGEX_EXCLUDE } "
ValidateBooleanVariable "IGNORE_GENERATED_FILES" " ${ IGNORE_GENERATED_FILES } "
ValidateBooleanVariable "IGNORE_GITIGNORED_FILES" " ${ IGNORE_GITIGNORED_FILES } "
2020-07-01 17:40:40 -04:00
for FILE in " ${ RAW_FILE_ARRAY [@] } " ; do
2023-12-16 03:30:33 -05:00
# Get the file extension
2020-08-31 17:44:35 -04:00
FILE_TYPE = " $( GetFileExtension " $FILE " ) "
2024-01-11 15:30:00 -05:00
# We want a lowercase value
local -l BASE_FILE
# Get the name of the file and the containing directory path
BASE_FILE = $( basename " ${ FILE } " )
2023-12-16 03:30:33 -05:00
FILE_DIR_NAME = " $( dirname " ${ FILE } " ) "
2020-06-29 10:55:59 -04:00
2023-12-16 03:30:33 -05:00
debug " FILE: ${ FILE } , FILE_TYPE: ${ FILE_TYPE } , BASE_FILE: ${ BASE_FILE } , FILE_DIR_NAME: ${ FILE_DIR_NAME } "
2020-06-29 10:55:59 -04:00
2024-01-30 14:24:55 -05:00
if [ ! -e " ${ FILE } " ] ; then
2020-11-10 11:02:03 -05:00
# File not found in workspace
2024-01-30 14:24:55 -05:00
warn " { $FILE } exists in commit data, but not found on file system, skipping... "
2020-11-10 11:02:03 -05:00
continue
fi
2024-01-30 14:24:55 -05:00
# Handle the corner cases of linters that are expected to lint the whole codebase,
# but we don't have a variable to explicitly set the directory
# to lint.
if [ [ " ${ FILE } " = = " ${ GITHUB_WORKSPACE } " ] ] ; then
debug " ${ FILE } matches with ${ GITHUB_WORKSPACE } . Adding it to the list of directories to lint for linters that are expected to lint the whole codebase "
if CheckovConfigurationFileContainsDirectoryOption " ${ CHECKOV_LINTER_RULES } " ; then
debug "No need to configure the directories to check for Checkov because its configuration file contains the list of directories to analyze."
debug "Add the Checkov configuration file path to the list of items to check to consume as output later."
echo " ${ CHECKOV_LINTER_RULES } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-CHECKOV "
else
debug " Adding ${ GITHUB_WORKSPACE } to the list of directories to analyze with Checkov. "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-CHECKOV "
fi
# JSCPD test cases are handled below because we first need to exclude non-relevant test cases
if [ [ " ${ TEST_CASE_RUN } " = = "false" ] ] ; then
debug " Add ${ FILE } to the list of items to lint with JSCPD "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-JSCPD "
fi
# No need to process this item furhter
2020-10-14 04:59:34 -04:00
continue
fi
2021-06-28 08:59:11 -04:00
###############################################
2021-02-03 10:52:12 -05:00
# Filter files if FILTER_REGEX_INCLUDE is set #
2021-06-28 08:59:11 -04:00
###############################################
2021-02-03 10:52:12 -05:00
if [ [ -n " $FILTER_REGEX_INCLUDE " ] ] && [ [ ! ( ${ FILE } = ~ $FILTER_REGEX_INCLUDE ) ] ] ; then
debug " FILTER_REGEX_INCLUDE didn't match. Skipping ${ FILE } "
continue
fi
2021-06-28 08:59:11 -04:00
###############################################
2021-02-03 10:52:12 -05:00
# Filter files if FILTER_REGEX_EXCLUDE is set #
2021-06-28 08:59:11 -04:00
###############################################
2021-02-03 10:52:12 -05:00
if [ [ -n " $FILTER_REGEX_EXCLUDE " ] ] && [ [ ${ FILE } = ~ $FILTER_REGEX_EXCLUDE ] ] ; then
debug " FILTER_REGEX_EXCLUDE match. Skipping ${ FILE } "
continue
fi
2021-06-28 08:59:11 -04:00
###################################################
# Filter files if FILTER_REGEX_EXCLUDE is not set #
###################################################
2023-12-06 02:32:46 -05:00
if [ " ${ IGNORE_GITIGNORED_FILES } " = = "true" ] && git -C " ${ GITHUB_WORKSPACE } " check-ignore " $FILE " ; then
2021-02-18 13:15:50 -05:00
debug " ${ FILE } is ignored by Git. Skipping ${ FILE } "
continue
fi
2021-06-28 08:59:11 -04:00
#########################################
# Filter files with at-generated marker #
#########################################
if [ " ${ IGNORE_GENERATED_FILES } " = = "true" ] && IsGenerated " $FILE " ; then
debug " ${ FILE } is generated. Skipping ${ FILE } "
continue
fi
2024-01-30 14:24:55 -05:00
# These linters check every file
local EDITORCONFIG_FILE_PATH
EDITORCONFIG_FILE_PATH = " ${ GITHUB_WORKSPACE } /.editorconfig "
if [ -e " ${ EDITORCONFIG_FILE_PATH } " ] ; then
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-EDITORCONFIG "
else
debug " Don't include ${ FILE } in the list of files to lint with editorconfig-checker because the workspace doesn't contain an EditorConfig file: ${ EDITORCONFIG_FILE_PATH } "
fi
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-GITLEAKS "
if [ [ ( " ${ FILE } " = ~ .*${ ANSIBLE_DIRECTORY } .*) ] ] && [ [ -d " ${ FILE } " ] ] ; then
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-ANSIBLE "
fi
# Handle JSCPD test cases
# At this point, we already processed the options to include or exclude files, so we
# excluded test cases that are not relevant
if [ [ " ${ TEST_CASE_RUN } " = = "true" ] ] && [ [ " ${ FILE } " = ~ .*${ DEFAULT_JSCPD_TEST_CASE_DIRECTORY } .* ] ] && [ [ -d " ${ FILE } " ] ] ; then
debug " ${ FILE } is a test case for JSCPD. Adding it to the list of items to lint with JSCPD "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-JSCPD "
fi
2022-03-14 10:22:23 -04:00
2023-09-12 12:58:09 -04:00
# See https://docs.renovatebot.com/configuration-options/
2023-09-29 16:25:37 -04:00
if [ [ " ${ BASE_FILE } " = ~ renovate.json5? ] ] ||
[ " ${ BASE_FILE } " = = ".renovaterc" ] || [ [ " ${ BASE_FILE } " = ~ .renovaterc.json5? ] ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-RENOVATE "
2023-09-12 12:58:09 -04:00
fi
2023-09-29 16:25:37 -04:00
# See https://docs.renovatebot.com/config-presets/
IFS = "," read -r -a RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES_ARRAY <<< " ${ RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES } "
for file_name in " ${ RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES_ARRAY [@] } " ; do
if [ " ${ BASE_FILE } " = = " ${ file_name } " ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-RENOVATE "
2023-09-29 16:25:37 -04:00
break
fi
done
2023-12-16 03:30:33 -05:00
if [ " ${ BASE_FILE } " = = "go.mod" ] ; then
debug " Found ${ FILE } . Checking if individual Go file linting is enabled as well. "
if [ " ${ VALIDATE_GO } " = = "true" ] ; then
debug " Checking if we are running tests. TEST_CASE_RUN: ${ TEST_CASE_RUN } "
if [ " ${ TEST_CASE_RUN } " = = "true" ] ; then
debug "Skipping the failure due to individual Go files and Go modules linting being enabled at the same time because we're in test mode."
else
fatal " Set VALIDATE_GO to false to avoid false positives due to analyzing Go files in the ${ FILE_DIR_NAME } directory individually instead of considering them in the context of a Go module. "
fi
else
debug " Considering ${ FILE_DIR_NAME } as a Go module. "
fi
2024-01-30 14:24:55 -05:00
echo " ${ FILE_DIR_NAME } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-GO_MODULES "
2023-12-16 03:30:33 -05:00
fi
2020-08-31 17:44:35 -04:00
if IsValidShellScript " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-BASH "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-BASH_EXEC "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-SHELL_SHFMT "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "clj" ] || [ " ${ FILE_TYPE } " = = "cljs" ] ||
[ " ${ FILE_TYPE } " = = "cljc" ] || [ " ${ FILE_TYPE } " = = "edn" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-CLOJURE "
2021-05-04 14:24:41 -04:00
elif [ " ${ FILE_TYPE } " = = "cpp" ] || [ " ${ FILE_TYPE } " = = "h" ] ||
[ " ${ FILE_TYPE } " = = "cc" ] || [ " ${ FILE_TYPE } " = = "hpp" ] ||
[ " ${ FILE_TYPE } " = = "cxx" ] || [ " ${ FILE_TYPE } " = = "cu" ] ||
[ " ${ FILE_TYPE } " = = "hxx" ] || [ " ${ FILE_TYPE } " = = "c++" ] ||
[ " ${ FILE_TYPE } " = = "hh" ] || [ " ${ FILE_TYPE } " = = "h++" ] ||
[ " ${ FILE_TYPE } " = = "cuh" ] || [ " ${ FILE_TYPE } " = = "c" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-CPP "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-CLANG_FORMAT "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "coffee" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-COFFEESCRIPT "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "cs" ] ; then
FILE_ARRAY_CSHARP += ( " ${ FILE } " )
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-CSHARP "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "css" ] || [ " ${ FILE_TYPE } " = = "scss" ] ||
[ " ${ FILE_TYPE } " = = "sass" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-CSS "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "dart" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-DART "
2020-10-03 06:55:34 -04:00
# Use BASE_FILE here because FILE_TYPE is not reliable when there is no file extension
2021-12-08 10:53:05 -05:00
elif [ [ " ${ FILE_TYPE } " != "tap" ] ] && [ [ " ${ FILE_TYPE } " != "yml" ] ] &&
2023-11-15 00:44:46 -05:00
[ [ " ${ FILE_TYPE } " != "yaml" ] ] && [ [ " ${ FILE_TYPE } " != "json" ] ] &&
[ [ " ${ FILE_TYPE } " != "xml" ] ] &&
[ [ " ${ BASE_FILE } " = ~ ^( .+\. ) ?( contain| dock) erfile$ ] ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-DOCKERFILE_HADOLINT "
2021-03-10 09:38:31 -05:00
elif [ " ${ FILE_TYPE } " = = "env" ] || [ [ " ${ BASE_FILE } " = = *".env." * ] ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-ENV "
2020-11-19 10:54:20 -05:00
elif [ " ${ FILE_TYPE } " = = "feature" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-GHERKIN "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "go" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-GO "
2023-01-04 21:41:19 -05:00
# Use BASE_FILE here because FILE_TYPE is not reliable when there is no file extension
2020-08-31 12:51:03 -04:00
elif [ " $FILE_TYPE " = = "groovy" ] || [ " $FILE_TYPE " = = "jenkinsfile" ] ||
2023-01-04 21:41:19 -05:00
[ " $FILE_TYPE " = = "gradle" ] || [ " $FILE_TYPE " = = "nf" ] ||
[ [ " $BASE_FILE " = ~ .*jenkinsfile.* ] ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-GROOVY "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "html" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-HTML "
2020-08-05 14:35:14 -04:00
elif [ " ${ FILE_TYPE } " = = "java" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-JAVA "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-GOOGLE_JAVA_FORMAT "
2020-07-21 13:09:07 -04:00
elif [ " ${ FILE_TYPE } " = = "js" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-JAVASCRIPT_ES "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-JAVASCRIPT_STANDARD "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-JAVASCRIPT_PRETTIER "
2021-05-11 11:54:58 -04:00
elif [ " $FILE_TYPE " = = "jsonc" ] || [ " $FILE_TYPE " = = "json5" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-JSONC "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "json" ] ; then
FILE_ARRAY_JSON += ( " ${ FILE } " )
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-JSON "
2020-08-31 12:51:03 -04:00
if DetectOpenAPIFile " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-OPENAPI "
2020-08-31 12:51:03 -04:00
fi
2024-01-30 14:24:55 -05:00
2020-08-31 12:51:03 -04:00
if DetectARMFile " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-ARM "
2020-08-31 12:51:03 -04:00
fi
2024-01-30 14:24:55 -05:00
2020-08-31 12:51:03 -04:00
if DetectCloudFormationFile " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-CLOUDFORMATION "
2020-08-31 12:51:03 -04:00
fi
2024-01-30 14:24:55 -05:00
2020-08-31 12:51:03 -04:00
if DetectAWSStatesFIle " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-STATES "
2020-08-31 12:51:03 -04:00
fi
elif [ " ${ FILE_TYPE } " = = "jsx" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-JSX "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "kt" ] || [ " ${ FILE_TYPE } " = = "kts" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-KOTLIN "
2020-08-31 12:51:03 -04:00
elif [ " $FILE_TYPE " = = "lua" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-LUA "
2020-08-18 18:54:32 -04:00
elif [ " ${ FILE_TYPE } " = = "tex" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-LATEX "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "md" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-MARKDOWN "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-NATURAL_LANGUAGE "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "php" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PHP_BUILTIN "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PHP_PHPCS "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PHP_PHPSTAN "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PHP_PSALM "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "pl" ] || [ " ${ FILE_TYPE } " = = "pm" ] ||
[ " ${ FILE_TYPE } " = = "t" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PERL "
2020-10-03 06:55:34 -04:00
elif [ " ${ FILE_TYPE } " = = "ps1" ] ||
2020-11-06 17:10:09 -05:00
[ " ${ FILE_TYPE } " = = "psm1" ] ||
[ " ${ FILE_TYPE } " = = "psd1" ] ||
[ " ${ FILE_TYPE } " = = "ps1xml" ] ||
[ " ${ FILE_TYPE } " = = "pssc" ] ||
[ " ${ FILE_TYPE } " = = "psrc" ] ||
[ " ${ FILE_TYPE } " = = "cdxml" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-POWERSHELL "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "proto" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PROTOBUF "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "py" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PYTHON_BLACK "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PYTHON_FLAKE8 "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PYTHON_ISORT "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PYTHON_PYLINT "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-PYTHON_MYPY "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "raku" ] || [ " ${ FILE_TYPE } " = = "rakumod" ] ||
[ " ${ FILE_TYPE } " = = "rakutest" ] || [ " ${ FILE_TYPE } " = = "pm6" ] ||
[ " ${ FILE_TYPE } " = = "pl6" ] || [ " ${ FILE_TYPE } " = = "p6" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-RAKU "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "r" ] || [ " ${ FILE_TYPE } " = = "rmd" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-R "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "rb" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-RUBY "
2021-02-26 09:47:21 -05:00
elif [ " ${ FILE_TYPE } " = = "rs" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-RUST_2015 "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-RUST_2018 "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-RUST_2021 "
2021-03-08 15:13:04 -05:00
elif [ " ${ BASE_FILE } " = = "cargo.toml" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-RUST_CLIPPY "
2022-01-06 10:28:26 -05:00
elif [ " ${ FILE_TYPE } " = = "scala" ] || [ " ${ FILE_TYPE } " = = "sc" ] || [ " ${ BASE_FILE } " = = "??????" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-SCALAFMT "
2020-10-03 06:55:34 -04:00
elif [ " ${ FILE_TYPE } " = = "smk" ] || [ " ${ BASE_FILE } " = = "snakefile" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-SNAKEMAKE_LINT "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-SNAKEMAKE_SNAKEFMT "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "sql" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-SQL "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-SQLFLUFF "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "tf" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TERRAFORM_TFLINT "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TERRAFORM_TERRASCAN "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TERRAFORM_FMT "
2024-01-29 07:51:28 -05:00
elif [ " ${ FILE_TYPE } " = = "hcl" ] &&
[ [ ${ FILE } != *".tflint.hcl" * ] ] &&
[ [ ${ FILE } != *".pkr.hcl" * ] ] &&
[ [ ${ FILE } != *"docker-bake.hcl" * ] ] &&
[ [ ${ FILE } != *"docker-bake.override.hcl" * ] ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TERRAGRUNT "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "ts" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TYPESCRIPT_ES "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TYPESCRIPT_STANDARD "
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TYPESCRIPT_PRETTIER "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "tsx" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TSX "
2024-01-10 03:49:04 -05:00
elif [ " ${ FILE_TYPE } " = = "txt" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TXT "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "xml" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-XML "
2020-08-31 12:51:03 -04:00
elif [ " ${ FILE_TYPE } " = = "yml" ] || [ " ${ FILE_TYPE } " = = "yaml" ] ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-YAML "
2021-07-19 10:28:49 -04:00
if DetectActions " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-GITHUB_ACTIONS "
2021-07-19 10:28:49 -04:00
fi
2020-12-04 17:04:09 -05:00
2020-08-31 12:51:03 -04:00
if DetectCloudFormationFile " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-CLOUDFORMATION "
2020-08-31 12:51:03 -04:00
fi
2020-12-23 18:16:17 -05:00
if DetectOpenAPIFile " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-OPENAPI "
2020-12-23 18:16:17 -05:00
fi
2020-10-13 11:21:23 -04:00
if DetectTektonFile " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-TEKTON "
2020-10-13 11:21:23 -04:00
fi
2020-09-21 18:53:30 -04:00
if DetectKubernetesFile " ${ FILE } " ; then
2024-01-30 14:24:55 -05:00
echo " ${ FILE } " >>" ${ FILE_ARRAYS_DIRECTORY_PATH } /file-array-KUBERNETES_KUBECONFORM "
2020-09-21 18:53:30 -04:00
fi
2020-06-29 10:55:59 -04:00
else
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
}
2024-01-30 14:24:55 -05:00
# We need this for parallel
export -f BuildFileArrays