mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-25 15:41:02 -05:00
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:
parent
5a2056d77a
commit
4a28fc5e73
5 changed files with 157 additions and 227 deletions
|
@ -188,8 +188,10 @@ function BuildFileList() {
|
|||
for FILE in "${RAW_FILE_ARRAY[@]}"; do
|
||||
# Get the file extension
|
||||
FILE_TYPE="$(GetFileExtension "$FILE")"
|
||||
# Get the name of the file (lowercase) and the containing directory path
|
||||
BASE_FILE=$(basename "${FILE,,}")
|
||||
# We want a lowercase value
|
||||
local -l BASE_FILE
|
||||
# Get the name of the file and the containing directory path
|
||||
BASE_FILE=$(basename "${FILE}")
|
||||
FILE_DIR_NAME="$(dirname "${FILE}")"
|
||||
|
||||
debug "FILE: ${FILE}, FILE_TYPE: ${FILE_TYPE}, BASE_FILE: ${BASE_FILE}, FILE_DIR_NAME: ${FILE_DIR_NAME}"
|
||||
|
|
|
@ -196,15 +196,10 @@ function CheckFileType() {
|
|||
|
||||
function GetFileExtension() {
|
||||
FILE="$1"
|
||||
|
||||
###########################
|
||||
# Get the files extension #
|
||||
###########################
|
||||
# Extract just the file extension
|
||||
# We want a lowercase value
|
||||
local -l FILE_TYPE
|
||||
# Extract the file extension
|
||||
FILE_TYPE=${FILE##*.}
|
||||
# To lowercase
|
||||
FILE_TYPE=${FILE_TYPE,,}
|
||||
|
||||
echo "$FILE_TYPE"
|
||||
}
|
||||
|
||||
|
|
|
@ -1,64 +1,60 @@
|
|||
#!/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() {
|
||||
############################################
|
||||
# Print headers for user provided env vars #
|
||||
############################################
|
||||
info "--------------------------------------------"
|
||||
info "Gathering user validation information..."
|
||||
info "Validating the configuration"
|
||||
|
||||
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."
|
||||
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 #
|
||||
################################################
|
||||
ANY_SET="false"
|
||||
ANY_TRUE="false"
|
||||
ANY_FALSE="false"
|
||||
# Loop through all languages
|
||||
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
# build the variable
|
||||
local 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
|
||||
# Validate if user provided a string representing a valid boolean
|
||||
ValidateBooleanVariable "${VALIDATE_LANGUAGE}" "${!VALIDATE_LANGUAGE}"
|
||||
# It was set, need to set flag
|
||||
ANY_SET="true"
|
||||
if [ "${!VALIDATE_LANGUAGE}" == "true" ]; then
|
||||
|
@ -66,6 +62,8 @@ function GetValidationInfo() {
|
|||
elif [ "${!VALIDATE_LANGUAGE}" == "false" ]; then
|
||||
ANY_FALSE="true"
|
||||
fi
|
||||
else
|
||||
debug "Configuration didn't provide a custom value for ${VALIDATE_LANGUAGE}"
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -76,13 +74,10 @@ function GetValidationInfo() {
|
|||
#########################################################
|
||||
# Validate if we should check/omit individual languages #
|
||||
#########################################################
|
||||
# Loop through all languages
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
# build the variable
|
||||
local VALIDATE_LANGUAGE
|
||||
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
|
||||
# Check if ANY_SET was set
|
||||
if [[ ${ANY_SET} == "true" ]]; then
|
||||
# Check to see if the variable was set
|
||||
if [ -z "${!VALIDATE_LANGUAGE}" ]; then
|
||||
# Flag was not set, default to:
|
||||
# if ANY_TRUE then set to false
|
||||
|
@ -101,11 +96,10 @@ function GetValidationInfo() {
|
|||
#######################################
|
||||
# Loop through all languages
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
# build the variable
|
||||
local VALIDATE_LANGUAGE
|
||||
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
|
||||
if [[ ${!VALIDATE_LANGUAGE} == "true" ]]; then
|
||||
# We need to validate
|
||||
PRINT_ARRAY+=("- Validating [${LANGUAGE}] files in code base...")
|
||||
debug "- Validating [${LANGUAGE}] files in code base..."
|
||||
|
||||
debug "Defining variables for ${LANGUAGE} linter..."
|
||||
|
||||
|
@ -115,8 +109,7 @@ function GetValidationInfo() {
|
|||
debug "Exporting ${ERRORS_VARIABLE_NAME} variable..."
|
||||
eval "export ${ERRORS_VARIABLE_NAME}"
|
||||
else
|
||||
# We are skipping the language
|
||||
PRINT_ARRAY+=("- Excluding [$LANGUAGE] files in code base...")
|
||||
debug "- Excluding [$LANGUAGE] files in code base..."
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -147,65 +140,9 @@ function GetValidationInfo() {
|
|||
debug "Setting Ansible directory to: ${ANSIBLE_DIRECTORY}"
|
||||
fi
|
||||
|
||||
###############################
|
||||
# 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 "Runner: $(id -un 2>/dev/null)"
|
||||
debug "ENV:"
|
||||
debug "${PRINTENV}"
|
||||
debug "---------------------------------------------"
|
||||
debug "$(printenv | sort)"
|
||||
}
|
||||
|
||||
function CheckIfGitBranchExists() {
|
||||
|
@ -220,6 +157,20 @@ function CheckIfGitBranchExists() {
|
|||
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() {
|
||||
debug "Check if ${GITHUB_WORKSPACE} is a Git repository"
|
||||
if ! git -C "${GITHUB_WORKSPACE}" rev-parse --git-dir; then
|
||||
|
|
|
@ -91,9 +91,10 @@ function LintCodebase() {
|
|||
for FILE in "${LIST_FILES[@]}"; do
|
||||
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
|
||||
INDIVIDUAL_TEST_FOLDER="${FILE_TYPE,,}"
|
||||
INDIVIDUAL_TEST_FOLDER="${FILE_TYPE}"
|
||||
debug "INDIVIDUAL_TEST_FOLDER for ${FILE}: ${INDIVIDUAL_TEST_FOLDER}"
|
||||
|
||||
local TEST_CASE_DIRECTORY
|
||||
|
|
187
lib/linter.sh
187
lib/linter.sh
|
@ -4,7 +4,8 @@
|
|||
# Debug Vars #
|
||||
# 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
|
||||
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)
|
||||
|
||||
##################################################################
|
||||
|
@ -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_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE)
|
||||
declare -l CREATE_LOG_FILE
|
||||
CREATE_LOG_FILE="${CREATE_LOG_FILE:-"false"}"
|
||||
export CREATE_LOG_FILE
|
||||
|
||||
if [[ ${ACTIONS_RUNNER_DEBUG} == true ]]; then LOG_LEVEL="DEBUG"; fi
|
||||
# Boolean to see trace logs
|
||||
|
@ -60,15 +61,10 @@ source /action/lib/functions/setupSSH.sh # Source the function script(s)
|
|||
# shellcheck source=/dev/null
|
||||
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
|
||||
DEFAULT_RUN_LOCAL='false'
|
||||
|
||||
if [ -z "${RUN_LOCAL}" ]; then
|
||||
RUN_LOCAL="${DEFAULT_RUN_LOCAL}"
|
||||
fi
|
||||
|
||||
# Convert string to lowercase
|
||||
RUN_LOCAL="${RUN_LOCAL,,}"
|
||||
RUN_LOCAL="${RUN_LOCAL:-"false"}"
|
||||
|
||||
# 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
|
||||
|
@ -84,37 +80,85 @@ ENABLE_GITHUB_ACTIONS_GROUP_TITLE="${ENABLE_GITHUB_ACTIONS_GROUP_TITLE:-"${DEFAU
|
|||
|
||||
startGitHubActionsLogGroup "${SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE}"
|
||||
|
||||
debug "RUN_LOCAL: ${RUN_LOCAL}"
|
||||
debug "ENABLE_GITHUB_ACTIONS_GROUP_TITLE: ${ENABLE_GITHUB_ACTIONS_GROUP_TITLE}"
|
||||
# We want a lowercase value
|
||||
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 #
|
||||
###########
|
||||
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
|
||||
if [ -n "$GITHUB_CUSTOM_API_URL" ]; then
|
||||
GITHUB_API_URL="${GITHUB_CUSTOM_API_URL}"
|
||||
elif [ -z "$GITHUB_API_URL" ]; then
|
||||
GITHUB_API_URL="https://api.github.com"
|
||||
fi
|
||||
GITHUB_API_URL="${GITHUB_CUSTOM_API_URL:-"https://api.github.com"}"
|
||||
# Remove trailing slash if present
|
||||
GITHUB_API_URL="${GITHUB_API_URL%/}"
|
||||
|
||||
# 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
|
||||
GITHUB_SERVER_URL="${GITHUB_DOMAIN:-"https://github.com"}"
|
||||
# Extract domain name from URL
|
||||
GITHUB_SERVER_URL=$(echo "$GITHUB_SERVER_URL" | cut -d '/' -f 3)
|
||||
|
||||
# Default Vars
|
||||
DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location
|
||||
LINTED_LANGUAGES_ARRAY=() # Will be filled at run time with all languages that were linted
|
||||
LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter rules directory
|
||||
# shellcheck disable=SC2034 # Variable is referenced in other scripts
|
||||
RAW_FILE_ARRAY=() # Array of all files that were changed
|
||||
# shellcheck disable=SC2034 # Variable is referenced in other scripts
|
||||
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
|
||||
export VERSION_FILE # Workaround SC2034
|
||||
|
||||
debug "CREATE_LOG_FILE: ${CREATE_LOG_FILE}"
|
||||
|
||||
# Set the log level
|
||||
TF_LOG_LEVEL="info"
|
||||
|
@ -215,15 +259,6 @@ SCALAFMT_FILE_NAME="${SCALAFMT_CONFIG_FILE:-.scalafmt.conf}"
|
|||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SNAKEMAKE_SNAKEFMT_FILE_NAME="${SNAKEMAKE_SNAKEFMT_CONFIG_FILE:-.snakefmt.toml}"
|
||||
# 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}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SQLFLUFF_FILE_NAME="${SQLFLUFF_CONFIG_FILE:-/.sqlfluff}"
|
||||
|
@ -241,14 +276,8 @@ TYPESCRIPT_STYLE_NAME='' # Variable for the style
|
|||
TYPESCRIPT_STYLE='' # Variable for the style
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
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
|
||||
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 #
|
||||
|
@ -383,50 +412,6 @@ LINTER_NAMES_ARRAY["${TYPESCRIPT_STYLE_NAME}"]="${TYPESCRIPT_STYLE}"
|
|||
LINTER_NAMES_ARRAY['XML']="xmllint"
|
||||
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 #
|
||||
##########################
|
||||
|
@ -462,6 +447,13 @@ Header() {
|
|||
info "The Super-Linter source code can be found at:"
|
||||
info " - https://github.com/super-linter/super-linter"
|
||||
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() {
|
||||
|
@ -491,16 +483,10 @@ GetGitHubVars() {
|
|||
GITHUB_WORKSPACE="${DEFAULT_WORKSPACE}"
|
||||
fi
|
||||
|
||||
if [ ! -d "${GITHUB_WORKSPACE}" ]; then
|
||||
fatal "The workspace (${GITHUB_WORKSPACE}) is not a directory!"
|
||||
fi
|
||||
ValidateGitHubWorkspace "${GITHUB_WORKSPACE}"
|
||||
|
||||
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
|
||||
ConfigureGitSafeDirectories
|
||||
debug "Initializing GITHUB_SHA considering ${GITHUB_WORKSPACE}"
|
||||
|
@ -518,11 +504,7 @@ GetGitHubVars() {
|
|||
MULTI_STATUS="false"
|
||||
debug "Setting MULTI_STATUS to ${MULTI_STATUS} because we are not running on GitHub Actions"
|
||||
else
|
||||
if [ -z "${GITHUB_WORKSPACE}" ]; then
|
||||
fatal "Failed to get GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
|
||||
else
|
||||
info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]"
|
||||
fi
|
||||
ValidateGitHubWorkspace "${GITHUB_WORKSPACE}"
|
||||
|
||||
# Ensure that Git can access the local repository
|
||||
ConfigureGitSafeDirectories
|
||||
|
@ -1083,9 +1065,8 @@ EDITORCONFIG_FILE_PATH="${GITHUB_WORKSPACE}"/.editorconfig
|
|||
####################################
|
||||
debug "--- ENV (before running linters) ---"
|
||||
debug "------------------------------------"
|
||||
PRINTENV=$(printenv | sort)
|
||||
debug "ENV:"
|
||||
debug "${PRINTENV}"
|
||||
debug "$(printenv | sort)"
|
||||
debug "------------------------------------"
|
||||
|
||||
endGitHubActionsLogGroup "${SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE}"
|
||||
|
|
Loading…
Reference in a new issue