lint/lib/linter.sh

1366 lines
54 KiB
Bash
Raw Normal View History

2020-06-23 12:02:45 -04:00
#!/usr/bin/env bash
2019-10-21 10:12:50 -04:00
################################################################################
2020-02-03 11:27:40 -05:00
################################################################################
2020-06-24 12:47:47 -04:00
########### Super-Linter (Lint all the code) @admiralawkbar ####################
2020-02-03 11:27:40 -05:00
################################################################################
2019-10-21 10:12:50 -04:00
################################################################################
##################################################################
# Debug Vars #
# Define these early, so we can use debug logging ASAP if needed #
##################################################################
RUN_LOCAL="${RUN_LOCAL}" # Boolean to see if we are running locally
ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-false}" # Boolean to see even more info (debug)
##################################################################
# Log Vars #
# Define these early, so we can use debug logging ASAP if needed #
##################################################################
2020-11-06 17:10:09 -05:00
LOG_FILE="${LOG_FILE:-super-linter.log}" # Default log file name (located in GITHUB_WORKSPACE folder)
LOG_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE)
2020-09-29 16:46:24 -04:00
if [[ ${ACTIONS_RUNNER_DEBUG} == true ]]; then LOG_LEVEL="DEBUG"; fi
# Boolean to see trace logs
LOG_TRACE=$(if [[ ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
export LOG_TRACE
# Boolean to see debug logs
LOG_DEBUG=$(if [[ ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
export LOG_DEBUG
# Boolean to see verbose logs (info function)
LOG_VERBOSE=$(if [[ ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
export LOG_VERBOSE
2020-10-28 20:08:01 -04:00
# Boolean to see notice logs
LOG_NOTICE=$(if [[ ${LOG_LEVEL} == "NOTICE" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
export LOG_NOTICE
# Boolean to see warn logs
LOG_WARN=$(if [[ ${LOG_LEVEL} == "WARN" || ${LOG_LEVEL} == "NOTICE" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
export LOG_WARN
# Boolean to see error logs
LOG_ERROR=$(if [[ ${LOG_LEVEL} == "ERROR" || ${LOG_LEVEL} == "WARN" || ${LOG_LEVEL} == "NOTICE" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi)
export LOG_ERROR
2020-06-29 10:55:59 -04:00
#########################
# Source Function Files #
#########################
2020-06-30 10:56:15 -04:00
# shellcheck source=/dev/null
2020-07-27 17:11:33 -04:00
source /action/lib/log.sh # Source the function script(s)
2020-07-01 15:00:05 -04:00
# shellcheck source=/dev/null
2020-07-01 17:40:40 -04:00
source /action/lib/buildFileList.sh # Source the function script(s)
2020-06-30 10:56:15 -04:00
# shellcheck source=/dev/null
2020-07-01 17:40:40 -04:00
source /action/lib/validation.sh # Source the function script(s)
2020-06-30 10:56:15 -04:00
# shellcheck source=/dev/null
2020-07-01 17:40:40 -04:00
source /action/lib/worker.sh # Source the function script(s)
2020-06-29 10:55:59 -04:00
2019-10-21 10:12:50 -04:00
###########
2019-10-21 12:05:55 -04:00
# GLOBALS #
2019-10-21 10:12:50 -04:00
###########
2019-10-21 15:12:37 -04:00
# Default Vars
2020-11-06 17:10:09 -05:00
DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location
2020-07-30 16:18:24 -04:00
LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory
2020-11-06 17:10:09 -05:00
GITHUB_API_URL='https://api.github.com' # GitHub API root url
VERSION_FILE='/action/lib/linter-versions.txt' # File to store linter versions
###############
# Rules files #
###############
# shellcheck disable=SC2034 # Variable is referenced indirectly
ANSIBLE_FILE_NAME=".ansible-lint.yml"
# shellcheck disable=SC2034 # Variable is referenced indirectly
ARM_FILE_NAME=".arm-ttk.psd1"
# shellcheck disable=SC2034 # Variable is referenced indirectly
CLOJURE_FILE_NAME=".clj-kondo/config.edn"
# shellcheck disable=SC2034 # Variable is referenced indirectly
CLOUDFORMATION_FILE_NAME=".cfnlintrc.yml"
# shellcheck disable=SC2034 # Variable is referenced indirectly
COFFEESCRIPT_FILE_NAME=".coffee-lint.json"
CSS_FILE_NAME="${CSS_FILE_NAME:-.stylelintrc.json}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
DART_FILE_NAME="analysis_options.yml"
# shellcheck disable=SC2034 # Variable is referenced indirectly
DOCKERFILE_FILE_NAME=".dockerfilelintrc"
DOCKERFILE_HADOLINT_FILE_NAME="${DOCKERFILE_HADOLINT_FILE_NAME:-.hadolint.yaml}"
EDITORCONFIG_FILE_NAME="${EDITORCONFIG_FILE_NAME:-.ecrc}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
GO_FILE_NAME=".golangci.yml"
# shellcheck disable=SC2034 # Variable is referenced indirectly
GROOVY_FILE_NAME=".groovylintrc.json"
# shellcheck disable=SC2034 # Variable is referenced indirectly
HTML_FILE_NAME=".htmlhintrc"
# shellcheck disable=SC2034 # Variable is referenced indirectly
JAVA_FILE_NAME="sun_checks.xml"
# shellcheck disable=SC2034 # Variable is referenced indirectly
JAVASCRIPT_ES_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
JAVASCRIPT_STANDARD_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
JSX_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
LATEX_FILE_NAME=".chktexrc"
# shellcheck disable=SC2034 # Variable is referenced indirectly
LUA_FILE_NAME=".luacheckrc"
# shellcheck disable=SC2034 # Variable is referenced indirectly
MARKDOWN_FILE_NAME="${MARKDOWN_CONFIG_FILE:-.markdown-lint.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
OPENAPI_FILE_NAME=".openapirc.yml"
# shellcheck disable=SC2034 # Variable is referenced indirectly
PHP_PHPCS_FILE_NAME="phpcs.xml"
# shellcheck disable=SC2034 # Variable is referenced indirectly
PHP_PHPSTAN_FILE_NAME="phpstan.neon"
# shellcheck disable=SC2034 # Variable is referenced indirectly
PHP_PSALM_FILE_NAME="psalm.xml"
# shellcheck disable=SC2034 # Variable is referenced indirectly
POWERSHELL_FILE_NAME=".powershell-psscriptanalyzer.psd1"
# shellcheck disable=SC2034 # Variable is referenced indirectly
PROTOBUF_FILE_NAME=".protolintrc.yml"
# shellcheck disable=SC2034 # Variable is referenced indirectly
PYTHON_BLACK_FILE_NAME="${PYTHON_BLACK_CONFIG_FILE:-.python-black}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
PYTHON_FLAKE8_FILE_NAME="${PYTHON_FLAKE8_CONFIG_FILE:-.flake8}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
2020-10-28 11:22:55 -04:00
PYTHON_ISORT_FILE_NAME="${PYTHON_ISORT_CONFIG_FILE:-.isort.cfg}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
PYTHON_PYLINT_FILE_NAME="${PYTHON_PYLINT_CONFIG_FILE:-.python-lint}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
R_FILE_NAME=".lintr"
# shellcheck disable=SC2034 # Variable is referenced indirectly
RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
SNAKEMAKE_SNAKEFMT_FILE_NAME="${SNAKEMAKE_SNAKEFMT_CONFIG_FILE:-.snakefmt.toml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
SQL_FILE_NAME=".sql-config.json"
# shellcheck disable=SC2034 # Variable is referenced indirectly
TERRAFORM_FILE_NAME=".tflint.hcl"
# shellcheck disable=SC2034 # Variable is referenced indirectly
TSX_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
TYPESCRIPT_ES_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
TYPESCRIPT_STANDARD_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
YAML_FILE_NAME="${YAML_CONFIG_FILE:-.yaml-lint.yml}"
2020-10-08 18:54:28 -04:00
##################
# Language array #
##################
2020-08-28 12:54:31 -04:00
LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSHARP' 'CSS'
2020-08-06 11:25:45 -04:00
'DART' 'DOCKERFILE' 'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV' 'GO' 'GROOVY' 'HTML'
2020-09-21 18:53:30 -04:00
'JAVA' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KUBERNETES_KUBEVAL' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN'
2020-08-06 11:25:45 -04:00
'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL'
2020-10-28 11:22:55 -04:00
'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'PYTHON_ISORT' 'R' 'RAKU' 'RUBY' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES' 'SQL'
2020-10-13 11:21:23 -04:00
'TEKTON' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML')
2020-07-21 09:12:28 -04:00
2020-10-08 18:54:28 -04:00
##############################
# Linter command names array #
##############################
declare -A LINTER_NAMES_ARRAY
LINTER_NAMES_ARRAY['ANSIBLE']="ansible-lint"
2020-10-08 18:54:28 -04:00
LINTER_NAMES_ARRAY['ARM']="arm-ttk"
LINTER_NAMES_ARRAY['BASH']="shellcheck"
LINTER_NAMES_ARRAY['BASH_EXEC']="bash-exec"
LINTER_NAMES_ARRAY['CLOJURE']="clj-kondo"
LINTER_NAMES_ARRAY['CLOUDFORMATION']="cfn-lint"
LINTER_NAMES_ARRAY['COFFEESCRIPT']="coffeelint"
LINTER_NAMES_ARRAY['CSHARP']="dotnet-format"
LINTER_NAMES_ARRAY['CSS']="stylelint"
LINTER_NAMES_ARRAY['DART']="dart"
LINTER_NAMES_ARRAY['DOCKERFILE']="dockerfilelint"
LINTER_NAMES_ARRAY['DOCKERFILE_HADOLINT']="hadolint"
LINTER_NAMES_ARRAY['EDITORCONFIG']="editorconfig-checker"
LINTER_NAMES_ARRAY['ENV']="dotenv-linter"
LINTER_NAMES_ARRAY['GO']="golangci-lint"
LINTER_NAMES_ARRAY['GROOVY']="npm-groovy-lint"
LINTER_NAMES_ARRAY['HTML']="htmlhint"
LINTER_NAMES_ARRAY['JAVA']="checkstyle"
LINTER_NAMES_ARRAY['JAVASCRIPT_ES']="eslint"
LINTER_NAMES_ARRAY['JAVASCRIPT_STANDARD']="standard"
LINTER_NAMES_ARRAY['JSON']="jsonlint"
LINTER_NAMES_ARRAY['JSX']="eslint"
LINTER_NAMES_ARRAY['KOTLIN']="ktlint"
LINTER_NAMES_ARRAY['KUBERNETES_KUBEVAL']="kubeval"
LINTER_NAMES_ARRAY['LATEX']="chktex"
LINTER_NAMES_ARRAY['LUA']="lua"
LINTER_NAMES_ARRAY['MARKDOWN']="markdownlint"
LINTER_NAMES_ARRAY['OPENAPI']="spectral"
LINTER_NAMES_ARRAY['PERL']="perl"
LINTER_NAMES_ARRAY['PHP_BUILTIN']="php"
LINTER_NAMES_ARRAY['PHP_PHPCS']="phpcs"
LINTER_NAMES_ARRAY['PHP_PHPSTAN']="phpstan"
LINTER_NAMES_ARRAY['PHP_PSALM']="psalm"
LINTER_NAMES_ARRAY['POWERSHELL']="pwsh"
LINTER_NAMES_ARRAY['PROTOBUF']="protolint"
LINTER_NAMES_ARRAY['PYTHON_BLACK']="black"
LINTER_NAMES_ARRAY['PYTHON_PYLINT']="pylint"
LINTER_NAMES_ARRAY['PYTHON_FLAKE8']="flake8"
2020-10-28 11:22:55 -04:00
LINTER_NAMES_ARRAY['PYTHON_ISORT']="isort"
LINTER_NAMES_ARRAY['R']="R"
2020-10-08 18:54:28 -04:00
LINTER_NAMES_ARRAY['RAKU']="raku"
LINTER_NAMES_ARRAY['RUBY']="rubocop"
LINTER_NAMES_ARRAY['SHELL_SHFMT']="shfmt"
LINTER_NAMES_ARRAY['SNAKEMAKE_LINT']="snakemake"
LINTER_NAMES_ARRAY['SNAKEMAKE_SNAKEFMT']="snakefmt"
LINTER_NAMES_ARRAY['STATES']="asl-validator"
LINTER_NAMES_ARRAY['SQL']="sql-lint"
2020-10-13 11:21:23 -04:00
LINTER_NAMES_ARRAY['TEKTON']="tekton-lint"
2020-10-08 18:54:28 -04:00
LINTER_NAMES_ARRAY['TERRAFORM']="tflint"
LINTER_NAMES_ARRAY['TERRAFORM_TERRASCAN']="terrascan"
LINTER_NAMES_ARRAY['TERRAGRUNT']="terragrunt"
LINTER_NAMES_ARRAY['TSX']="eslint"
LINTER_NAMES_ARRAY['TYPESCRIPT_ES']="eslint"
LINTER_NAMES_ARRAY['TYPESCRIPT_STANDARD']="standard"
LINTER_NAMES_ARRAY['XML']="xmllint"
LINTER_NAMES_ARRAY['YAML']="yamllint"
2020-07-21 09:12:28 -04:00
############################################
# Array for all languages that were linted #
############################################
LINTED_LANGUAGES_ARRAY=() # Will be filled at run time with all languages that were linted
2020-04-27 15:13:12 -04:00
2019-10-21 15:12:37 -04:00
###################
# GitHub ENV Vars #
###################
2020-11-06 17:10:09 -05:00
ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory
DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default)
DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors
FILTER_REGEX_INCLUDE="${FILTER_REGEX_INCLUDE}" # RegExp defining which files will be processed by linters (all by default)
FILTER_REGEX_EXCLUDE="${FILTER_REGEX_EXCLUDE}" # RegExp defining which files will be excluded from linting (none by default)
GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path
GITHUB_REPOSITORY="${GITHUB_REPOSITORY}" # GitHub Org/Repo passed from system
GITHUB_RUN_ID="${GITHUB_RUN_ID}" # GitHub RUn ID to point to logs
GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit
GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub Token passed from environment
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace
MULTI_STATUS="${MULTI_STATUS:-true}" # Multiple status are created for each check ran
TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases
VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files
2020-07-30 15:15:42 -04:00
2019-10-25 12:29:31 -04:00
################
# Default Vars #
################
2020-07-01 17:40:40 -04:00
DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files
DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-/tmp/lint}" # Default workspace if running locally
DEFAULT_RUN_LOCAL='false' # Default value for debugging locally
DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases
2020-06-29 11:34:23 -04:00
###############################################################
# Default Vars that are called in Subs and need to be ignored #
###############################################################
2020-11-06 17:10:09 -05:00
DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors
export DEFAULT_DISABLE_ERRORS # Workaround SC2034
ERROR_ON_MISSING_EXEC_BIT="${ERROR_ON_MISSING_EXEC_BIT:-false}" # Default to report a warning if a shell script doesn't have the executable bit set to 1
export ERROR_ON_MISSING_EXEC_BIT
2020-11-06 17:10:09 -05:00
RAW_FILE_ARRAY=() # Array of all files that were changed
export RAW_FILE_ARRAY # Workaround SC2034
TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore
export TEST_CASE_FOLDER # Workaround SC2034
WARNING_ARRAY_TEST=() # Array of warning linters that did not have an expected test result.
export WARNING_ARRAY_TEST # Workaround SC2034
2019-10-21 12:05:55 -04:00
2020-06-23 10:25:12 -04:00
##############
# Format #
##############
2020-11-06 17:10:09 -05:00
OUTPUT_FORMAT="${OUTPUT_FORMAT}" # Output format to be generated. Default none
OUTPUT_FOLDER="${OUTPUT_FOLDER:-super-linter.report}" # Folder where the reports are generated. Default super-linter.report
OUTPUT_DETAILS="${OUTPUT_DETAILS:-simpler}" # What level of details. (simpler or detailed). Default simpler
2020-06-23 10:25:12 -04:00
2019-10-25 15:22:57 -04:00
##########################
# Array of changed files #
##########################
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
FILE_ARRAY_VARIABLE_NAME="FILE_ARRAY_${LANGUAGE}"
debug "Setting ${FILE_ARRAY_VARIABLE_NAME} variable..."
eval "${FILE_ARRAY_VARIABLE_NAME}=()"
done
2019-10-25 15:22:57 -04:00
#####################################
# Validate we have linter installed #
#####################################
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
LINTER_NAME="${LINTER_NAMES_ARRAY["${LANGUAGE}"]}"
debug "Checking if linter with name ${LINTER_NAME} for the ${LANGUAGE} language is available..."
2020-11-06 17:10:09 -05:00
if ! command -v "${LINTER_NAME}" 1 &>/dev/null 2>&1; then
# Failed
fatal "Failed to find [${LINTER_NAME}] in system!"
else
# Success
debug "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]}."
fi
done
2019-10-21 10:12:50 -04:00
################################################################################
2019-10-21 12:05:55 -04:00
########################## FUNCTIONS BELOW #####################################
2019-10-21 10:12:50 -04:00
################################################################################
################################################################################
2019-10-21 12:05:55 -04:00
#### Function Header ###########################################################
2020-07-01 17:40:40 -04:00
Header() {
2020-05-06 11:03:06 -04:00
###############################
# Give them the possum action #
###############################
2020-05-06 11:27:45 -04:00
/bin/bash /action/lib/possum.sh
2020-05-06 11:03:06 -04:00
##########
# Prints #
##########
2020-07-30 16:39:05 -04:00
info "---------------------------------------------"
info "--- GitHub Actions Multi Language Linter ----"
2020-09-04 11:14:47 -04:00
info " - Image Creation Date:[${BUILD_DATE}]"
info " - Image Revision:[${BUILD_REVISION}]"
info " - Image Version:[${BUILD_VERSION}]"
2020-07-30 16:39:05 -04:00
info "---------------------------------------------"
info "---------------------------------------------"
info "The Super-Linter source code can be found at:"
info " - https://github.com/github/super-linter"
info "---------------------------------------------"
2019-10-21 12:05:55 -04:00
}
################################################################################
2020-01-08 14:34:05 -05:00
#### Function GetLinterVersions ################################################
2020-07-01 17:40:40 -04:00
GetLinterVersions() {
2020-01-08 14:34:05 -05:00
#########################
# Print version headers #
#########################
2020-07-30 16:39:05 -04:00
debug "---------------------------------------------"
debug "Linter Version Info:"
2020-01-08 14:34:05 -05:00
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
2020-09-03 10:12:49 -04:00
################################
# Cat the linter versions file #
################################
2020-09-03 11:12:29 -04:00
CAT_CMD=$(cat "${VERSION_FILE}" 2>&1)
2020-01-08 14:34:05 -05:00
2020-09-03 10:12:49 -04:00
#######################
# Load the error code #
#######################
ERROR_CODE=$?
2020-01-08 14:34:05 -05:00
2020-09-03 10:12:49 -04:00
##############################
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Failure
fatal "Failed to view version file:[${VERSION_FILE}]"
2020-09-03 10:12:49 -04:00
else
# Success
2020-09-03 11:12:29 -04:00
debug "${CAT_CMD}"
2020-09-03 10:12:49 -04:00
fi
2020-07-06 09:18:09 -04:00
2020-07-02 17:31:16 -04:00
#########################
# Print version footers #
#########################
2020-07-30 16:39:05 -04:00
debug "---------------------------------------------"
2020-01-08 14:34:05 -05:00
}
################################################################################
2019-10-21 12:05:55 -04:00
#### Function GetLinterRules ###################################################
2020-07-01 17:40:40 -04:00
GetLinterRules() {
2019-10-21 12:05:55 -04:00
# Need to validate the rules files exist
2020-02-03 11:27:40 -05:00
################
# Pull in vars #
################
2020-07-21 13:09:07 -04:00
LANGUAGE_NAME="${1}" # Name of the language were looking for
2020-09-08 13:20:49 -04:00
debug "Getting linter rules for ${LANGUAGE_NAME}..."
2020-07-01 10:45:55 -04:00
DEFAULT_RULES_LOCATION="${2}"
debug "Default rules location: ${DEFAULT_RULES_LOCATION}..."
2020-07-01 10:45:55 -04:00
#######################################################
# Need to create the variables for the real variables #
#######################################################
LANGUAGE_FILE_NAME="${LANGUAGE_NAME}_FILE_NAME"
LANGUAGE_LINTER_RULES="${LANGUAGE_NAME}_LINTER_RULES"
2020-09-08 13:20:49 -04:00
debug "Variable names for language file name: ${LANGUAGE_FILE_NAME}, language linter rules: ${LANGUAGE_LINTER_RULES}"
2020-02-03 11:27:40 -05:00
2020-10-03 17:01:07 -04:00
#####################################################
# 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}="
2020-08-06 11:30:10 -04:00
##########################
# Get the file extension #
##########################
FILE_EXTENSION=$(echo "${!LANGUAGE_FILE_NAME}" | rev | cut -d'.' -f1 | rev)
2020-09-08 13:20:49 -04:00
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"
2020-08-06 11:30:10 -04:00
########################################
# Set the secondary file name and path #
########################################
debug "Initializing SECONDARY_FILE_NAME and SECONDARY_LANGUAGE_FILE_PATH..."
2020-08-06 11:30:10 -04:00
SECONDARY_FILE_NAME=''
SECONDARY_LANGUAGE_FILE_PATH=
2020-08-06 11:30:10 -04:00
#################################
# 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
2020-11-03 11:06:33 -05:00
###############################
# Set Flag for set Rules File #
###############################
SET_RULES=0
2020-02-03 11:27:40 -05:00
#####################################
# Validate we have the linter rules #
#####################################
LANGUAGE_FILE_PATH="${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}"
2020-11-03 11:06:33 -05:00
debug "Checking if the user-provided:[${!LANGUAGE_FILE_NAME}] and exists at:[${LANGUAGE_FILE_PATH}]"
if [ -f "${LANGUAGE_FILE_PATH}" ]; then
2020-07-30 16:39:05 -04:00
info "----------------------------------------------"
info "User provided file:[${LANGUAGE_FILE_PATH}] exists, setting rules file..."
2019-10-22 13:21:42 -04:00
2020-07-01 10:45:55 -04:00
########################################
# Update the path to the file location #
########################################
eval "${LANGUAGE_LINTER_RULES}=${LANGUAGE_FILE_PATH}"
2020-11-03 11:06:33 -05:00
######################
# Set the rules flag #
######################
SET_RULES=1
else
# Failed to find the primary rules file
debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}]."
2020-11-03 11:06:33 -05:00
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}"
2020-11-03 11:06:33 -05:00
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}"
2020-11-03 11:06:33 -05:00
######################
# Set the rules flag #
######################
SET_RULES=1
fi
2020-11-03 11:06:33 -05:00
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}]"
2020-11-03 11:06:33 -05:00
######################
# Set the rules flag #
######################
SET_RULES=1
fi
2020-11-03 11:06:33 -05:00
####################
# Debug Print info #
####################
debug " -> Language rules file variable (${LANGUAGE_LINTER_RULES}) value is:[${!LANGUAGE_LINTER_RULES}]"
2020-11-03 11:06:33 -05:00
############################
# Validate the file exists #
############################
if [ -e "${!LANGUAGE_LINTER_RULES}" ]; then
2020-11-03 11:06:33 -05:00
# 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.
2020-10-19 15:16:33 -04:00
fatal " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) doesn't exist. Terminating..."
2019-10-22 13:21:42 -04:00
fi
2020-10-15 09:45:40 -04:00
2020-11-03 11:06:33 -05:00
######################
# Export the results #
######################
2020-10-15 09:45:40 -04:00
eval "export ${LANGUAGE_LINTER_RULES}"
2020-02-03 11:27:40 -05:00
}
################################################################################
#### Function GetStandardRules #################################################
2020-07-01 17:40:40 -04:00
GetStandardRules() {
2020-04-02 13:42:07 -04:00
################
# Pull In Vars #
################
2020-07-21 13:09:07 -04:00
LINTER="${1}" # Type: javascript | typescript
2020-04-02 13:42:07 -04:00
2020-02-03 11:27:40 -05:00
#########################################################################
# Need to get the ENV vars from the linter rules to run in command line #
#########################################################################
# Copy orig IFS to var
2020-07-21 13:09:07 -04:00
ORIG_IFS="${IFS}"
2020-02-03 11:27:40 -05:00
# Set the IFS to newline
IFS=$'\n'
2019-11-06 16:45:44 -05:00
2020-02-03 11:27:40 -05:00
#########################################
# Get list of all environment variables #
#########################################
# Only env vars that are marked as true
2020-04-02 13:42:07 -04:00
GET_ENV_ARRAY=()
2020-07-21 13:09:07 -04:00
if [[ ${LINTER} == "javascript" ]]; then
mapfile -t GET_ENV_ARRAY < <(yq .env "${JAVASCRIPT_STANDARD_LINTER_RULES}" | grep true)
2020-07-21 13:09:07 -04:00
elif [[ ${LINTER} == "typescript" ]]; then
mapfile -t GET_ENV_ARRAY < <(yq .env "${TYPESCRIPT_STANDARD_LINTER_RULES}" | grep true)
2020-04-02 13:42:07 -04:00
fi
2019-11-06 16:45:44 -05:00
2020-02-03 11:27:40 -05:00
#######################
# Load the error code #
#######################
ERROR_CODE=$?
2019-11-06 16:45:44 -05:00
2020-02-03 11:27:40 -05:00
##############################
# Check the shell for errors #
##############################
2020-07-21 13:09:07 -04:00
if [ ${ERROR_CODE} -ne 0 ]; then
2020-02-03 11:27:40 -05:00
# ERROR
2020-07-30 16:39:05 -04:00
error "Failed to gain list of ENV vars to load!"
fatal "[${GET_ENV_ARRAY[*]}]"
2019-11-06 16:45:44 -05:00
fi
2020-01-10 14:33:28 -05:00
2020-02-03 11:27:40 -05:00
##########################
# Set IFS back to normal #
##########################
# Set IFS back to Orig
2020-07-21 13:09:07 -04:00
IFS="${ORIG_IFS}"
2020-01-10 14:33:28 -05:00
2020-02-03 11:27:40 -05:00
######################
# Set the env string #
######################
ENV_STRING=''
2020-01-10 14:33:28 -05:00
2020-02-03 11:27:40 -05:00
#############################
# Pull out the envs to load #
#############################
2020-07-01 17:40:40 -04:00
for ENV in "${GET_ENV_ARRAY[@]}"; do
2020-02-03 11:27:40 -05:00
#############################
# remove spaces from return #
#############################
ENV="$(echo -e "${ENV}" | tr -d '[:space:]')"
################################
# Get the env to add to string #
################################
ENV="$(echo "${ENV}" | cut -d'"' -f2)"
2020-07-30 16:39:05 -04:00
debug "ENV:[${ENV}]"
2020-02-03 11:27:40 -05:00
ENV_STRING+="--env ${ENV} "
done
2020-01-10 14:33:28 -05:00
2020-06-21 00:03:30 -04:00
#########################################
# Remove trailing and ending whitespace #
#########################################
2020-07-21 13:09:07 -04:00
if [[ ${LINTER} == "javascript" ]]; then
2020-04-02 13:42:07 -04:00
JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
2020-07-21 13:09:07 -04:00
elif [[ ${LINTER} == "typescript" ]]; then
2020-04-02 13:42:07 -04:00
TYPESCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
2019-10-21 12:05:55 -04:00
}
2020-06-25 02:13:19 -04:00
################################################################################
#### Function DetectOpenAPIFile ################################################
2020-07-01 17:40:40 -04:00
DetectOpenAPIFile() {
2020-06-26 09:26:36 -04:00
################
# Pull in vars #
################
2020-07-21 13:09:07 -04:00
FILE="${1}"
debug "Checking if ${FILE} is an OpenAPI file..."
2020-06-26 09:26:36 -04:00
###############################
# Check the file for keywords #
###############################
grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "${FILE}" >/dev/null
2020-06-26 09:26:36 -04:00
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
2020-07-21 13:09:07 -04:00
if [ ${ERROR_CODE} -eq 0 ]; then
2020-06-26 09:26:36 -04:00
########################
# Found string in file #
########################
2020-07-01 17:40:40 -04:00
return 0
2020-06-25 02:13:19 -04:00
else
2020-06-26 09:26:36 -04:00
###################
# No string match #
###################
2020-07-01 17:40:40 -04:00
return 1
2020-06-25 02:13:19 -04:00
fi
}
2020-06-29 15:38:24 -04:00
################################################################################
2020-10-13 11:21:23 -04:00
#### Function DetectTektonFile #################################################
DetectTektonFile() {
################
# Pull in vars #
################
FILE="${1}"
debug "Checking if ${FILE} is a Tekton file..."
2020-10-13 11:21:23 -04:00
###############################
# 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
}
################################################################################
2020-07-06 09:18:09 -04:00
#### Function DetectARMFile ####################################################
2020-07-06 09:29:36 -04:00
DetectARMFile() {
2020-07-02 17:31:16 -04:00
################
# Pull in vars #
################
2020-07-21 13:09:07 -04:00
FILE="${1}" # Name of the file/path we are validating
debug "Checking if ${FILE} is an ARM file..."
2020-07-02 17:31:16 -04:00
###############################
# Check the file for keywords #
###############################
grep -E 'schema.management.azure.com' "${FILE}" >/dev/null
2020-07-02 17:31:16 -04:00
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
2020-07-21 13:09:07 -04:00
if [ ${ERROR_CODE} -eq 0 ]; then
2020-07-02 17:31:16 -04:00
########################
# Found string in file #
########################
2020-07-06 09:18:09 -04:00
return 0
2020-07-02 17:31:16 -04:00
else
###################
# No string match #
###################
2020-07-06 09:18:09 -04:00
return 1
2020-07-02 17:31:16 -04:00
fi
}
################################################################################
#### Function DetectCloudFormationFile #########################################
2020-07-01 17:40:40 -04:00
DetectCloudFormationFile() {
2020-06-29 15:49:20 -04:00
################
# Pull in Vars #
################
2020-07-21 13:09:07 -04:00
FILE="${1}" # File that we need to validate
debug "Checking if ${FILE} is a Cloud Formation file..."
2020-06-29 15:49:20 -04:00
2020-06-29 15:38:24 -04:00
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-formats.html
2020-06-26 15:43:44 -04:00
# AWSTemplateFormatVersion is optional
2020-06-29 15:49:20 -04:00
#######################################
# Check if file has AWS Template info #
#######################################
if grep -q 'AWSTemplateFormatVersion' "${FILE}" >/dev/null; then
2020-06-29 15:49:20 -04:00
# Found it
return 0
fi
2020-06-29 15:49:20 -04:00
2020-07-23 11:18:54 -04:00
#####################################
# See if it contains AWS References #
#####################################
if grep -q -E '(AWS|Alexa|Custom)::' "${FILE}" >/dev/null; then
2020-06-29 15:49:20 -04:00
# Found it
2020-06-26 15:43:44 -04:00
return 0
fi
2020-07-22 15:07:08 -04:00
#####################################################
# No identifiers of a CLOUDFORMATION template found #
#####################################################
2020-06-26 15:43:44 -04:00
return 1
}
2020-07-21 14:50:04 -04:00
################################################################################
2020-09-21 18:53:30 -04:00
#### Function DetectKubernetesFile #########################################
DetectKubernetesFile() {
################
# Pull in Vars #
################
FILE="${1}" # File that we need to validate
debug "Checking if ${FILE} is a Kubernetes descriptor..."
2020-10-13 14:46:46 -04:00
if grep -v 'kustomize.config.k8s.io' "${FILE}" | grep -v tekton | grep -q -E '(apiVersion):'; then
2020-09-21 18:53:30 -04:00
debug "${FILE} is a Kubernetes descriptor"
return 0
fi
debug "${FILE} is NOT a Kubernetes descriptor"
return 1
}
################################################################################
2020-07-21 14:50:04 -04:00
#### Function DetectAWSStatesFIle ##############################################
DetectAWSStatesFIle() {
################
# Pull in Vars #
################
2020-07-21 15:39:14 -04:00
FILE="${1}" # File that we need to validate
debug "Checking if ${FILE} is a AWS states descriptor..."
2020-07-21 14:50:04 -04:00
# https://states-language.net/spec.html#example
2020-06-29 15:49:20 -04:00
###############################
# check if file has resources #
###############################
if grep -q '"Resource": *"arn"*' "${FILE}"; then
2020-06-29 15:49:20 -04:00
# Found it
2020-06-26 15:43:44 -04:00
return 0
fi
2020-07-21 14:50:04 -04:00
#################################################
# No identifiers of a AWS States Language found #
#################################################
2020-06-26 15:43:44 -04:00
return 1
}
2020-01-09 17:08:01 -05:00
################################################################################
2019-10-21 15:12:37 -04:00
#### Function GetGitHubVars ####################################################
2020-07-01 17:40:40 -04:00
GetGitHubVars() {
2019-10-21 15:12:37 -04:00
##########
# Prints #
##########
2020-07-30 16:39:05 -04:00
info "--------------------------------------------"
info "Gathering GitHub information..."
2019-10-21 15:12:37 -04:00
2020-02-04 12:49:07 -05:00
###############################
# Get the Run test cases flag #
###############################
2020-07-21 13:09:07 -04:00
if [ -z "${TEST_CASE_RUN}" ]; then
2020-02-04 12:49:07 -05:00
##################################
# No flag passed, set to default #
##################################
2020-07-21 13:09:07 -04:00
TEST_CASE_RUN="${DEFAULT_TEST_CASE_RUN}"
2020-02-04 12:49:07 -05:00
fi
###############################
# Convert string to lowercase #
###############################
2020-07-21 12:09:05 -04:00
TEST_CASE_RUN="${TEST_CASE_RUN,,}"
2020-02-04 12:49:07 -05:00
2020-01-09 11:29:18 -05:00
##########################
# Get the run local flag #
##########################
2020-07-21 13:09:07 -04:00
if [ -z "${RUN_LOCAL}" ]; then
2020-01-09 11:29:18 -05:00
##################################
# No flag passed, set to default #
##################################
2020-07-21 13:09:07 -04:00
RUN_LOCAL="${DEFAULT_RUN_LOCAL}"
2019-10-21 15:12:37 -04:00
fi
2020-01-09 11:29:18 -05:00
###############################
# Convert string to lowercase #
###############################
2020-07-21 12:09:05 -04:00
RUN_LOCAL="${RUN_LOCAL,,}"
2020-02-04 12:49:07 -05:00
2020-01-09 11:29:18 -05:00
#################################
# Check if were running locally #
#################################
2020-07-21 13:09:07 -04:00
if [[ ${RUN_LOCAL} != "false" ]]; then
2020-01-09 11:29:18 -05:00
##########################################
# We are running locally for a debug run #
##########################################
2020-07-30 16:39:05 -04:00
info "NOTE: ENV VAR [RUN_LOCAL] has been set to:[true]"
info "bypassing GitHub Actions variables..."
############################
# Set the GITHUB_WORKSPACE #
############################
2020-07-21 13:09:07 -04:00
if [ -z "${GITHUB_WORKSPACE}" ]; then
GITHUB_WORKSPACE="${DEFAULT_WORKSPACE}"
fi
2020-06-29 10:55:59 -04:00
2020-07-21 13:09:07 -04:00
if [ ! -d "${GITHUB_WORKSPACE}" ]; then
2020-07-30 16:39:05 -04:00
fatal "Provided volume is not a directory!"
fi
2020-08-18 10:51:38 -04:00
################################
# Set the report output folder #
################################
REPORT_OUTPUT_FOLDER="${DEFAULT_WORKSPACE}/${OUTPUT_FOLDER}"
2020-07-30 16:39:05 -04:00
info "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]"
2020-01-09 11:29:18 -05:00
# No need to touch or set the GITHUB_SHA
# No need to touch or set the GITHUB_EVENT_PATH
# No need to touch or set the GITHUB_ORG
# No need to touch or set the GITHUB_REPO
#################################
# Set the VALIDATE_ALL_CODEBASE #
#################################
2020-07-21 13:09:07 -04:00
VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}"
2019-10-21 15:12:37 -04:00
else
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
2020-07-21 13:09:07 -04:00
if [ -z "${GITHUB_SHA}" ]; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_SHA]!"
fatal "[${GITHUB_SHA}]"
2020-01-09 11:29:18 -05:00
else
2020-07-30 16:39:05 -04:00
info "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]"
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
2020-07-21 13:09:07 -04:00
if [ -z "${GITHUB_WORKSPACE}" ]; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_WORKSPACE]!"
fatal "[${GITHUB_WORKSPACE}]"
2020-01-09 11:29:18 -05:00
else
2020-07-30 16:39:05 -04:00
info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]"
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
2020-07-21 13:09:07 -04:00
if [ -z "${GITHUB_EVENT_PATH}" ]; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_EVENT_PATH]!"
fatal "[${GITHUB_EVENT_PATH}]"
2020-01-09 11:29:18 -05:00
else
2020-07-30 16:39:05 -04:00
info "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}"
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
2020-01-09 11:29:18 -05:00
##################################################
# Need to pull the GitHub Vars from the env file #
##################################################
######################
# Get the GitHub Org #
######################
GITHUB_ORG=$(jq -r '.repository.owner.login' <"${GITHUB_EVENT_PATH}")
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
2020-07-21 13:09:07 -04:00
if [ -z "${GITHUB_ORG}" ]; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_ORG]!"
fatal "[${GITHUB_ORG}]"
2020-01-09 11:29:18 -05:00
else
2020-07-30 16:39:05 -04:00
info "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]"
2020-01-09 11:29:18 -05:00
fi
#######################
# Get the GitHub Repo #
#######################
GITHUB_REPO=$(jq -r '.repository.name' <"${GITHUB_EVENT_PATH}")
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
2020-07-21 13:09:07 -04:00
if [ -z "${GITHUB_REPO}" ]; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_REPO]!"
fatal "[${GITHUB_REPO}]"
2020-01-09 11:29:18 -05:00
else
2020-07-30 16:39:05 -04:00
info "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]"
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
fi
2020-07-20 15:07:56 -04:00
############################
# Validate we have a value #
############################
2020-07-22 12:59:46 -04:00
if [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_TOKEN]!"
error "[${GITHUB_TOKEN}]"
error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!"
2020-07-21 11:21:08 -04:00
################################################################################
# Need to set MULTI_STATUS to false as we cant hit API endpoints without token #
################################################################################
MULTI_STATUS='false'
2020-07-20 15:07:56 -04:00
else
2020-07-30 16:39:05 -04:00
info "Successfully found:${F[W]}[GITHUB_TOKEN]"
2020-07-20 15:07:56 -04:00
fi
###############################
# Convert string to lowercase #
###############################
2020-07-21 12:09:05 -04:00
MULTI_STATUS="${MULTI_STATUS,,}"
2020-07-20 15:07:56 -04:00
#######################################################################
# Check to see if the multi status is set, and we have a token to use #
#######################################################################
2020-07-21 13:09:07 -04:00
if [ "${MULTI_STATUS}" == "true" ] && [ -n "${GITHUB_TOKEN}" ]; then
2020-07-20 15:07:56 -04:00
############################
# Validate we have a value #
############################
2020-07-21 13:09:07 -04:00
if [ -z "${GITHUB_REPOSITORY}" ]; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_REPOSITORY]!"
fatal "[${GITHUB_REPOSITORY}]"
2020-07-20 15:07:56 -04:00
else
2020-07-30 16:39:05 -04:00
info "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]"
2020-07-20 15:07:56 -04:00
fi
############################
# Validate we have a value #
############################
2020-07-21 13:09:07 -04:00
if [ -z "${GITHUB_RUN_ID}" ]; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_RUN_ID]!"
fatal "[${GITHUB_RUN_ID}]"
2020-01-09 11:29:18 -05:00
else
2020-07-30 16:39:05 -04:00
info "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]"
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
fi
2020-04-27 13:21:38 -04:00
}
################################################################################
2020-07-20 15:07:56 -04:00
#### Function CallStatusAPI ####################################################
CallStatusAPI() {
####################
# Pull in the vars #
####################
2020-07-30 16:39:05 -04:00
LANGUAGE="${1}" # langauge that was validated
STATUS="${2}" # success | error
2020-07-20 15:07:56 -04:00
SUCCESS_MSG='No errors were found in the linting process'
FAIL_MSG='Errors were detected, please view logs'
2020-07-30 16:39:05 -04:00
MESSAGE='' # Message to send to status API
2020-07-20 15:07:56 -04:00
######################################
# Check the status to create message #
######################################
2020-07-21 13:09:07 -04:00
if [ "${STATUS}" == "success" ]; then
2020-07-20 15:07:56 -04:00
# Success
2020-07-21 13:09:07 -04:00
MESSAGE="${SUCCESS_MSG}"
2020-07-20 15:07:56 -04:00
else
# Failure
2020-07-21 13:09:07 -04:00
MESSAGE="${FAIL_MSG}"
2020-07-20 15:07:56 -04:00
fi
##########################################################
# Check to see if were enabled for multi Status mesaages #
##########################################################
2020-08-19 15:18:49 -04:00
if [ "${MULTI_STATUS}" == "true" ] && [ -n "${GITHUB_TOKEN}" ] && [ -n "${GITHUB_REPOSITORY}" ]; then
2020-09-03 19:37:10 -04:00
# make sure we honor DISABLE_ERRORS
if [ "${DISABLE_ERRORS}" == "true" ]; then
STATUS="success"
fi
##############################################
# Call the status API to create status check #
##############################################
2020-09-09 14:22:32 -04:00
SEND_STATUS_CMD=$(
curl -f -s -X POST \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}" \
-H 'accept: application/vnd.github.v3+json' \
-H "authorization: Bearer ${GITHUB_TOKEN}" \
-H 'content-type: application/json' \
-d "{ \"state\": \"${STATUS}\",
2020-07-21 13:09:07 -04:00
\"target_url\": \"https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\",
\"description\": \"${MESSAGE}\", \"context\": \"--> Linted: ${LANGUAGE}\"
2020-09-09 14:22:32 -04:00
}" 2>&1
)
2020-07-20 15:07:56 -04:00
#######################
# Load the error code #
#######################
ERROR_CODE=$?
2020-07-20 15:07:56 -04:00
##############################
# Check the shell for errors #
##############################
2020-07-21 13:09:07 -04:00
if [ "${ERROR_CODE}" -ne 0 ]; then
# ERROR
2020-07-30 16:39:05 -04:00
info "ERROR! Failed to call GitHub Status API!"
info "ERROR:[${SEND_STATUS_CMD}]"
# Not going to fail the script on this yet...
fi
fi
}
################################################################################
2020-07-22 15:49:26 -04:00
#### Function Reports ##########################################################
Reports() {
2020-07-30 16:39:05 -04:00
info "----------------------------------------------"
info "----------------------------------------------"
info "Generated reports:"
info "----------------------------------------------"
info "----------------------------------------------"
2020-04-27 15:13:12 -04:00
2020-06-23 10:25:12 -04:00
###################################
# Prints output report if enabled #
###################################
2020-07-30 16:39:05 -04:00
if [ -z "${FORMAT_REPORT}" ]; then
info "Reports generated in folder ${REPORT_OUTPUT_FOLDER}"
2020-08-18 10:51:38 -04:00
#############################################
# Print info on reports that were generated #
#############################################
2020-08-31 18:06:15 -04:00
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
2020-06-23 10:25:12 -04:00
fi
2020-07-22 15:49:26 -04:00
################################
# Prints for warnings if found #
################################
for TEST in "${WARNING_ARRAY_TEST[@]}"; do
2020-07-30 16:39:05 -04:00
warn "Expected file to compare with was not found for ${TEST}"
2020-07-22 15:49:26 -04:00
done
}
################################################################################
#### Function Footer ###########################################################
Footer() {
2020-07-30 16:39:05 -04:00
info "----------------------------------------------"
info "----------------------------------------------"
info "The script has completed"
info "----------------------------------------------"
info "----------------------------------------------"
2020-07-22 15:49:26 -04:00
2020-07-21 09:23:32 -04:00
####################################################
# Need to clean up the lanuage array of duplicates #
####################################################
2020-08-27 15:12:24 -04:00
mapfile -t UNIQUE_LINTED_ARRAY < <(for LANG in "${LINTED_LANGUAGES_ARRAY[@]}"; do echo "${LANG}"; done | sort -u)
2020-07-21 09:23:32 -04:00
2020-04-27 15:13:12 -04:00
##############################
# Prints for errors if found #
##############################
2020-07-01 17:40:40 -04:00
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
2020-04-27 15:13:12 -04:00
###########################
# Build the error counter #
###########################
2020-07-21 13:09:07 -04:00
ERROR_COUNTER="ERRORS_FOUND_${LANGUAGE}"
2020-04-27 15:13:12 -04:00
##################
# Print if not 0 #
##################
2020-07-30 16:39:05 -04:00
if [[ ${!ERROR_COUNTER} -ne 0 ]]; then
2020-07-21 09:12:28 -04:00
# We found errors in the language
2020-07-20 15:07:56 -04:00
###################
# Print the goods #
###################
2020-07-30 16:39:05 -04:00
error "ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]"
2020-07-20 15:07:56 -04:00
#########################################
# Create status API for Failed language #
#########################################
2020-07-21 13:09:07 -04:00
CallStatusAPI "${LANGUAGE}" "error"
######################################
# Check if we validated the langauge #
######################################
elif [[ ${!ERROR_COUNTER} -eq 0 ]]; then
if CheckInArray "${LANGUAGE}"; then
# No errors found when linting the language
CallStatusAPI "${LANGUAGE}" "success"
fi
2020-04-27 15:13:12 -04:00
fi
done
2020-06-18 15:24:47 -04:00
##################################
# Exit with 0 if errors disabled #
##################################
2020-07-21 13:09:07 -04:00
if [ "${DISABLE_ERRORS}" == "true" ]; then
2020-07-30 16:39:05 -04:00
warn "Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]"
2020-06-18 15:24:47 -04:00
exit 0
2020-07-22 15:49:26 -04:00
fi
2019-10-21 12:05:55 -04:00
###############################
# Exit with 1 if errors found #
###############################
2020-07-22 15:49:26 -04:00
# Loop through all languages
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
# build the variable
ERRORS_FOUND_LANGUAGE="ERRORS_FOUND_${LANGUAGE}"
# Check if error was found
2020-07-30 16:39:05 -04:00
if [[ ${!ERRORS_FOUND_LANGUAGE} -ne 0 ]]; then
2020-07-22 15:49:26 -04:00
# Failed exit
2020-07-30 16:39:05 -04:00
fatal "Exiting with errors found!"
2020-07-22 15:49:26 -04:00
fi
done
########################
# Footer prints Exit 0 #
########################
2020-07-30 16:39:05 -04:00
notice "All file(s) linted successfully with no errors detected"
info "----------------------------------------------"
2020-07-22 15:49:26 -04:00
# Successful exit
exit 0
2019-10-21 10:12:50 -04:00
}
2020-08-24 15:12:37 -04:00
################################################################################
#### 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
2020-08-24 15:12:37 -04:00
###################
# Did not find it #
###################
return 1
}
2020-07-27 17:11:33 -04:00
################################################################################
#### Function Cleanup ##########################################################
cleanup() {
2020-07-30 16:39:05 -04:00
local -ri EXIT_CODE=$?
2020-07-27 17:11:33 -04:00
2020-07-30 16:39:05 -04:00
sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/${LOG_FILE}" || true
2020-07-27 17:11:33 -04:00
2020-07-30 16:39:05 -04:00
exit ${EXIT_CODE}
trap - 0 1 2 3 6 14 15
2019-10-21 10:12:50 -04:00
}
2020-07-27 17:11:33 -04:00
trap 'cleanup' 0 1 2 3 6 14 15
2019-10-21 10:12:50 -04:00
################################################################################
2019-10-21 12:05:55 -04:00
############################### MAIN ###########################################
2019-10-21 10:12:50 -04:00
################################################################################
2019-10-21 12:05:55 -04:00
##########
# Header #
##########
Header
2020-06-23 10:25:12 -04:00
##############################################################
# check flag for validating the report folder does not exist #
##############################################################
if [ -n "${OUTPUT_FORMAT}" ]; then
2020-07-30 16:39:05 -04:00
if [ -d "${REPORT_OUTPUT_FOLDER}" ]; then
error "ERROR! Found ${REPORT_OUTPUT_FOLDER}"
fatal "Please remove the folder and try again."
2020-06-23 10:25:12 -04:00
fi
fi
##################################
# Get and print all version info #
##################################
GetLinterVersions
2019-10-21 15:12:37 -04:00
#######################
# Get GitHub Env Vars #
2019-10-21 15:12:37 -04:00
#######################
# Need to pull in all the GitHub variables
2019-10-21 15:12:37 -04:00
# needed to connect back and update checks
GetGitHubVars
2020-09-21 18:53:30 -04:00
########################################################
# Initialize variables that depend on GitHub variables #
########################################################
2020-11-06 17:10:09 -05:00
DEFAULT_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/ansible" # Default Ansible Directory
export DEFAULT_ANSIBLE_DIRECTORY # Workaround SC2034
REPORT_OUTPUT_FOLDER="${GITHUB_WORKSPACE}/${OUTPUT_FOLDER}" # Location for the report folder
2020-09-21 18:53:30 -04:00
2020-10-08 18:54:28 -04:00
############################
# Validate the environment #
############################
2020-04-27 14:47:11 -04:00
GetValidationInfo
2020-04-27 13:21:38 -04:00
2019-10-21 12:05:55 -04:00
########################
# Get the linter rules #
########################
2020-10-03 17:01:07 -04:00
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
debug "Loading rules for ${LANGUAGE}..."
eval "GetLinterRules ${LANGUAGE} ${DEFAULT_RULES_LOCATION}"
2020-10-03 17:01:07 -04:00
done
2020-02-03 11:27:40 -05:00
2020-10-08 18:54:28 -04:00
# Load rules for a couple of special cases
GetStandardRules "javascript"
GetStandardRules "typescript"
##########################
# Define linter commands #
##########################
declare -A LINTER_COMMANDS_ARRAY
LINTER_COMMANDS_ARRAY['ARM']="Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath"
LINTER_COMMANDS_ARRAY['BASH']="shellcheck --color --external-sources"
LINTER_COMMANDS_ARRAY['BASH_EXEC']="bash-exec"
LINTER_COMMANDS_ARRAY['CLOJURE']="clj-kondo --config ${CLOJURE_LINTER_RULES} --lint"
LINTER_COMMANDS_ARRAY['CLOUDFORMATION']="cfn-lint --config-file ${CLOUDFORMATION_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['COFFEESCRIPT']="coffeelint -f ${COFFEESCRIPT_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['CSHARP']="dotnet-format --folder --check --exclude / --include"
LINTER_COMMANDS_ARRAY['CSS']="stylelint --config ${CSS_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['DART']="dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}"
# NOTE: dockerfilelint's "-c" option expects the folder *containing* the DOCKER_LINTER_RULES file
LINTER_COMMANDS_ARRAY['DOCKERFILE']="dockerfilelint -c $(dirname "${DOCKERFILE_LINTER_RULES}")"
2020-10-08 18:54:28 -04:00
LINTER_COMMANDS_ARRAY['DOCKERFILE_HADOLINT']="hadolint -c ${DOCKERFILE_HADOLINT_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['EDITORCONFIG']="editorconfig-checker -config ${EDITORCONFIG_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['ENV']="dotenv-linter"
LINTER_COMMANDS_ARRAY['GO']="golangci-lint run -c ${GO_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['GROOVY']="npm-groovy-lint -c ${GROOVY_LINTER_RULES} --failon warning"
2020-10-08 18:54:28 -04:00
LINTER_COMMANDS_ARRAY['HTML']="htmlhint --config ${HTML_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['JAVA']="java -jar /usr/bin/checkstyle -c ${JAVA_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['JAVASCRIPT_ES']="eslint --no-eslintrc -c ${JAVASCRIPT_ES_LINTER_RULES}"
2020-10-08 18:54:28 -04:00
LINTER_COMMANDS_ARRAY['JAVASCRIPT_STANDARD']="standard ${JAVASCRIPT_STANDARD_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['JSON']="jsonlint"
LINTER_COMMANDS_ARRAY['JSX']="eslint --no-eslintrc -c ${JSX_LINTER_RULES}"
2020-10-08 18:54:28 -04:00
LINTER_COMMANDS_ARRAY['KOTLIN']="ktlint"
LINTER_COMMANDS_ARRAY['KUBERNETES_KUBEVAL']="kubeval --strict"
LINTER_COMMANDS_ARRAY['LATEX']="chktex -q -l ${LATEX_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['LUA']="luacheck --config ${LUA_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['MARKDOWN']="markdownlint -c ${MARKDOWN_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['OPENAPI']="spectral lint -r ${OPENAPI_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['PERL']="perlcritic"
LINTER_COMMANDS_ARRAY['PHP_BUILTIN']="php -l"
LINTER_COMMANDS_ARRAY['PHP_PHPCS']="phpcs --standard=${PHP_PHPCS_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['PHP_PHPSTAN']="phpstan analyse --no-progress --no-ansi -c ${PHP_PHPSTAN_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['PHP_PSALM']="psalm --config=${PHP_PSALM_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['POWERSHELL']="Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path"
LINTER_COMMANDS_ARRAY['PROTOBUF']="protolint lint --config_path ${PROTOBUF_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['PYTHON_BLACK']="black --config ${PYTHON_BLACK_LINTER_RULES} --diff --check"
LINTER_COMMANDS_ARRAY['PYTHON_PYLINT']="pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['PYTHON_FLAKE8']="flake8 --config=${PYTHON_FLAKE8_LINTER_RULES}"
2020-10-28 11:22:55 -04:00
LINTER_COMMANDS_ARRAY['PYTHON_ISORT']="isort --check --diff --sp ${PYTHON_ISORT_LINTER_RULES}"
2020-10-08 18:54:28 -04:00
LINTER_COMMANDS_ARRAY['R']="lintr"
LINTER_COMMANDS_ARRAY['RAKU']="raku"
LINTER_COMMANDS_ARRAY['RUBY']="rubocop -c ${RUBY_LINTER_RULES} --force-exclusion"
LINTER_COMMANDS_ARRAY['SHELL_SHFMT']="shfmt -d"
LINTER_COMMANDS_ARRAY['SNAKEMAKE_LINT']="snakemake --lint -s"
LINTER_COMMANDS_ARRAY['SNAKEMAKE_SNAKEFMT']="snakefmt --config ${SNAKEMAKE_SNAKEFMT_LINTER_RULES} --check --compact-diff"
LINTER_COMMANDS_ARRAY['STATES']="asl-validator --json-path"
LINTER_COMMANDS_ARRAY['SQL']="sql-lint --config ${SQL_LINTER_RULES}"
2020-10-13 11:21:23 -04:00
LINTER_COMMANDS_ARRAY['TEKTON']="tekton-lint"
2020-10-08 18:54:28 -04:00
LINTER_COMMANDS_ARRAY['TERRAFORM']="tflint -c ${TERRAFORM_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['TERRAFORM_TERRASCAN']="terrascan scan -p /root/.terrascan/pkg/policies/opa/rego/ -t aws -f "
LINTER_COMMANDS_ARRAY['TERRAGRUNT']="terragrunt hclfmt --terragrunt-check --terragrunt-hclfmt-file "
LINTER_COMMANDS_ARRAY['TSX']="eslint --no-eslintrc -c ${TSX_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['TYPESCRIPT_ES']="eslint --no-eslintrc -c ${TYPESCRIPT_ES_LINTER_RULES}"
2020-10-08 18:54:28 -04:00
LINTER_COMMANDS_ARRAY['TYPESCRIPT_STANDARD']="standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}"
LINTER_COMMANDS_ARRAY['XML']="xmllint"
LINTER_COMMANDS_ARRAY['YAML']="yamllint -c ${YAML_LINTER_RULES}"
2020-10-15 10:04:51 -04:00
debug "--- Linter commands ---"
debug "-----------------------"
for i in "${!LINTER_COMMANDS_ARRAY[@]}"; do
debug "Linter key: $i, command: ${LINTER_COMMANDS_ARRAY[$i]}"
done
debug "---------------------------------------------"
###########################################
# Build the list of files for each linter #
###########################################
BuildFileList "${VALIDATE_ALL_CODEBASE}" "${TEST_CASE_RUN}"
2019-10-21 15:12:37 -04:00
2020-07-23 13:52:43 -04:00
###############
2020-10-08 18:54:28 -04:00
# Run linters #
2020-07-23 13:52:43 -04:00
###############
2020-10-08 18:54:28 -04:00
EDITORCONFIG_FILE_PATH="${GITHUB_WORKSPACE}"/.editorconfig
2019-10-21 12:05:55 -04:00
####################################
# Print ENV before running linters #
####################################
debug "--- ENV (before running linters) ---"
debug "------------------------------------"
PRINTENV=$(printenv | sort)
debug "ENV:"
debug "${PRINTENV}"
debug "------------------------------------"
2020-10-08 18:54:28 -04:00
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
debug "Running linter for the ${LANGUAGE} language..."
VALIDATE_LANGUAGE_VARIABLE_NAME="VALIDATE_${LANGUAGE}"
debug "Setting VALIDATE_LANGUAGE_VARIABLE_NAME to ${VALIDATE_LANGUAGE_VARIABLE_NAME}..."
VALIDATE_LANGUAGE_VARIABLE_VALUE="${!VALIDATE_LANGUAGE_VARIABLE_NAME}"
debug "Setting VALIDATE_LANGUAGE_VARIABLE_VALUE to ${VALIDATE_LANGUAGE_VARIABLE_VALUE}..."
if [ "${VALIDATE_LANGUAGE_VARIABLE_VALUE}" = "true" ]; then
# Check if we need an .editorconfig file
# shellcheck disable=SC2153
if [ "${LANGUAGE}" = "EDITORCONFIG" ] || [ "${LANGUAGE}" = "SHELL_SHFMT" ]; then
if [ -e "${EDITORCONFIG_FILE_PATH}" ]; then
debug "Found an EditorConfig file at ${EDITORCONFIG_FILE_PATH}"
else
debug "No .editorconfig found at: $EDITORCONFIG_FILE_PATH. Skipping ${LANGUAGE} linting..."
continue
fi
elif [ "${LANGUAGE}" = "R" ] && [ ! -f "${GITHUB_WORKSPACE}/.lintr" ] && ((${#FILE_ARRAY_R[@]})); then
2020-11-06 17:10:09 -05:00
info "No .lintr configuration file found, using defaults."
cp "$R_LINTER_RULES" "$GITHUB_WORKSPACE"
2020-10-08 18:54:28 -04:00
# Check if there's local configuration for the Raku linter
elif [ "${LANGUAGE}" = "RAKU" ] && [ -e "${GITHUB_WORKSPACE}/META6.json" ]; then
cd "${GITHUB_WORKSPACE}" && zef install --deps-only --/test .
fi
2020-06-25 02:13:19 -04:00
2020-10-08 18:54:28 -04:00
if [ "${LANGUAGE}" = "ANSIBLE" ]; then
# Due to the nature of how we want to validate Ansible, we cannot use the
# standard loop, since it looks for an ansible folder, excludes certain
# files, and looks for additional changes, it should be an outlier
LintAnsibleFiles "${ANSIBLE_LINTER_RULES}" # Passing rules but not needed, dont want to exclude unused var
else
LINTER_NAME="${LINTER_NAMES_ARRAY["${LANGUAGE}"]}"
2020-11-06 17:10:09 -05:00
if [ -z "${LINTER_NAME}" ]; then
2020-10-08 18:54:28 -04:00
fatal "Cannot find the linter name for ${LANGUAGE} language."
else
debug "Setting LINTER_NAME to ${LINTER_NAME}..."
fi
2020-08-17 08:01:25 -04:00
2020-10-08 18:54:28 -04:00
LINTER_COMMAND="${LINTER_COMMANDS_ARRAY["${LANGUAGE}"]}"
2020-11-06 17:10:09 -05:00
if [ -z "${LINTER_COMMAND}" ]; then
2020-10-08 18:54:28 -04:00
fatal "Cannot find the linter command for ${LANGUAGE} language."
else
debug "Setting LINTER_COMMAND to ${LINTER_COMMAND}..."
fi
2020-08-15 15:29:22 -04:00
2020-10-08 18:54:28 -04:00
FILE_ARRAY_VARIABLE_NAME="FILE_ARRAY_${LANGUAGE}"
debug "Setting FILE_ARRAY_VARIABLE_NAME to ${FILE_ARRAY_VARIABLE_NAME}..."
2020-06-25 02:13:19 -04:00
2020-10-08 18:54:28 -04:00
# shellcheck disable=SC2125
LANGUAGE_FILE_ARRAY="${FILE_ARRAY_VARIABLE_NAME}"[@]
debug "${FILE_ARRAY_VARIABLE_NAME} file array contents: ${!LANGUAGE_FILE_ARRAY}"
2020-07-04 18:14:27 -04:00
debug "Invoking ${LINTER_NAME} linter. TEST_CASE_RUN: ${TEST_CASE_RUN}"
LintCodebase "${LANGUAGE}" "${LINTER_NAME}" "${LINTER_COMMAND}" "${FILTER_REGEX_INCLUDE}" "${FILTER_REGEX_EXCLUDE}" "${TEST_CASE_RUN}" "${!LANGUAGE_FILE_ARRAY}"
2020-10-08 18:54:28 -04:00
fi
2020-08-31 17:44:35 -04:00
fi
2020-10-08 18:54:28 -04:00
done
2020-07-23 13:52:43 -04:00
2020-07-22 15:49:26 -04:00
###########
# Reports #
###########
Reports
2019-10-21 12:05:55 -04:00
##########
# Footer #
##########
Footer