feat: validate variables and simplify lowercase (#5128)

- Validate variables representing boolean values.
- Group global variables in the same sections.
- Declare variables as lowercase with the 'declare -l' shell builtin for
  more clarity.
This commit is contained in:
Marco Ferrari 2024-01-11 21:30:00 +01:00 committed by GitHub
parent 5a2056d77a
commit 4a28fc5e73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 157 additions and 227 deletions

View file

@ -188,8 +188,10 @@ function BuildFileList() {
for FILE in "${RAW_FILE_ARRAY[@]}"; do for FILE in "${RAW_FILE_ARRAY[@]}"; do
# Get the file extension # Get the file extension
FILE_TYPE="$(GetFileExtension "$FILE")" FILE_TYPE="$(GetFileExtension "$FILE")"
# Get the name of the file (lowercase) and the containing directory path # We want a lowercase value
BASE_FILE=$(basename "${FILE,,}") local -l BASE_FILE
# Get the name of the file and the containing directory path
BASE_FILE=$(basename "${FILE}")
FILE_DIR_NAME="$(dirname "${FILE}")" FILE_DIR_NAME="$(dirname "${FILE}")"
debug "FILE: ${FILE}, FILE_TYPE: ${FILE_TYPE}, BASE_FILE: ${BASE_FILE}, FILE_DIR_NAME: ${FILE_DIR_NAME}" debug "FILE: ${FILE}, FILE_TYPE: ${FILE_TYPE}, BASE_FILE: ${BASE_FILE}, FILE_DIR_NAME: ${FILE_DIR_NAME}"

View file

@ -196,15 +196,10 @@ function CheckFileType() {
function GetFileExtension() { function GetFileExtension() {
FILE="$1" FILE="$1"
# We want a lowercase value
########################### local -l FILE_TYPE
# Get the files extension # # Extract the file extension
###########################
# Extract just the file extension
FILE_TYPE=${FILE##*.} FILE_TYPE=${FILE##*.}
# To lowercase
FILE_TYPE=${FILE_TYPE,,}
echo "$FILE_TYPE" echo "$FILE_TYPE"
} }

View file

@ -1,64 +1,60 @@
#!/usr/bin/env bash #!/usr/bin/env bash
function ValidateBooleanConfigurationVariables() {
ValidateBooleanVariable "ACTIONS_RUNNER_DEBUG" "${ACTIONS_RUNNER_DEBUG}"
ValidateBooleanVariable "CREATE_LOG_FILE" "${CREATE_LOG_FILE}"
ValidateBooleanVariable "DISABLE_ERRORS" "${DISABLE_ERRORS}"
ValidateBooleanVariable "ENABLE_GITHUB_ACTIONS_GROUP_TITLE" "${ENABLE_GITHUB_ACTIONS_GROUP_TITLE}"
ValidateBooleanVariable "IGNORE_GENERATED_FILES" "${IGNORE_GENERATED_FILES}"
ValidateBooleanVariable "IGNORE_GITIGNORED_FILES" "${IGNORE_GITIGNORED_FILES}"
ValidateBooleanVariable "MULTI_STATUS" "${MULTI_STATUS}"
ValidateBooleanVariable "RUN_LOCAL" "${RUN_LOCAL}"
ValidateBooleanVariable "SSH_INSECURE_NO_VERIFY_GITHUB_KEY" "${SSH_INSECURE_NO_VERIFY_GITHUB_KEY}"
ValidateBooleanVariable "SSH_SETUP_GITHUB" "${SSH_SETUP_GITHUB}"
ValidateBooleanVariable "SUPPRESS_FILE_TYPE_WARN" "${SUPPRESS_FILE_TYPE_WARN}"
ValidateBooleanVariable "SUPPRESS_POSSUM" "${SUPPRESS_POSSUM}"
ValidateBooleanVariable "USE_FIND_ALGORITHM" "${USE_FIND_ALGORITHM}"
ValidateBooleanVariable "TEST_CASE_RUN" "${TEST_CASE_RUN}"
ValidateBooleanVariable "VALIDATE_ALL_CODEBASE" "${VALIDATE_ALL_CODEBASE}"
ValidateBooleanVariable "YAML_ERROR_ON_WARNING" "${YAML_ERROR_ON_WARNING}"
ValidateBooleanVariable "WRITE_LINTER_VERSIONS_FILE" "${WRITE_LINTER_VERSIONS_FILE}"
}
function ValidateGitHubWorkspace() {
local GITHUB_WORKSPACE
GITHUB_WORKSPACE="${1}"
if [ -z "${GITHUB_WORKSPACE}" ]; then
fatal "Failed to get GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
fi
if [ ! -d "${GITHUB_WORKSPACE}" ]; then
fatal "The workspace (${GITHUB_WORKSPACE}) is not a directory!"
fi
info "Successfully validated GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
}
function GetValidationInfo() { function GetValidationInfo() {
############################################
# Print headers for user provided env vars #
############################################
info "--------------------------------------------" info "--------------------------------------------"
info "Gathering user validation information..." info "Validating the configuration"
if [[ "${USE_FIND_ALGORITHM}" == "true" ]] && [[ "${VALIDATE_ALL_CODEBASE}" == "false" ]]; then if [[ "${USE_FIND_ALGORITHM}" == "true" ]] && [[ "${VALIDATE_ALL_CODEBASE}" == "false" ]]; then
fatal "Setting USE_FIND_ALGORITHM to true and VALIDATE_ALL_CODEBASE to false is not supported because super-linter relies on Git to validate changed files." fatal "Setting USE_FIND_ALGORITHM to true and VALIDATE_ALL_CODEBASE to false is not supported because super-linter relies on Git to validate changed files."
fi fi
###########################################
# Skip validation if were running locally #
###########################################
if [[ ${RUN_LOCAL} != "true" ]]; then
###############################
# Convert string to lowercase #
###############################
VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE,,}"
######################################
# Validate we should check all files #
######################################
if [[ ${VALIDATE_ALL_CODEBASE} != "false" ]]; then
# Set to true
VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}"
info "- Validating ALL files in code base..."
else
info "- Only validating [new], or [edited] files in code base..."
fi
fi
######################
# Create Print Array #
######################
PRINT_ARRAY=()
################################
# Convert strings to lowercase #
################################
# Loop through all languages
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
# build the variable
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
# Set the value of the var to lowercase
eval "${VALIDATE_LANGUAGE}=${!VALIDATE_LANGUAGE,,}"
done
################################################ ################################################
# Determine if any linters were explicitly set # # Determine if any linters were explicitly set #
################################################ ################################################
ANY_SET="false" ANY_SET="false"
ANY_TRUE="false" ANY_TRUE="false"
ANY_FALSE="false" ANY_FALSE="false"
# Loop through all languages
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
# build the variable local VALIDATE_LANGUAGE
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
# Check to see if the variable was set debug "Set VALIDATE_LANGUAGE while validating the configuration: ${VALIDATE_LANGUAGE}"
if [ -n "${!VALIDATE_LANGUAGE}" ]; then if [ -n "${!VALIDATE_LANGUAGE}" ]; then
# Validate if user provided a string representing a valid boolean
ValidateBooleanVariable "${VALIDATE_LANGUAGE}" "${!VALIDATE_LANGUAGE}"
# It was set, need to set flag # It was set, need to set flag
ANY_SET="true" ANY_SET="true"
if [ "${!VALIDATE_LANGUAGE}" == "true" ]; then if [ "${!VALIDATE_LANGUAGE}" == "true" ]; then
@ -66,6 +62,8 @@ function GetValidationInfo() {
elif [ "${!VALIDATE_LANGUAGE}" == "false" ]; then elif [ "${!VALIDATE_LANGUAGE}" == "false" ]; then
ANY_FALSE="true" ANY_FALSE="true"
fi fi
else
debug "Configuration didn't provide a custom value for ${VALIDATE_LANGUAGE}"
fi fi
done done
@ -76,13 +74,10 @@ function GetValidationInfo() {
######################################################### #########################################################
# Validate if we should check/omit individual languages # # Validate if we should check/omit individual languages #
######################################################### #########################################################
# Loop through all languages
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
# build the variable local VALIDATE_LANGUAGE
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
# Check if ANY_SET was set
if [[ ${ANY_SET} == "true" ]]; then if [[ ${ANY_SET} == "true" ]]; then
# Check to see if the variable was set
if [ -z "${!VALIDATE_LANGUAGE}" ]; then if [ -z "${!VALIDATE_LANGUAGE}" ]; then
# Flag was not set, default to: # Flag was not set, default to:
# if ANY_TRUE then set to false # if ANY_TRUE then set to false
@ -101,11 +96,10 @@ function GetValidationInfo() {
####################################### #######################################
# Loop through all languages # Loop through all languages
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
# build the variable local VALIDATE_LANGUAGE
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
if [[ ${!VALIDATE_LANGUAGE} == "true" ]]; then if [[ ${!VALIDATE_LANGUAGE} == "true" ]]; then
# We need to validate debug "- Validating [${LANGUAGE}] files in code base..."
PRINT_ARRAY+=("- Validating [${LANGUAGE}] files in code base...")
debug "Defining variables for ${LANGUAGE} linter..." debug "Defining variables for ${LANGUAGE} linter..."
@ -115,8 +109,7 @@ function GetValidationInfo() {
debug "Exporting ${ERRORS_VARIABLE_NAME} variable..." debug "Exporting ${ERRORS_VARIABLE_NAME} variable..."
eval "export ${ERRORS_VARIABLE_NAME}" eval "export ${ERRORS_VARIABLE_NAME}"
else else
# We are skipping the language debug "- Excluding [$LANGUAGE] files in code base..."
PRINT_ARRAY+=("- Excluding [$LANGUAGE] files in code base...")
fi fi
done done
@ -147,65 +140,9 @@ function GetValidationInfo() {
debug "Setting Ansible directory to: ${ANSIBLE_DIRECTORY}" debug "Setting Ansible directory to: ${ANSIBLE_DIRECTORY}"
fi fi
############################### debug "Runner: $(id -un 2>/dev/null)"
# Get the disable errors flag #
###############################
if [ -z "${DISABLE_ERRORS}" ]; then
##################################
# No flag passed, set to default #
##################################
DISABLE_ERRORS="${DEFAULT_DISABLE_ERRORS}"
fi
###############################
# Convert string to lowercase #
###############################
DISABLE_ERRORS="${DISABLE_ERRORS,,}"
############################
# Set to false if not true #
############################
if [ "${DISABLE_ERRORS}" != "true" ]; then
DISABLE_ERRORS="false"
fi
############################
# Get the run verbose flag #
############################
if [ -z "${ACTIONS_RUNNER_DEBUG}" ]; then
##################################
# No flag passed, set to default #
##################################
ACTIONS_RUNNER_DEBUG="${DEFAULT_ACTIONS_RUNNER_DEBUG}"
fi
###############################
# Convert string to lowercase #
###############################
ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG,,}"
############################
# Set to true if not false #
############################
if [ "${ACTIONS_RUNNER_DEBUG}" != "false" ]; then
ACTIONS_RUNNER_DEBUG="true"
fi
###########################
# Print the validate info #
###########################
for LINE in "${PRINT_ARRAY[@]}"; do
debug "${LINE}"
done
debug "--- DEBUG INFO ---"
debug "---------------------------------------------"
RUNNER=$(id -un 2>/dev/null)
debug "Runner:[${RUNNER}]"
PRINTENV=$(printenv | sort)
debug "ENV:" debug "ENV:"
debug "${PRINTENV}" debug "$(printenv | sort)"
debug "---------------------------------------------"
} }
function CheckIfGitBranchExists() { function CheckIfGitBranchExists() {
@ -220,6 +157,20 @@ function CheckIfGitBranchExists() {
fi fi
} }
function ValidateBooleanVariable() {
local VAR_NAME
VAR_NAME="${1}"
local VAR_VALUE
VAR_VALUE="${2}"
if [[ "${VAR_VALUE}" != "true" ]] && [[ "${VAR_VALUE}" != "false" ]]; then
fatal "Set ${VAR_NAME} to either true or false. It was set to: ${VAR_VALUE}"
else
debug "${VAR_NAME} has a valid boolean string value: ${VAR_VALUE}"
fi
}
function ValidateLocalGitRepository() { function ValidateLocalGitRepository() {
debug "Check if ${GITHUB_WORKSPACE} is a Git repository" debug "Check if ${GITHUB_WORKSPACE} is a Git repository"
if ! git -C "${GITHUB_WORKSPACE}" rev-parse --git-dir; then if ! git -C "${GITHUB_WORKSPACE}" rev-parse --git-dir; then

View file

@ -91,9 +91,10 @@ function LintCodebase() {
for FILE in "${LIST_FILES[@]}"; do for FILE in "${LIST_FILES[@]}"; do
debug "Linting FILE: ${FILE}" debug "Linting FILE: ${FILE}"
local INDIVIDUAL_TEST_FOLDER # We want a lowercase value
local -l INDIVIDUAL_TEST_FOLDER
# Folder for specific tests. By convention, it's the lowercased FILE_TYPE # Folder for specific tests. By convention, it's the lowercased FILE_TYPE
INDIVIDUAL_TEST_FOLDER="${FILE_TYPE,,}" INDIVIDUAL_TEST_FOLDER="${FILE_TYPE}"
debug "INDIVIDUAL_TEST_FOLDER for ${FILE}: ${INDIVIDUAL_TEST_FOLDER}" debug "INDIVIDUAL_TEST_FOLDER for ${FILE}: ${INDIVIDUAL_TEST_FOLDER}"
local TEST_CASE_DIRECTORY local TEST_CASE_DIRECTORY

View file

@ -4,8 +4,9 @@
# Debug Vars # # Debug Vars #
# Define these early, so we can use debug logging ASAP if needed # # Define these early, so we can use debug logging ASAP if needed #
################################################################## ##################################################################
ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-false}" # Boolean to see even more info (debug) declare -l ACTIONS_RUNNER_DEBUG
IMAGE="${IMAGE:-standard}" # Version of the Super-linter (standard,slim,etc) ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-"false"}" # Boolean to see even more info (debug)
IMAGE="${IMAGE:-standard}" # Version of the Super-linter (standard,slim,etc)
################################################################## ##################################################################
# Log Vars # # Log Vars #
@ -13,8 +14,8 @@ IMAGE="${IMAGE:-standard}" # Version of the Super-lin
################################################################## ##################################################################
LOG_FILE="${LOG_FILE:-"super-linter.log"}" # Default log file name (located in GITHUB_WORKSPACE folder) 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) LOG_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE)
declare -l CREATE_LOG_FILE
CREATE_LOG_FILE="${CREATE_LOG_FILE:-"false"}" CREATE_LOG_FILE="${CREATE_LOG_FILE:-"false"}"
export CREATE_LOG_FILE
if [[ ${ACTIONS_RUNNER_DEBUG} == true ]]; then LOG_LEVEL="DEBUG"; fi if [[ ${ACTIONS_RUNNER_DEBUG} == true ]]; then LOG_LEVEL="DEBUG"; fi
# Boolean to see trace logs # Boolean to see trace logs
@ -60,15 +61,10 @@ source /action/lib/functions/setupSSH.sh # Source the function script(s)
# shellcheck source=/dev/null # shellcheck source=/dev/null
source /action/lib/functions/githubEvent.sh source /action/lib/functions/githubEvent.sh
# We want a lowercase value
declare -l RUN_LOCAL
# Initialize RUN_LOCAL early because we need it for logging # Initialize RUN_LOCAL early because we need it for logging
DEFAULT_RUN_LOCAL='false' RUN_LOCAL="${RUN_LOCAL:-"false"}"
if [ -z "${RUN_LOCAL}" ]; then
RUN_LOCAL="${DEFAULT_RUN_LOCAL}"
fi
# Convert string to lowercase
RUN_LOCAL="${RUN_LOCAL,,}"
# Dynamically set the default behavior for GitHub Actions log markers because # Dynamically set the default behavior for GitHub Actions log markers because
# we want to give users a chance to enable this even when running locally, but # we want to give users a chance to enable this even when running locally, but
@ -84,37 +80,85 @@ ENABLE_GITHUB_ACTIONS_GROUP_TITLE="${ENABLE_GITHUB_ACTIONS_GROUP_TITLE:-"${DEFAU
startGitHubActionsLogGroup "${SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE}" startGitHubActionsLogGroup "${SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE}"
debug "RUN_LOCAL: ${RUN_LOCAL}" # We want a lowercase value
debug "ENABLE_GITHUB_ACTIONS_GROUP_TITLE: ${ENABLE_GITHUB_ACTIONS_GROUP_TITLE}" declare -l DISABLE_ERRORS
DISABLE_ERRORS="${DISABLE_ERRORS:-"false"}"
# We want a lowercase value
declare -l IGNORE_GENERATED_FILES
# Do not ignore generated files by default for backwards compatibility
IGNORE_GENERATED_FILES="${IGNORE_GENERATED_FILES:-false}"
# We want a lowercase value
declare -l IGNORE_GITIGNORED_FILES
IGNORE_GITIGNORED_FILES="${IGNORE_GITIGNORED_FILES:-false}"
# We want a lowercase value
declare -l MULTI_STATUS
MULTI_STATUS="${MULTI_STATUS:-true}"
# We want a lowercase value
declare -l SSH_INSECURE_NO_VERIFY_GITHUB_KEY
SSH_INSECURE_NO_VERIFY_GITHUB_KEY="${SSH_INSECURE_NO_VERIFY_GITHUB_KEY:-false}"
# We want a lowercase value
declare -l SSH_SETUP_GITHUB
SSH_SETUP_GITHUB="${SSH_SETUP_GITHUB:-false}"
# We want a lowercase value
declare -l SUPPRESS_FILE_TYPE_WARN
SUPPRESS_FILE_TYPE_WARN="${SUPPRESS_FILE_TYPE_WARN:-false}"
# We want a lowercase value
declare -l SUPPRESS_POSSUM
SUPPRESS_POSSUM="${SUPPRESS_POSSUM:-false}"
# We want a lowercase value
declare -l TEST_CASE_RUN
# Option to tell code to run only test cases
TEST_CASE_RUN="${TEST_CASE_RUN:-"false"}"
# We want a lowercase value
declare -l USE_FIND_ALGORITHM
USE_FIND_ALGORITHM="${USE_FIND_ALGORITHM:-false}"
# We want a lowercase value
declare -l VALIDATE_ALL_CODEBASE
VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE:-"true"}"
# We want a lowercase value
declare -l YAML_ERROR_ON_WARNING
YAML_ERROR_ON_WARNING="${YAML_ERROR_ON_WARNING:-false}"
declare -l WRITE_LINTER_VERSIONS_FILE
WRITE_LINTER_VERSIONS_FILE="${WRITE_LINTER_VERSIONS_FILE:-"false"}"
ValidateBooleanConfigurationVariables
########### ###########
# GLOBALS # # GLOBALS #
########### ###########
DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}"
DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location
DEFAULT_SUPER_LINTER_WORKSPACE="/tmp/lint" # Fall-back value for the workspace
DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-${DEFAULT_SUPER_LINTER_WORKSPACE}}" # Default workspace if running locally
FILTER_REGEX_INCLUDE="${FILTER_REGEX_INCLUDE:-""}"
FILTER_REGEX_EXCLUDE="${FILTER_REGEX_EXCLUDE:-""}"
# GitHub API root url # GitHub API root url
if [ -n "$GITHUB_CUSTOM_API_URL" ]; then GITHUB_API_URL="${GITHUB_CUSTOM_API_URL:-"https://api.github.com"}"
GITHUB_API_URL="${GITHUB_CUSTOM_API_URL}"
elif [ -z "$GITHUB_API_URL" ]; then
GITHUB_API_URL="https://api.github.com"
fi
# Remove trailing slash if present # Remove trailing slash if present
GITHUB_API_URL="${GITHUB_API_URL%/}" GITHUB_API_URL="${GITHUB_API_URL%/}"
GITHUB_SERVER_URL="${GITHUB_DOMAIN:-"https://github.com"}"
# GitHub server url
if [ -n "$GITHUB_DOMAIN" ]; then
GITHUB_SERVER_URL="${GITHUB_DOMAIN}"
elif [ -z "$GITHUB_SERVER_URL" ]; then
GITHUB_SERVER_URL="https://github.com"
fi
# Extract domain name from URL # Extract domain name from URL
GITHUB_SERVER_URL=$(echo "$GITHUB_SERVER_URL" | cut -d '/' -f 3) GITHUB_SERVER_URL=$(echo "$GITHUB_SERVER_URL" | cut -d '/' -f 3)
LINTED_LANGUAGES_ARRAY=() # Will be filled at run time with all languages that were linted
# Default Vars
DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location
LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter rules directory LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter rules directory
VERSION_FILE='/action/lib/functions/linterVersions.txt' # File to store linter versions # shellcheck disable=SC2034 # Variable is referenced in other scripts
export VERSION_FILE # Workaround SC2034 RAW_FILE_ARRAY=() # Array of all files that were changed
# shellcheck disable=SC2034 # Variable is referenced in other scripts
debug "CREATE_LOG_FILE: ${CREATE_LOG_FILE}" TEST_CASE_FOLDER='test/linters' # Folder for test cases we should always ignore
# shellcheck disable=SC2034 # Variable is referenced in other scripts
VERSION_FILE='/action/lib/functions/linterVersions.txt' # File to store linter versions
# Set the log level # Set the log level
TF_LOG_LEVEL="info" TF_LOG_LEVEL="info"
@ -215,15 +259,6 @@ SCALAFMT_FILE_NAME="${SCALAFMT_CONFIG_FILE:-.scalafmt.conf}"
# shellcheck disable=SC2034 # Variable is referenced indirectly # shellcheck disable=SC2034 # Variable is referenced indirectly
SNAKEMAKE_SNAKEFMT_FILE_NAME="${SNAKEMAKE_SNAKEFMT_CONFIG_FILE:-.snakefmt.toml}" SNAKEMAKE_SNAKEFMT_FILE_NAME="${SNAKEMAKE_SNAKEFMT_CONFIG_FILE:-.snakefmt.toml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly # shellcheck disable=SC2034 # Variable is referenced indirectly
SUPPRESS_FILE_TYPE_WARN="${SUPPRESS_FILE_TYPE_WARN:-false}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
SUPPRESS_POSSUM="${SUPPRESS_POSSUM:-false}"
# SSH_KEY="${SSH_KEY}"
SSH_SETUP_GITHUB="${SSH_SETUP_GITHUB:-false}"
SSH_INSECURE_NO_VERIFY_GITHUB_KEY="${SSH_INSECURE_NO_VERIFY_GITHUB_KEY:-false}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
# SSL_CERT_SECRET="${SSL_CERT_SECRET}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
SQL_FILE_NAME="${SQL_CONFIG_FILE:-.sql-config.json}" SQL_FILE_NAME="${SQL_CONFIG_FILE:-.sql-config.json}"
# shellcheck disable=SC2034 # Variable is referenced indirectly # shellcheck disable=SC2034 # Variable is referenced indirectly
SQLFLUFF_FILE_NAME="${SQLFLUFF_CONFIG_FILE:-/.sqlfluff}" SQLFLUFF_FILE_NAME="${SQLFLUFF_CONFIG_FILE:-/.sqlfluff}"
@ -241,14 +276,8 @@ TYPESCRIPT_STYLE_NAME='' # Variable for the style
TYPESCRIPT_STYLE='' # Variable for the style TYPESCRIPT_STYLE='' # Variable for the style
# shellcheck disable=SC2034 # Variable is referenced indirectly # shellcheck disable=SC2034 # Variable is referenced indirectly
TYPESCRIPT_ES_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" TYPESCRIPT_ES_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
USE_FIND_ALGORITHM="${USE_FIND_ALGORITHM:-false}"
debug "USE_FIND_ALGORITHM: ${USE_FIND_ALGORITHM}"
# shellcheck disable=SC2034 # Variable is referenced indirectly # shellcheck disable=SC2034 # Variable is referenced indirectly
YAML_FILE_NAME="${YAML_CONFIG_FILE:-.yaml-lint.yml}" YAML_FILE_NAME="${YAML_CONFIG_FILE:-.yaml-lint.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
YAML_ERROR_ON_WARNING="${YAML_ERROR_ON_WARNING:-false}"
################################################# #################################################
# Parse if we are using JS standard or prettier # # Parse if we are using JS standard or prettier #
@ -383,50 +412,6 @@ LINTER_NAMES_ARRAY["${TYPESCRIPT_STYLE_NAME}"]="${TYPESCRIPT_STYLE}"
LINTER_NAMES_ARRAY['XML']="xmllint" LINTER_NAMES_ARRAY['XML']="xmllint"
LINTER_NAMES_ARRAY['YAML']="yamllint" LINTER_NAMES_ARRAY['YAML']="yamllint"
############################################
# Array for all languages that were linted #
############################################
LINTED_LANGUAGES_ARRAY=() # Will be filled at run time with all languages that were linted
###################
# GitHub ENV Vars #
###################
MULTI_STATUS="${MULTI_STATUS:-true}" # Multiple status are created for each check ran
MULTI_STATUS="${MULTI_STATUS,,}" # Convert string to lowercase
DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default)
IGNORE_GITIGNORED_FILES="${IGNORE_GITIGNORED_FILES:-false}"
debug "IGNORE_GITIGNORED_FILES: ${IGNORE_GITIGNORED_FILES}"
# Do not ignore generated files by default for backwards compatibility
IGNORE_GENERATED_FILES="${IGNORE_GENERATED_FILES:-false}"
debug "IGNORE_GENERATED_FILES: ${IGNORE_GENERATED_FILES}"
################
# Default Vars #
################
DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files
DEFAULT_SUPER_LINTER_WORKSPACE="/tmp/lint" # Fall-back value for the workspace
DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-${DEFAULT_SUPER_LINTER_WORKSPACE}}" # Default workspace if running locally
DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases
if [ -z "${TEST_CASE_RUN}" ]; then
TEST_CASE_RUN="${DEFAULT_TEST_CASE_RUN}"
fi
# Convert string to lowercase
TEST_CASE_RUN="${TEST_CASE_RUN,,}"
debug "TEST_CASE_RUN: ${TEST_CASE_RUN}"
###############################################################
# Default Vars that are called in Subs and need to be ignored #
###############################################################
DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors
export DEFAULT_DISABLE_ERRORS # Workaround SC2034
RAW_FILE_ARRAY=() # Array of all files that were changed
export RAW_FILE_ARRAY # Workaround SC2034
TEST_CASE_FOLDER='test/linters' # Folder for test cases we should always ignore
export TEST_CASE_FOLDER # Workaround SC2034
########################## ##########################
# Array of changed files # # Array of changed files #
########################## ##########################
@ -462,6 +447,13 @@ Header() {
info "The Super-Linter source code can be found at:" info "The Super-Linter source code can be found at:"
info " - https://github.com/super-linter/super-linter" info " - https://github.com/super-linter/super-linter"
info "---------------------------------------------" info "---------------------------------------------"
if [[ ${VALIDATE_ALL_CODEBASE} != "false" ]]; then
VALIDATE_ALL_CODEBASE="true"
info "- Validating all files in code base..."
else
info "- Validating changed files in code base..."
fi
} }
ConfigureGitSafeDirectories() { ConfigureGitSafeDirectories() {
@ -491,16 +483,10 @@ GetGitHubVars() {
GITHUB_WORKSPACE="${DEFAULT_WORKSPACE}" GITHUB_WORKSPACE="${DEFAULT_WORKSPACE}"
fi fi
if [ ! -d "${GITHUB_WORKSPACE}" ]; then ValidateGitHubWorkspace "${GITHUB_WORKSPACE}"
fatal "The workspace (${GITHUB_WORKSPACE}) is not a directory!"
fi
pushd "${GITHUB_WORKSPACE}" >/dev/null || exit 1 pushd "${GITHUB_WORKSPACE}" >/dev/null || exit 1
VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}"
info "Linting all files in mapped directory: ${GITHUB_WORKSPACE}"
debug "Setting VALIDATE_ALL_CODEBASE to ${VALIDATE_ALL_CODEBASE} because we are not running on GitHub Actions"
if [[ "${USE_FIND_ALGORITHM}" == "false" ]]; then if [[ "${USE_FIND_ALGORITHM}" == "false" ]]; then
ConfigureGitSafeDirectories ConfigureGitSafeDirectories
debug "Initializing GITHUB_SHA considering ${GITHUB_WORKSPACE}" debug "Initializing GITHUB_SHA considering ${GITHUB_WORKSPACE}"
@ -518,11 +504,7 @@ GetGitHubVars() {
MULTI_STATUS="false" MULTI_STATUS="false"
debug "Setting MULTI_STATUS to ${MULTI_STATUS} because we are not running on GitHub Actions" debug "Setting MULTI_STATUS to ${MULTI_STATUS} because we are not running on GitHub Actions"
else else
if [ -z "${GITHUB_WORKSPACE}" ]; then ValidateGitHubWorkspace "${GITHUB_WORKSPACE}"
fatal "Failed to get GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
else
info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]"
fi
# Ensure that Git can access the local repository # Ensure that Git can access the local repository
ConfigureGitSafeDirectories ConfigureGitSafeDirectories
@ -1083,9 +1065,8 @@ EDITORCONFIG_FILE_PATH="${GITHUB_WORKSPACE}"/.editorconfig
#################################### ####################################
debug "--- ENV (before running linters) ---" debug "--- ENV (before running linters) ---"
debug "------------------------------------" debug "------------------------------------"
PRINTENV=$(printenv | sort)
debug "ENV:" debug "ENV:"
debug "${PRINTENV}" debug "$(printenv | sort)"
debug "------------------------------------" debug "------------------------------------"
endGitHubActionsLogGroup "${SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE}" endGitHubActionsLogGroup "${SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE}"