2020-06-29 10:55:59 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
########### Super-Linter Validation Functions @admiralawkbar ###################
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
########################## FUNCTION CALLS BELOW ################################
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
#### Function GetValidationInfo ################################################
|
2020-07-01 17:40:40 -04:00
|
|
|
function GetValidationInfo() {
|
2020-07-30 16:39:05 -04:00
|
|
|
############################################
|
|
|
|
# Print headers for user provided env vars #
|
|
|
|
############################################
|
|
|
|
info "--------------------------------------------"
|
|
|
|
info "Gathering user validation information..."
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Skip validation if were running locally #
|
|
|
|
###########################################
|
|
|
|
if [[ ${RUN_LOCAL} != "true" ]]; then
|
2020-07-30 16:18:24 -04:00
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
2020-07-30 16:39:05 -04:00
|
|
|
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
|
|
|
|
# Its false
|
|
|
|
info "- Only validating [new], or [edited] files in code base..."
|
2020-07-04 18:14:27 -04:00
|
|
|
fi
|
2020-07-30 16:39:05 -04:00
|
|
|
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"
|
2020-08-11 22:05:01 -04:00
|
|
|
ANY_TRUE="false"
|
|
|
|
ANY_FALSE="false"
|
2020-07-30 16:39:05 -04:00
|
|
|
# Loop through all languages
|
|
|
|
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
|
|
|
# build the variable
|
|
|
|
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
|
|
|
|
# Check to see if the variable was set
|
|
|
|
if [ -n "${!VALIDATE_LANGUAGE}" ]; then
|
|
|
|
# It was set, need to set flag
|
|
|
|
ANY_SET="true"
|
2020-08-11 22:05:01 -04:00
|
|
|
if [ "${!VALIDATE_LANGUAGE}" == "true" ]; then
|
|
|
|
ANY_TRUE="true"
|
|
|
|
elif [ "${!VALIDATE_LANGUAGE}" == "false" ]; then
|
|
|
|
ANY_FALSE="true"
|
|
|
|
fi
|
2020-07-22 15:26:45 -04:00
|
|
|
fi
|
2020-07-30 16:39:05 -04:00
|
|
|
done
|
|
|
|
|
2020-08-11 22:05:01 -04:00
|
|
|
if [ $ANY_TRUE == "true" ] && [ $ANY_FALSE == "true" ]; then
|
|
|
|
fatal "Behavior not supported, please either only include (VALIDATE=true) or exclude (VALIDATE=false) linters, but not both"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#########################################################
|
|
|
|
# Validate if we should check/omit individual languages #
|
|
|
|
#########################################################
|
2020-07-30 16:39:05 -04:00
|
|
|
# Loop through all languages
|
|
|
|
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
|
|
|
# build the variable
|
|
|
|
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
|
2020-08-11 22:05:01 -04:00
|
|
|
# Flag was not set, default to:
|
|
|
|
# if ANY_TRUE then set to false
|
|
|
|
# if ANY_FALSE then set to true
|
|
|
|
eval "${VALIDATE_LANGUAGE}='$ANY_FALSE'"
|
2020-07-30 16:39:05 -04:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
# No linter flags were set - default all to true
|
|
|
|
eval "${VALIDATE_LANGUAGE}='true'"
|
2020-06-29 10:55:59 -04:00
|
|
|
fi
|
2020-10-02 17:02:47 -04:00
|
|
|
eval "export ${VALIDATE_LANGUAGE}"
|
2020-07-30 16:39:05 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Print which linters we are enabling #
|
|
|
|
#######################################
|
|
|
|
# Loop through all languages
|
|
|
|
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
|
|
|
# build the variable
|
|
|
|
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
|
|
|
|
if [[ ${!VALIDATE_LANGUAGE} == "true" ]]; then
|
|
|
|
# We need to validate
|
2020-09-28 16:29:48 -04:00
|
|
|
PRINT_ARRAY+=("- Validating [${LANGUAGE}] files in code base...")
|
|
|
|
|
|
|
|
debug "Defining variables for ${LANGUAGE} linter..."
|
|
|
|
|
|
|
|
ERRORS_VARIABLE_NAME="ERRORS_FOUND_${LANGUAGE}"
|
|
|
|
debug "Setting ${ERRORS_VARIABLE_NAME} variable value to 0..."
|
|
|
|
eval "${ERRORS_VARIABLE_NAME}=0"
|
|
|
|
debug "Exporting ${ERRORS_VARIABLE_NAME} variable..."
|
|
|
|
eval "export ${ERRORS_VARIABLE_NAME}"
|
2020-07-30 16:39:05 -04:00
|
|
|
else
|
|
|
|
# We are skipping the language
|
|
|
|
PRINT_ARRAY+=("- Excluding [$LANGUAGE] files in code base...")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Validate Ansible Directory #
|
|
|
|
##############################
|
|
|
|
if [ -z "${ANSIBLE_DIRECTORY}" ]; then
|
|
|
|
# No Value, need to default
|
|
|
|
ANSIBLE_DIRECTORY="${DEFAULT_ANSIBLE_DIRECTORY}"
|
2020-09-21 18:53:30 -04:00
|
|
|
debug "Setting Ansible directory to the default: ${DEFAULT_ANSIBLE_DIRECTORY}"
|
2020-07-30 16:39:05 -04:00
|
|
|
else
|
|
|
|
# Check if first char is '/'
|
|
|
|
if [[ ${ANSIBLE_DIRECTORY:0:1} == "/" ]]; then
|
|
|
|
# Remove first char
|
|
|
|
ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY:1}"
|
|
|
|
fi
|
|
|
|
# Need to give it full path
|
|
|
|
TEMP_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/${ANSIBLE_DIRECTORY}"
|
|
|
|
# Set the value
|
|
|
|
ANSIBLE_DIRECTORY="${TEMP_ANSIBLE_DIRECTORY}"
|
2020-09-21 18:53:30 -04:00
|
|
|
debug "Setting Ansible directory to: ${ANSIBLE_DIRECTORY}"
|
|
|
|
fi
|
|
|
|
|
2020-07-30 16:39:05 -04:00
|
|
|
###############################
|
|
|
|
# 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=$(whoami)
|
|
|
|
debug "Runner:[${RUNNER}]"
|
2020-09-25 18:51:53 -04:00
|
|
|
PRINTENV=$(printenv | sort)
|
2020-07-30 16:39:05 -04:00
|
|
|
debug "ENV:"
|
|
|
|
debug "${PRINTENV}"
|
|
|
|
debug "---------------------------------------------"
|
2020-06-29 10:55:59 -04:00
|
|
|
}
|
2020-10-08 18:54:28 -04:00
|
|
|
################################################################################
|
|
|
|
#### Function ValidatePowershellModules ########################################
|
|
|
|
function ValidatePowershellModules() {
|
|
|
|
VALIDATE_PSSA_MODULE=$(pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>&1)
|
2020-10-30 15:16:21 -04:00
|
|
|
VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1)
|
2020-10-08 18:54:28 -04:00
|
|
|
# If module found, ensure Invoke-ScriptAnalyzer command is available
|
2020-10-30 15:16:21 -04:00
|
|
|
if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]] && [[ ${VALIDATE_PSSA_CMD} == "Invoke-ScriptAnalyzer" ]]; then
|
2020-10-08 18:54:28 -04:00
|
|
|
# Success
|
|
|
|
debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system"
|
|
|
|
debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system"
|
2020-10-30 15:16:21 -04:00
|
|
|
else
|
|
|
|
# Failed
|
|
|
|
error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!"
|
|
|
|
fatal "[PSSA_MODULE: ${VALIDATE_PSSA_MODULE}] [PSSA_CMD: ${VALIDATE_PSSA_CMD}]"
|
2020-10-08 18:54:28 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
################################################################################
|