2019-10-23 11:42:28 -04:00
|
|
|
#!/bin/bash
|
2019-10-21 10:12:50 -04:00
|
|
|
|
|
|
|
################################################################################
|
2020-02-03 11:27:40 -05:00
|
|
|
################################################################################
|
|
|
|
########### Super-Linter (Lint all the code) @AdmiralAwkbar ####################
|
|
|
|
################################################################################
|
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
|
2019-10-23 10:51:13 -04:00
|
|
|
DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location
|
2020-04-23 13:10:49 -04:00
|
|
|
LINTER_PATH='.github/linters' # Default linter path
|
2019-10-21 15:12:37 -04:00
|
|
|
# YAML Vars
|
2019-10-23 10:51:13 -04:00
|
|
|
YAML_FILE_NAME='.yaml-lint.yml' # Name of the file
|
|
|
|
YAML_LINTER_RULES="$DEFAULT_RULES_LOCATION/$YAML_FILE_NAME" # Path to the yaml lint rules
|
2019-10-21 15:12:37 -04:00
|
|
|
# MD Vars
|
2019-10-23 10:51:13 -04:00
|
|
|
MD_FILE_NAME='.markdown-lint.yml' # Name of the file
|
|
|
|
MD_LINTER_RULES="$DEFAULT_RULES_LOCATION/$MD_FILE_NAME" # Path to the markdown lint rules
|
2019-10-21 15:12:37 -04:00
|
|
|
# Python Vars
|
2019-10-23 10:51:13 -04:00
|
|
|
PYTHON_FILE_NAME='.python-lint' # Name of the file
|
|
|
|
PYTHON_LINTER_RULES="$DEFAULT_RULES_LOCATION/$PYTHON_FILE_NAME" # Path to the python lint rules
|
2019-10-21 15:12:37 -04:00
|
|
|
# Ruby Vars
|
2019-10-23 10:51:13 -04:00
|
|
|
RUBY_FILE_NAME='.ruby-lint.yml' # Name of the file
|
|
|
|
RUBY_LINTER_RULES="$DEFAULT_RULES_LOCATION/$RUBY_FILE_NAME" # Path to the ruby lint rules
|
2019-10-21 15:12:37 -04:00
|
|
|
# Coffee Vars
|
2020-02-04 13:20:22 -05:00
|
|
|
COFFEE_FILE_NAME='.coffee-lint.json' # Name of the file
|
|
|
|
COFFEESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$COFFEE_FILE_NAME" # Path to the coffescript lint rules
|
2019-11-06 16:45:44 -05:00
|
|
|
# Javascript Vars
|
2019-11-07 09:27:22 -05:00
|
|
|
JAVASCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file
|
2019-11-06 16:45:44 -05:00
|
|
|
JAVASCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$JAVASCRIPT_FILE_NAME" # Path to the Javascript lint rules
|
2020-04-02 13:42:07 -04:00
|
|
|
JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
|
|
|
|
# Typecript Vars
|
|
|
|
TYPESCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file
|
|
|
|
TYPESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TYPESCRIPT_FILE_NAME" # Path to the Typescript lint rules
|
|
|
|
TYPESCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
|
2019-10-22 13:21:42 -04:00
|
|
|
# Ansible Vars
|
2019-10-23 10:51:13 -04:00
|
|
|
ANSIBLE_FILE_NAME='.ansible-lint.yml' # Name of the file
|
2020-01-10 14:33:28 -05:00
|
|
|
ANSIBLE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$ANSIBLE_FILE_NAME" # Path to the Ansible lint rules
|
|
|
|
# Docker Vars
|
|
|
|
DOCKER_FILE_NAME='.dockerfilelintrc' # Name of the file
|
|
|
|
DOCKER_LINTER_RULES="$DEFAULT_RULES_LOCATION/$DOCKER_FILE_NAME" # Path to the Docker lint rules
|
2020-02-28 10:51:29 -05:00
|
|
|
# Golang Vars
|
|
|
|
GO_FILE_NAME='.golangci.yml' # Name of the file
|
2020-03-11 15:18:21 -04:00
|
|
|
GO_LINTER_RULES="$DEFAULT_RULES_LOCATION/$GO_FILE_NAME" # Path to the Go lint rules
|
|
|
|
# Terraform Vars
|
|
|
|
TERRAFORM_FILE_NAME='.tflint.hcl' # Name of the file
|
|
|
|
TERRAFORM_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TERRAFORM_FILE_NAME" # Path to the Terraform lint rules
|
2019-10-21 15:12:37 -04:00
|
|
|
|
2020-01-08 14:34:05 -05:00
|
|
|
#######################################
|
|
|
|
# Linter array for information prints #
|
|
|
|
#######################################
|
|
|
|
LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
2020-02-03 11:27:40 -05:00
|
|
|
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
|
2020-03-11 15:18:21 -04:00
|
|
|
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint")
|
2020-01-08 14:34:05 -05:00
|
|
|
|
2019-10-21 15:12:37 -04:00
|
|
|
###################
|
|
|
|
# GitHub ENV Vars #
|
|
|
|
###################
|
2020-04-02 13:42:07 -04:00
|
|
|
GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit
|
|
|
|
GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path
|
|
|
|
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace
|
|
|
|
ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory
|
|
|
|
VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files
|
|
|
|
VALIDATE_YAML="${VALIDATE_YAML}" # Boolean to validate language
|
|
|
|
VALIDATE_JSON="${VALIDATE_JSON}" # Boolean to validate language
|
|
|
|
VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate language
|
|
|
|
VALIDATE_MD="${VALIDATE_MD}" # Boolean to validate language
|
|
|
|
VALIDATE_BASH="${VALIDATE_BASH}" # Boolean to validate language
|
|
|
|
VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language
|
|
|
|
VALIDATE_PYTHON="${VALIDATE_PYTHON}" # Boolean to validate language
|
|
|
|
VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language
|
|
|
|
VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language
|
|
|
|
VALIDATE_ANSIBLE="${VALIDATE_ANSIBLE}" # Boolean to validate language
|
|
|
|
VALIDATE_JAVASCRIPT_ES="${VALIDATE_JAVASCRIPT_ES}" # Boolean to validate language
|
|
|
|
VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to validate language
|
|
|
|
VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to validate language
|
|
|
|
VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to validate language
|
|
|
|
VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language
|
|
|
|
VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language
|
|
|
|
VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language
|
|
|
|
TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases
|
2020-02-03 15:54:43 -05:00
|
|
|
|
|
|
|
##############
|
|
|
|
# Debug Vars #
|
|
|
|
##############
|
2020-04-27 13:21:38 -04:00
|
|
|
RUN_LOCAL="${RUN_LOCAL}" # Boolean to see if we are running locally
|
|
|
|
ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG}" # Boolean to see even more info (debug)
|
2019-10-25 12:29:31 -04:00
|
|
|
|
|
|
|
################
|
|
|
|
# Default Vars #
|
|
|
|
################
|
2019-12-03 14:47:23 -05:00
|
|
|
DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files
|
|
|
|
DEFAULT_VALIDATE_LANGUAGE='true' # Default to validate language
|
2020-01-09 11:29:18 -05:00
|
|
|
DEFAULT_WORKSPACE='/tmp/lint' # Default workspace if running locally
|
2019-12-03 14:47:23 -05:00
|
|
|
DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory
|
2020-02-03 11:27:40 -05:00
|
|
|
DEFAULT_RUN_LOCAL='false' # Default value for debugging locally
|
2020-02-04 12:49:07 -05:00
|
|
|
DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases
|
2020-04-27 13:21:38 -04:00
|
|
|
DEFAULT_ACTIONS_RUNNER_DEBUG='false' # Default value for debugging output
|
2019-12-03 14:47:23 -05:00
|
|
|
RAW_FILE_ARRAY=() # Array of all files that were changed
|
2020-02-03 11:27:40 -05:00
|
|
|
READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md
|
2020-02-04 09:49:58 -05:00
|
|
|
TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2020-02-04 12:49:07 -05:00
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Array of changed files #
|
|
|
|
##########################
|
2020-04-02 13:42:07 -04:00
|
|
|
FILE_ARRAY_YML=() # Array of files to check
|
|
|
|
FILE_ARRAY_JSON=() # Array of files to check
|
|
|
|
FILE_ARRAY_XML=() # Array of files to check
|
|
|
|
FILE_ARRAY_MD=() # Array of files to check
|
|
|
|
FILE_ARRAY_BASH=() # Array of files to check
|
|
|
|
FILE_ARRAY_PERL=() # Array of files to check
|
|
|
|
FILE_ARRAY_RUBY=() # Array of files to check
|
|
|
|
FILE_ARRAY_PYTHON=() # Array of files to check
|
|
|
|
FILE_ARRAY_COFFEESCRIPT=() # Array of files to check
|
|
|
|
FILE_ARRAY_JAVASCRIPT_ES=() # Array of files to check
|
|
|
|
FILE_ARRAY_JAVASCRIPT_STANDARD=() # Array of files to check
|
|
|
|
FILE_ARRAY_TYPESCRIPT_ES=() # Array of files to check
|
|
|
|
FILE_ARRAY_TYPESCRIPT_STANDARD=() # Array of files to check
|
|
|
|
FILE_ARRAY_DOCKER=() # Array of files to check
|
|
|
|
FILE_ARRAY_GO=() # Array of files to check
|
|
|
|
FILE_ARRAY_TERRAFORM=() # Array of files to check
|
2019-10-25 15:22:57 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
############
|
|
|
|
# Counters #
|
|
|
|
############
|
2020-04-02 13:42:07 -04:00
|
|
|
ERRORS_FOUND_YML=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_JSON=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_XML=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_MARKDOWN=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_BASH=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_PERL=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_RUBY=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_PYTHON=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_COFFEESCRIPT=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_ANSIBLE=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_JAVASCRIPT_STANDARD=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_JAVASCRIPT_ES=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_TYPESCRIPT_STANDARD=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_TYPESCRIPT_ES=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_DOCKER=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_GO=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_TERRAFORM=0 # Count of errors found
|
2019-10-21 15:12:37 -04:00
|
|
|
|
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 ###########################################################
|
|
|
|
Header()
|
2019-10-21 10:12:50 -04:00
|
|
|
{
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
|
|
|
echo "---------------------------------------------"
|
2020-02-03 11:27:40 -05:00
|
|
|
echo "--- Github Actions Multi Language Linter ----"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "---------------------------------------------"
|
|
|
|
echo ""
|
2020-01-08 14:34:05 -05:00
|
|
|
echo "---------------------------------------------"
|
|
|
|
echo "The Super-Linter source code can be found at:"
|
|
|
|
echo " - https://github.com/github/super-linter"
|
|
|
|
echo "---------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2020-01-08 14:34:05 -05:00
|
|
|
#### Function GetLinterVersions ################################################
|
|
|
|
GetLinterVersions()
|
|
|
|
{
|
|
|
|
#########################
|
|
|
|
# Print version headers #
|
|
|
|
#########################
|
|
|
|
echo ""
|
|
|
|
echo "---------------------------------------------"
|
|
|
|
echo "Linter Version Info:"
|
|
|
|
echo "---------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
##########################################################
|
|
|
|
# Go through the array of linters and print version info #
|
|
|
|
##########################################################
|
|
|
|
for LINTER in "${LINTER_ARRAY[@]}"
|
|
|
|
do
|
|
|
|
echo "---------------------------------------------"
|
|
|
|
echo "[$LINTER]:"
|
|
|
|
###################
|
|
|
|
# Get the version #
|
|
|
|
###################
|
2020-01-08 14:37:02 -05:00
|
|
|
# shellcheck disable=SC2207
|
2020-01-08 14:34:05 -05:00
|
|
|
GET_VERSION_CMD=($("$LINTER" --version 2>&1))
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2020-01-31 18:00:28 -05:00
|
|
|
if [ $ERROR_CODE -ne 0 ] | [ -z "${GET_VERSION_CMD[*]}" ]; then
|
2020-01-08 14:34:05 -05:00
|
|
|
echo "WARN! Failed to get version info for:[$LINTER]"
|
|
|
|
echo "---------------------------------------------"
|
|
|
|
else
|
|
|
|
##########################
|
|
|
|
# Print the version info #
|
|
|
|
##########################
|
2020-01-08 14:37:02 -05:00
|
|
|
echo "${GET_VERSION_CMD[*]}"
|
2020-01-08 14:34:05 -05:00
|
|
|
echo "---------------------------------------------"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 12:05:55 -04:00
|
|
|
#### Function GetLinterRules ###################################################
|
|
|
|
GetLinterRules()
|
|
|
|
{
|
|
|
|
# Need to validate the rules files exist
|
2020-02-03 11:27:40 -05:00
|
|
|
|
|
|
|
################
|
|
|
|
# Pull in vars #
|
|
|
|
################
|
|
|
|
FILE_NAME="$1" # Name fo the linter file
|
|
|
|
FILE_LOCATION="$2" # Location of the linter file
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have the linter rules #
|
|
|
|
#####################################
|
2020-04-23 13:10:49 -04:00
|
|
|
if [ -f "$GITHUB_WORKSPACE/$LINTER_PATH/$FILE_NAME" ]; then
|
2020-04-27 13:21:38 -04:00
|
|
|
echo "----------------------------------------------"
|
2020-02-03 11:27:40 -05:00
|
|
|
echo "User provided file:[$FILE_NAME], setting rules file..."
|
2019-10-22 13:21:42 -04:00
|
|
|
|
|
|
|
####################################
|
2020-02-03 11:27:40 -05:00
|
|
|
# Copy users into default location #
|
2019-10-22 13:21:42 -04:00
|
|
|
####################################
|
2020-04-23 13:10:49 -04:00
|
|
|
CP_CMD=$(cp "$GITHUB_WORKSPACE/$LINTER_PATH/$FILE_NAME" "$FILE_LOCATION" 2>&1)
|
2019-10-22 13:21:42 -04:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Load Error code #
|
|
|
|
###################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
echo "ERROR! Failed to set file:[$FILE_NAME] as default!"
|
|
|
|
echo "ERROR:[$CP_CMD]"
|
2019-10-22 13:21:42 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-23 10:51:13 -04:00
|
|
|
else
|
2020-02-03 11:27:40 -05:00
|
|
|
########################################################
|
|
|
|
# No user default provided, using the template default #
|
|
|
|
########################################################
|
2020-04-27 13:21:38 -04:00
|
|
|
if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then
|
|
|
|
echo " -> Codebase does NOT have file:[$LINTER_PATH/$FILE_NAME], using Default rules at:[$FILE_LOCATION]"
|
|
|
|
fi
|
2019-10-22 13:21:42 -04:00
|
|
|
fi
|
2020-02-03 11:27:40 -05:00
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function GetStandardRules #################################################
|
|
|
|
GetStandardRules()
|
|
|
|
{
|
2020-04-02 13:42:07 -04:00
|
|
|
################
|
|
|
|
# Pull In Vars #
|
|
|
|
################
|
|
|
|
LINTER="$1" # Type: javascript | typescript
|
|
|
|
|
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
|
|
|
|
ORIG_IFS="$IFS"
|
|
|
|
# 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=()
|
|
|
|
if [[ "$LINTER" == "javascript" ]]; then
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
GET_ENV_ARRAY=($(yq .env "$JAVASCRIPT_LINTER_RULES" |grep true))
|
|
|
|
elif [[ "$LINTER" == "typescript" ]]; then
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
GET_ENV_ARRAY=($(yq .env "$TYPESCRIPT_LINTER_RULES" |grep true))
|
|
|
|
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 #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
# ERROR
|
|
|
|
echo "ERROR! Failed to gain list of ENV vars to load!"
|
|
|
|
echo "ERROR:[${GET_ENV_ARRAY[*]}]"
|
|
|
|
exit 1
|
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
|
|
|
|
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 #
|
|
|
|
#############################
|
|
|
|
for ENV in "${GET_ENV_ARRAY[@]}"
|
|
|
|
do
|
|
|
|
#############################
|
|
|
|
# remove spaces from return #
|
|
|
|
#############################
|
|
|
|
ENV="$(echo -e "${ENV}" | tr -d '[:space:]')"
|
|
|
|
################################
|
|
|
|
# Get the env to add to string #
|
|
|
|
################################
|
|
|
|
ENV="$(echo "${ENV}" | cut -d'"' -f2)"
|
|
|
|
# echo "ENV:[$ENV]"
|
|
|
|
ENV_STRING+="--env ${ENV} "
|
|
|
|
done
|
2020-01-10 14:33:28 -05:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
########################################
|
|
|
|
# Remove trailing and ending witespace #
|
|
|
|
########################################
|
2020-04-02 13:42:07 -04:00
|
|
|
if [[ "$LINTER" == "javascript" ]]; then
|
|
|
|
JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
|
|
|
elif [[ "$LINTER" == "typescript" ]]; then
|
|
|
|
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-02-03 11:27:40 -05:00
|
|
|
#### Function LintAnsibleFiles #################################################
|
|
|
|
LintAnsibleFiles()
|
2019-10-21 12:05:55 -04:00
|
|
|
{
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2020-02-03 15:54:43 -05:00
|
|
|
echo "Linting [Ansible] files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
2020-02-03 11:27:40 -05:00
|
|
|
LINTER_NAME="ansible-lint"
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
###########################################
|
|
|
|
# Validate we have ansible-lint installed #
|
|
|
|
###########################################
|
2019-10-21 12:05:55 -04:00
|
|
|
# shellcheck disable=SC2230
|
2019-10-23 11:16:17 -04:00
|
|
|
VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1)
|
2019-10-21 10:12:50 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2019-10-21 12:05:55 -04:00
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
# Failed
|
2020-02-03 11:27:40 -05:00
|
|
|
echo "ERROR! Failed to find $LINTER_NAME in system!"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "ERROR:[$VALIDATE_INSTALL_CMD]"
|
|
|
|
exit 1
|
2019-10-21 10:12:50 -04:00
|
|
|
else
|
2019-10-21 12:05:55 -04:00
|
|
|
# Success
|
2020-04-27 13:21:38 -04:00
|
|
|
if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then
|
2020-04-23 13:07:35 -04:00
|
|
|
# Success
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
|
|
|
fi
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
######################################################
|
|
|
|
# Only go into ansible linter if we have base folder #
|
|
|
|
######################################################
|
|
|
|
if [ -d "$ANSIBLE_DIRECTORY" ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
|
|
|
if [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# We need to only check the ansible playbooks that have updates
|
|
|
|
#LIST_FILES=("${ANSIBLE_ARRAY[@]}")
|
|
|
|
# shellcheck disable=SC2164,SC2010,SC2207
|
|
|
|
LIST_FILES=($(cd "$ANSIBLE_DIRECTORY"; ls | grep ".yml" 2>&1))
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2164,SC2010,SC2207
|
|
|
|
LIST_FILES=($(cd "$ANSIBLE_DIRECTORY"; ls | grep ".yml" 2>&1))
|
2019-12-03 14:47:23 -05:00
|
|
|
fi
|
2019-10-25 15:22:57 -04:00
|
|
|
|
2020-01-07 15:38:05 -05:00
|
|
|
###############################################################
|
|
|
|
# Set the list to empty if only MD and TXT files were changed #
|
|
|
|
###############################################################
|
|
|
|
# No need to run the full ansible checks on read only file changes
|
2020-01-07 15:41:12 -05:00
|
|
|
if [ "$READ_ONLY_CHANGE_FLAG" -eq 0 ]; then
|
2020-01-07 15:46:57 -05:00
|
|
|
##########################
|
|
|
|
# Set the array to empty #
|
|
|
|
##########################
|
2020-01-07 15:38:05 -05:00
|
|
|
LIST_FILES=()
|
2020-01-07 15:46:57 -05:00
|
|
|
###################################
|
|
|
|
# Send message that were skipping #
|
|
|
|
###################################
|
|
|
|
echo "- Skipping Ansible lint run as file(s) that were modified were read only..."
|
2020-01-07 15:38:05 -05:00
|
|
|
fi
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
2020-02-03 11:27:40 -05:00
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
2020-01-09 17:08:01 -05:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
########################################
|
|
|
|
# Make sure we dont lint certain files #
|
|
|
|
########################################
|
|
|
|
if [[ $FILE == *"vault.yml"* ]] || [[ $FILE == *"galaxy.yml"* ]]; then
|
|
|
|
# This is a file we dont look at
|
|
|
|
continue
|
|
|
|
fi
|
2020-01-09 17:08:01 -05:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
####################
|
|
|
|
# Get the filename #
|
|
|
|
####################
|
|
|
|
FILE_NAME=$(basename "$ANSIBLE_DIRECTORY/$FILE" 2>&1)
|
2020-01-09 17:08:01 -05:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
2020-01-09 17:08:01 -05:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
|
|
|
LINT_CMD=$("$LINTER_NAME" -v -c "$ANSIBLE_LINTER_RULES" "$ANSIBLE_DIRECTORY/$FILE" 2>&1)
|
2020-01-09 17:08:01 -05:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
#########
|
|
|
|
# Error #
|
|
|
|
#########
|
|
|
|
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
|
|
|
|
echo "ERROR:[$LINT_CMD]"
|
|
|
|
# Increment error count
|
|
|
|
((ERRORS_FOUND_ANSIBLE++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
########################
|
|
|
|
# No Ansible dir found #
|
|
|
|
########################
|
|
|
|
echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIRECTORY]"
|
|
|
|
echo "skipping ansible lint"
|
|
|
|
fi
|
2020-01-09 17:08:01 -05:00
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 15:12:37 -04:00
|
|
|
#### Function GetGitHubVars ####################################################
|
|
|
|
GetGitHubVars()
|
|
|
|
{
|
|
|
|
##########
|
|
|
|
# Prints #
|
|
|
|
##########
|
|
|
|
echo "--------------------------------------------"
|
|
|
|
echo "Gathering GitHub information..."
|
|
|
|
|
2020-02-04 12:49:07 -05:00
|
|
|
###############################
|
|
|
|
# Get the Run test cases flag #
|
|
|
|
###############################
|
|
|
|
if [ -z "$TEST_CASE_RUN" ]; then
|
|
|
|
##################################
|
|
|
|
# No flag passed, set to default #
|
|
|
|
##################################
|
|
|
|
TEST_CASE_RUN="$DEFAULT_TEST_CASE_RUN"
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
TEST_CASE_RUN=$(echo "$TEST_CASE_RUN" | awk '{print tolower($0)}')
|
|
|
|
|
2020-01-09 11:29:18 -05:00
|
|
|
##########################
|
|
|
|
# Get the run local flag #
|
|
|
|
##########################
|
|
|
|
if [ -z "$RUN_LOCAL" ]; then
|
|
|
|
##################################
|
|
|
|
# No flag passed, set to default #
|
|
|
|
##################################
|
|
|
|
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 #
|
|
|
|
###############################
|
|
|
|
RUN_LOCAL=$(echo "$RUN_LOCAL" | awk '{print tolower($0)}')
|
2020-02-04 12:49:07 -05:00
|
|
|
|
2020-01-09 11:29:18 -05:00
|
|
|
#################################
|
|
|
|
# Check if were running locally #
|
|
|
|
#################################
|
|
|
|
if [[ "$RUN_LOCAL" != "false" ]]; then
|
|
|
|
##########################################
|
|
|
|
# We are running locally for a debug run #
|
|
|
|
##########################################
|
|
|
|
echo "NOTE: ENV VAR [RUN_LOCAL] has been set to:[true]"
|
|
|
|
echo "bypassing GitHub Actions variables..."
|
|
|
|
echo "Linting all files in mapped directory:[$DEFAULT_WORKSPACE]"
|
|
|
|
|
|
|
|
# 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 GITHUB_WORKSPACE #
|
|
|
|
############################
|
|
|
|
GITHUB_WORKSPACE="$DEFAULT_WORKSPACE"
|
2019-10-21 15:12:37 -04:00
|
|
|
|
2020-01-09 11:29:18 -05:00
|
|
|
#################################
|
|
|
|
# Set the VALIDATE_ALL_CODEBASE #
|
|
|
|
#################################
|
|
|
|
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 #
|
|
|
|
############################
|
|
|
|
if [ -z "$GITHUB_SHA" ]; then
|
|
|
|
echo "ERROR! Failed to get [GITHUB_SHA]!"
|
|
|
|
echo "ERROR:[$GITHUB_SHA]"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Successfully found:[GITHUB_SHA], value:[$GITHUB_SHA]"
|
|
|
|
fi
|
2019-10-21 15:12:37 -04:00
|
|
|
|
2020-01-09 11:29:18 -05:00
|
|
|
############################
|
|
|
|
# Validate we have a value #
|
|
|
|
############################
|
|
|
|
if [ -z "$GITHUB_WORKSPACE" ]; then
|
|
|
|
echo "ERROR! Failed to get [GITHUB_WORKSPACE]!"
|
|
|
|
echo "ERROR:[$GITHUB_WORKSPACE]"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]"
|
|
|
|
fi
|
2019-10-21 15:12:37 -04:00
|
|
|
|
2020-01-09 11:29:18 -05:00
|
|
|
############################
|
|
|
|
# Validate we have a value #
|
|
|
|
############################
|
|
|
|
if [ -z "$GITHUB_EVENT_PATH" ]; then
|
|
|
|
echo "ERROR! Failed to get [GITHUB_EVENT_PATH]!"
|
|
|
|
echo "ERROR:[$GITHUB_EVENT_PATH]"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Successfully found:[GITHUB_EVENT_PATH], value:[$GITHUB_EVENT_PATH]"
|
|
|
|
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 #
|
|
|
|
######################
|
|
|
|
# shellcheck disable=SC2002
|
|
|
|
GITHUB_ORG=$(cat "$GITHUB_EVENT_PATH" | jq -r '.repository.owner.login' )
|
|
|
|
|
|
|
|
############################
|
|
|
|
# Validate we have a value #
|
|
|
|
############################
|
|
|
|
if [ -z "$GITHUB_ORG" ]; then
|
|
|
|
echo "ERROR! Failed to get [GITHUB_ORG]!"
|
|
|
|
echo "ERROR:[$GITHUB_ORG]"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Successfully found:[GITHUB_ORG], value:[$GITHUB_ORG]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Get the GitHub Repo #
|
|
|
|
#######################
|
|
|
|
# shellcheck disable=SC2002
|
|
|
|
GITHUB_REPO=$(cat "$GITHUB_EVENT_PATH"| jq -r '.repository.name' )
|
|
|
|
|
|
|
|
############################
|
|
|
|
# Validate we have a value #
|
|
|
|
############################
|
|
|
|
if [ -z "$GITHUB_REPO" ]; then
|
|
|
|
echo "ERROR! Failed to get [GITHUB_REPO]!"
|
|
|
|
echo "ERROR:[$GITHUB_REPO]"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Successfully found:[GITHUB_REPO], value:[$GITHUB_REPO]"
|
|
|
|
fi
|
2019-10-21 15:12:37 -04:00
|
|
|
fi
|
2020-04-27 13:21:38 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function GetValidationInfo ################################################
|
|
|
|
GetValidationInfo()
|
|
|
|
{
|
2019-10-25 12:29:31 -04:00
|
|
|
############################################
|
|
|
|
# Print headers for user provided env vars #
|
|
|
|
############################################
|
|
|
|
echo ""
|
|
|
|
echo "--------------------------------------------"
|
2020-04-27 13:21:38 -04:00
|
|
|
echo "Gathering user validation information..."
|
2019-10-25 12:29:31 -04:00
|
|
|
|
2020-01-09 11:29:18 -05:00
|
|
|
###########################################
|
|
|
|
# Skip validation if were running locally #
|
|
|
|
###########################################
|
|
|
|
if [[ "$RUN_LOCAL" != "true" ]]; then
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_ALL_CODEBASE=$(echo "$VALIDATE_ALL_CODEBASE" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_ALL_CODEBASE" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_ALL_CODEBASE="$DEFAULT_VALIDATE_ALL_CODEBASE"
|
|
|
|
echo "- Validating ALL files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Only validating [new], or [edited] files in code base..."
|
|
|
|
fi
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_YAML=$(echo "$VALIDATE_YAML" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_YAML" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_YAML="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [YML] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [YML] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_JSON=$(echo "$VALIDATE_JSON" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_JSON" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_JSON="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [JSON] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [JSON] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_XML=$(echo "$VALIDATE_XML" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_XML" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_XML="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [XML] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [XML] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_MD=$(echo "$VALIDATE_MD" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_MD" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_MD="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [MARKDOWN] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [MARKDOWN] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_BASH=$(echo "$VALIDATE_BASH" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_BASH" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_BASH="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [BASH] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [BASH] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_PERL=$(echo "$VALIDATE_PERL" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_PERL" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_PERL="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [PERL] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [PERL] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_PYTHON=$(echo "$VALIDATE_PYTHON" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_PYTHON" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_PYTHON="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [PYTHON] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [PYTHON] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_RUBY=$(echo "$VALIDATE_RUBY" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_RUBY" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_RUBY="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [RUBY] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [RUBY] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_COFFEE=$(echo "$VALIDATE_COFFEE" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_COFFEE" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_COFFEE="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [COFFEE] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [COFFEE] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_ANSIBLE=$(echo "$VALIDATE_ANSIBLE" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_ANSIBLE" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_ANSIBLE="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [ANSIBLE] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [ANSIBLE] files in code base..."
|
|
|
|
fi
|
2019-11-06 16:45:44 -05:00
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
2020-04-02 13:42:07 -04:00
|
|
|
VALIDATE_JAVASCRIPT_ES=$(echo "$VALIDATE_JAVASCRIPT_ES" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_JAVASCRIPT_ES" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_JAVASCRIPT_ES="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [JAVASCRIPT(eslint)] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [JAVASCRIPT(eslint)] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_JAVASCRIPT_STANDARD=$(echo "$VALIDATE_JAVASCRIPT_STANDARD" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_JAVASCRIPT_STANDARD" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_JAVASCRIPT_STANDARD="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [JAVASCRIPT(standard)] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [JAVASCRIPT(standard)] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_TYPESCRIPT_ES=$(echo "$VALIDATE_TYPESCRIPT_ES" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_TYPESCRIPT_ES" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_TYPESCRIPT_ES="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [TYPESCRIPT(eslint)] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [TYPESCRIPT(eslint)] files in code base..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_TYPESCRIPT_STANDARD=$(echo "$VALIDATE_TYPESCRIPT_STANDARD" | awk '{print tolower($0)}')
|
2019-11-06 16:45:44 -05:00
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
2020-04-02 13:42:07 -04:00
|
|
|
if [[ "$VALIDATE_TYPESCRIPT_STANDARD" != "false" ]]; then
|
2019-11-06 16:45:44 -05:00
|
|
|
# Set to true
|
2020-04-02 13:42:07 -04:00
|
|
|
VALIDATE_TYPESCRIPT_STANDARD="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [TYPESCRIPT(standard)] files in code base..."
|
2019-11-06 16:45:44 -05:00
|
|
|
else
|
|
|
|
# Its false
|
2020-04-02 13:42:07 -04:00
|
|
|
echo "- Excluding [TYPESCRIPT(standard)] files in code base..."
|
2019-11-06 16:45:44 -05:00
|
|
|
fi
|
2019-12-03 14:47:23 -05:00
|
|
|
|
2020-01-09 17:08:01 -05:00
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_DOCKER=$(echo "$VALIDATE_DOCKER" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_DOCKER" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_DOCKER="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [DOCKER] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [DOCKER] files in code base..."
|
|
|
|
fi
|
|
|
|
|
2020-02-28 10:51:29 -05:00
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_GO=$(echo "$VALIDATE_GO" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_GO" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_GO="$DEFAULT_VALIDATE_LANGUAGE"
|
2020-02-28 11:08:38 -05:00
|
|
|
echo "- Validating [GOLANG] files in code base..."
|
2020-02-28 10:51:29 -05:00
|
|
|
else
|
|
|
|
# Its false
|
2020-02-28 11:08:38 -05:00
|
|
|
echo "- Excluding [GOLANG] files in code base..."
|
2020-02-28 10:51:29 -05:00
|
|
|
fi
|
2020-01-09 17:08:01 -05:00
|
|
|
|
2020-03-11 15:18:21 -04:00
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
|
|
|
VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_TERRAFORM" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_TERRAFORM="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [TERRAFORM] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [TERRAFORM] files in code base..."
|
|
|
|
fi
|
|
|
|
|
2019-12-03 14:47:23 -05:00
|
|
|
##############################
|
|
|
|
# Validate Ansible Directory #
|
|
|
|
##############################
|
|
|
|
if [ -z "$ANSIBLE_DIRECTORY" ]; then
|
|
|
|
# No Value, need to default
|
|
|
|
ANSIBLE_DIRECTORY="$DEFAULT_ANSIBLE_DIRECTORY"
|
|
|
|
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"
|
|
|
|
fi
|
2020-02-03 11:27:40 -05:00
|
|
|
|
|
|
|
############################
|
|
|
|
# Get the run verbose flag #
|
|
|
|
############################
|
2020-04-27 13:21:38 -04:00
|
|
|
if [ -z "$ACTIONS_RUNNER_DEBUG" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
##################################
|
|
|
|
# No flag passed, set to default #
|
|
|
|
##################################
|
2020-04-27 13:21:38 -04:00
|
|
|
ACTIONS_RUNNER_DEBUG="$DEFAULT_ACTIONS_RUNNER_DEBUG"
|
2020-02-03 11:27:40 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Convert string to lowercase #
|
|
|
|
###############################
|
2020-04-27 13:21:38 -04:00
|
|
|
ACTIONS_RUNNER_DEBUG=$(echo "$ACTIONS_RUNNER_DEBUG" | awk '{print tolower($0)}')
|
2020-02-03 15:54:43 -05:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Debug on runner #
|
|
|
|
###################
|
2020-04-27 13:21:38 -04:00
|
|
|
if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then
|
2020-02-03 15:54:43 -05:00
|
|
|
echo "--- DEBUG ---"
|
|
|
|
echo "---------------------------------------------"
|
|
|
|
RUNNER=$(whoami)
|
|
|
|
echo "Runner:[$RUNNER]"
|
|
|
|
echo "ENV:"
|
|
|
|
printenv
|
|
|
|
echo "---------------------------------------------"
|
|
|
|
fi
|
2019-10-21 15:12:37 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-25 15:22:57 -04:00
|
|
|
#### Function BuildFileList ####################################################
|
|
|
|
BuildFileList()
|
2019-10-22 13:21:42 -04:00
|
|
|
{
|
2019-10-25 15:22:57 -04:00
|
|
|
# Need to build a list of all files changed
|
|
|
|
# This can be pulled from the GITHUB_EVENT_PATH payload
|
2019-10-22 13:21:42 -04:00
|
|
|
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
2020-04-27 13:27:41 -04:00
|
|
|
if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "Pulling in code history and branches..."
|
|
|
|
fi
|
2019-10-28 12:18:05 -04:00
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Switch codebase back to master to get a list of all files changed #
|
|
|
|
#####################################################################
|
2020-04-27 13:27:41 -04:00
|
|
|
SWITCH_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git pull --quiet; git checkout master 2>&1)
|
2019-10-28 12:18:05 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
# Error
|
|
|
|
echo "Failed to switch to master branch to get files changed!"
|
|
|
|
echo "ERROR:[$SWITCH_CMD]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-22 13:21:42 -04:00
|
|
|
|
2019-12-06 08:51:40 -05:00
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
2020-04-27 13:27:41 -04:00
|
|
|
if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "Generating Diff with:[git diff --name-only 'master..$GITHUB_SHA' --diff-filter=d]"
|
|
|
|
fi
|
2019-12-03 15:07:19 -05:00
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
################################################
|
|
|
|
# Get the Array of files changed in the comits #
|
|
|
|
################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
# shellcheck disable=SC2207
|
2019-10-29 09:48:10 -04:00
|
|
|
RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only "master..$GITHUB_SHA" --diff-filter=d 2>&1))
|
2019-10-22 13:21:42 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# Error
|
2019-10-28 09:42:27 -04:00
|
|
|
echo "ERROR! Failed to gain a list of all files changed!"
|
2019-10-25 15:22:57 -04:00
|
|
|
echo "ERROR:[${RAW_FILE_ARRAY[*]}]"
|
2019-10-22 13:21:42 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
#################################################
|
|
|
|
# Itterate through the array of all files found #
|
|
|
|
#################################################
|
2019-12-06 08:51:40 -05:00
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
2019-12-03 15:07:19 -05:00
|
|
|
echo "Files that have been modified in the commit(s):"
|
2019-10-25 15:22:57 -04:00
|
|
|
for FILE in "${RAW_FILE_ARRAY[@]}"
|
|
|
|
do
|
2019-12-03 15:07:19 -05:00
|
|
|
##############
|
|
|
|
# Print file #
|
|
|
|
##############
|
|
|
|
echo "File:[$FILE]"
|
2019-12-03 15:29:16 -05:00
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
###########################
|
|
|
|
# Get the files extension #
|
|
|
|
###########################
|
2019-10-28 12:18:05 -04:00
|
|
|
# Extract just the file and extension, reverse it, cut off extension,
|
|
|
|
# reverse it back, substitute to lowercase
|
|
|
|
FILE_TYPE=$(basename "$FILE" | rev | cut -f1 -d'.' | rev | awk '{print tolower($0)}')
|
2019-10-23 10:51:13 -04:00
|
|
|
|
2019-10-28 12:18:05 -04:00
|
|
|
#########
|
|
|
|
# DEBUG #
|
|
|
|
#########
|
|
|
|
#echo "FILE_TYPE:[$FILE_TYPE]"
|
2019-10-23 10:51:13 -04:00
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
#####################
|
|
|
|
# Get the YML files #
|
|
|
|
#####################
|
|
|
|
if [ "$FILE_TYPE" == "yml" ] || [ "$FILE_TYPE" == "yaml" ]; then
|
2019-10-23 10:51:13 -04:00
|
|
|
################################
|
2019-10-25 15:22:57 -04:00
|
|
|
# Append the file to the array #
|
2019-10-23 10:51:13 -04:00
|
|
|
################################
|
2019-10-25 15:22:57 -04:00
|
|
|
FILE_ARRAY_YML+=("$FILE")
|
2020-01-07 15:38:05 -05:00
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2019-10-25 15:22:57 -04:00
|
|
|
######################
|
|
|
|
# Get the JSON files #
|
|
|
|
######################
|
|
|
|
elif [ "$FILE_TYPE" == "json" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_JSON+=("$FILE")
|
2020-01-07 15:38:05 -05:00
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2019-10-25 15:22:57 -04:00
|
|
|
#####################
|
|
|
|
# Get the XML files #
|
|
|
|
#####################
|
|
|
|
elif [ "$FILE_TYPE" == "xml" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_XML+=("$FILE")
|
2020-01-07 15:38:05 -05:00
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Get the MARKDOWN files #
|
|
|
|
##########################
|
|
|
|
elif [ "$FILE_TYPE" == "md" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_MD+=("$FILE")
|
|
|
|
######################
|
|
|
|
# Get the BASH files #
|
|
|
|
######################
|
|
|
|
elif [ "$FILE_TYPE" == "sh" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_BASH+=("$FILE")
|
2020-01-07 15:38:05 -05:00
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2019-10-25 15:22:57 -04:00
|
|
|
######################
|
|
|
|
# Get the PERL files #
|
|
|
|
######################
|
|
|
|
elif [ "$FILE_TYPE" == "pl" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_PERL+=("$FILE")
|
2020-01-07 15:38:05 -05:00
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2019-10-25 15:22:57 -04:00
|
|
|
######################
|
|
|
|
# Get the RUBY files #
|
|
|
|
######################
|
|
|
|
elif [ "$FILE_TYPE" == "rb" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_RUBY+=("$FILE")
|
2020-01-07 15:38:05 -05:00
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2019-10-23 10:51:13 -04:00
|
|
|
########################
|
2019-10-25 15:22:57 -04:00
|
|
|
# Get the PYTHON files #
|
2019-10-23 10:51:13 -04:00
|
|
|
########################
|
2019-10-25 15:22:57 -04:00
|
|
|
elif [ "$FILE_TYPE" == "py" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_PYTHON+=("$FILE")
|
2020-01-07 15:38:05 -05:00
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2019-10-25 15:22:57 -04:00
|
|
|
########################
|
|
|
|
# Get the COFFEE files #
|
|
|
|
########################
|
|
|
|
elif [ "$FILE_TYPE" == "coffee" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
2020-02-04 13:20:22 -05:00
|
|
|
FILE_ARRAY_COFFEESCRIPT+=("$FILE")
|
2020-01-07 15:38:05 -05:00
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
|
|
|
############################
|
|
|
|
# Get the JavaScript files #
|
|
|
|
############################
|
2019-11-06 16:45:44 -05:00
|
|
|
elif [ "$FILE_TYPE" == "js" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
2020-04-02 13:42:07 -04:00
|
|
|
FILE_ARRAY_JAVASCRIPT_ES+=("$FILE")
|
|
|
|
FILE_ARRAY_JAVASCRIPT_STANDARD+=("$FILE")
|
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
|
|
|
############################
|
|
|
|
# Get the TypeScript files #
|
|
|
|
############################
|
|
|
|
elif [ "$FILE_TYPE" == "ts" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_TYPESCRIPT_ES+=("$FILE")
|
|
|
|
FILE_ARRAY_TYPESCRIPT_STANDARD+=("$FILE")
|
2020-01-07 15:38:05 -05:00
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2020-02-28 10:51:29 -05:00
|
|
|
########################
|
|
|
|
# Get the Golang files #
|
|
|
|
########################
|
2020-03-11 15:18:21 -04:00
|
|
|
elif [ "$FILE_TYPE" == "go" ]; then
|
2020-02-28 10:51:29 -05:00
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_GO+=("$FILE")
|
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2020-03-11 15:18:21 -04:00
|
|
|
###########################
|
|
|
|
# Get the Terraform files #
|
|
|
|
###########################
|
|
|
|
elif [ "$FILE_TYPE" == "tf" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_TERRAFORM+=("$FILE")
|
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2020-01-09 17:08:01 -05:00
|
|
|
elif [ "$FILE" == "Dockerfile" ]; then
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_DOCKER+=("$FILE")
|
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2019-10-25 15:22:57 -04:00
|
|
|
else
|
2020-04-16 14:20:05 -04:00
|
|
|
##############################################
|
|
|
|
# Use file to see if we can parse what it is #
|
|
|
|
##############################################
|
|
|
|
GET_FILE_TYPE_CMD=$(file "$FILE" 2>&1)
|
|
|
|
|
|
|
|
#################
|
|
|
|
# Check if bash #
|
|
|
|
#################
|
2020-04-16 14:23:36 -04:00
|
|
|
if [[ "$GET_FILE_TYPE_CMD" == *"Bourne-Again shell script"* ]]; then
|
2020-04-16 14:20:05 -04:00
|
|
|
#######################
|
|
|
|
# It is a bash script #
|
|
|
|
#######################
|
|
|
|
echo "WARN! Found bash script without extension:[.sh]"
|
|
|
|
echo "Please update file with proper extensions."
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_BASH+=("$FILE")
|
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
2020-04-16 14:23:36 -04:00
|
|
|
elif [[ "$GET_FILE_TYPE_CMD" == *"Ruby script"* ]]; then
|
2020-04-16 14:20:05 -04:00
|
|
|
#######################
|
|
|
|
# It is a Ruby script #
|
|
|
|
#######################
|
|
|
|
echo "WARN! Found ruby script without extension:[.rb]"
|
|
|
|
echo "Please update file with proper extensions."
|
|
|
|
################################
|
|
|
|
# Append the file to the array #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_RUBY+=("$FILE")
|
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
|
|
|
else
|
|
|
|
############################
|
|
|
|
# Extension was not found! #
|
|
|
|
############################
|
|
|
|
echo " - WARN! Failed to get filetype for:[$FILE]!"
|
|
|
|
##########################################################
|
|
|
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
|
|
|
##########################################################
|
|
|
|
READ_ONLY_CHANGE_FLAG=1
|
|
|
|
fi
|
2019-10-25 15:22:57 -04:00
|
|
|
fi
|
|
|
|
done
|
2019-10-28 12:18:05 -04:00
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Need to switch back to branch of code #
|
|
|
|
#########################################
|
|
|
|
SWITCH2_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git checkout --progress --force "$GITHUB_SHA" 2>&1)
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
# Error
|
|
|
|
echo "Failed to switch back to branch!"
|
|
|
|
echo "ERROR:[$SWITCH2_CMD]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
################
|
|
|
|
# Footer print #
|
|
|
|
################
|
2019-12-06 08:51:40 -05:00
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
2019-10-28 12:18:05 -04:00
|
|
|
echo "Successfully gathered list of files..."
|
2019-10-25 12:29:31 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2020-02-03 11:27:40 -05:00
|
|
|
#### Function LintCodebase #####################################################
|
|
|
|
LintCodebase()
|
|
|
|
{
|
|
|
|
####################
|
|
|
|
# Pull in the vars #
|
|
|
|
####################
|
|
|
|
FILE_TYPE="$1" && shift # Pull the variable and remove from array path (Example: JSON)
|
2020-02-03 11:49:25 -05:00
|
|
|
LINTER_NAME="$1" && shift # Pull the variable and remove from array path (Example: jsonlint)
|
|
|
|
LINTER_COMMAND="$1" && shift # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file)
|
|
|
|
FILE_EXTENSIONS="$1" && shift # Pull the variable and remove from array path (Example: *.json)
|
2020-02-03 11:27:40 -05:00
|
|
|
FILE_ARRAY=("$@") # Array of files to validate (Example: $FILE_ARRAY_JSON)
|
|
|
|
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "----------------------------------------------"
|
2020-02-03 15:54:43 -05:00
|
|
|
echo "Linting [$FILE_TYPE] files..."
|
2020-02-03 11:27:40 -05:00
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Validate we have jsonlint installed #
|
|
|
|
#######################################
|
|
|
|
# shellcheck disable=SC2230
|
|
|
|
VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1)
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
# Failed
|
|
|
|
echo "ERROR! Failed to find [$LINTER_NAME] in system!"
|
|
|
|
echo "ERROR:[$VALIDATE_INSTALL_CMD]"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
# Success
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
|
|
|
if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
2020-02-03 16:28:18 -05:00
|
|
|
echo " - No files found in chageset to lint for language:[$FILE_TYPE]"
|
2020-02-03 11:27:40 -05:00
|
|
|
elif [ ${#FILE_ARRAY[@]} -ne 0 ]; then
|
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
2020-02-03 15:54:43 -05:00
|
|
|
# shellcheck disable=SC2207,SC2086
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex "$FILE_EXTENSIONS" 2>&1))
|
2020-02-03 11:27:40 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
#####################
|
|
|
|
# Get the file name #
|
|
|
|
#####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
2020-02-04 09:49:58 -05:00
|
|
|
#####################################################
|
|
|
|
# Make sure we dont lint node modules or test cases #
|
|
|
|
#####################################################
|
2020-02-03 11:27:40 -05:00
|
|
|
if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# This is a node modules file
|
|
|
|
continue
|
2020-02-04 10:04:43 -05:00
|
|
|
elif [[ $FILE == *"$TEST_CASE_FOLDER"* ]]; then
|
2020-02-04 09:49:58 -05:00
|
|
|
# This is the test cases, we should always skip
|
|
|
|
continue
|
2020-02-03 11:27:40 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
2020-02-03 15:54:43 -05:00
|
|
|
LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1)
|
2020-02-03 11:27:40 -05:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
#########
|
|
|
|
# Error #
|
|
|
|
#########
|
|
|
|
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
|
|
|
|
echo "ERROR:[$LINT_CMD]"
|
|
|
|
# Increment the error count
|
2020-02-03 15:54:43 -05:00
|
|
|
(("ERRORS_FOUND_$FILE_TYPE++"))
|
2020-02-03 11:27:40 -05:00
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
2020-02-04 12:49:07 -05:00
|
|
|
#### Function TestCodebase #####################################################
|
|
|
|
TestCodebase()
|
|
|
|
{
|
|
|
|
####################
|
|
|
|
# Pull in the vars #
|
|
|
|
####################
|
|
|
|
FILE_TYPE="$1" # Pull the variable and remove from array path (Example: JSON)
|
|
|
|
LINTER_NAME="$2" # Pull the variable and remove from array path (Example: jsonlint)
|
|
|
|
LINTER_COMMAND="$3" # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file)
|
|
|
|
FILE_EXTENSIONS="$4" # Pull the variable and remove from array path (Example: *.json)
|
|
|
|
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "Testing Codebase [$FILE_TYPE] files..."
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have linter installed #
|
|
|
|
#####################################
|
|
|
|
# shellcheck disable=SC2230
|
|
|
|
VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1)
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
# Failed
|
|
|
|
echo "ERROR! Failed to find [$LINTER_NAME] in system!"
|
|
|
|
echo "ERROR:[$VALIDATE_INSTALL_CMD]"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
# Success
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################
|
|
|
|
# Check if its ansible, as its the outlier #
|
|
|
|
############################################
|
|
|
|
if [[ "$FILE_TYPE" == "ANSIBLE" ]]; then
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
2020-02-04 12:56:02 -05:00
|
|
|
# shellcheck disable=SC2207,SC2086,SC2010
|
2020-02-04 12:49:07 -05:00
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; ls ansible/ | grep ".yml" 2>&1))
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207,SC2086
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; find . -type f -regex "$FILE_EXTENSIONS" ! -path "*./ansible*" 2>&1))
|
|
|
|
fi
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
#####################
|
|
|
|
# Get the file name #
|
|
|
|
#####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
############################
|
|
|
|
# Get the file pass status #
|
|
|
|
############################
|
|
|
|
# Example: markdown_good_1.md -> good
|
|
|
|
FILE_STATUS=$(echo "$FILE_NAME" |cut -f2 -d'_')
|
|
|
|
|
2020-02-04 16:20:58 -05:00
|
|
|
#########################################################
|
|
|
|
# If not found, assume it should be linted successfully #
|
|
|
|
#########################################################
|
2020-02-04 16:32:14 -05:00
|
|
|
if [ -z "$FILE_STATUS" ] || [[ "$FILE" == *"README"* ]]; then
|
2020-02-04 16:20:58 -05:00
|
|
|
##################################
|
|
|
|
# Set to good for proper linting #
|
|
|
|
##################################
|
|
|
|
FILE_STATUS="good"
|
|
|
|
fi
|
|
|
|
|
2020-02-04 12:49:07 -05:00
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
########################
|
|
|
|
# Set the lint command #
|
|
|
|
########################
|
|
|
|
LINT_CMD=''
|
|
|
|
|
2020-02-04 16:20:58 -05:00
|
|
|
#######################################
|
|
|
|
# Check if docker and get folder name #
|
|
|
|
#######################################
|
|
|
|
if [[ "$FILE_TYPE" == "DOCKER" ]]; then
|
|
|
|
if [[ "$FILE" == *"good"* ]]; then
|
|
|
|
#############
|
|
|
|
# Good file #
|
|
|
|
#############
|
|
|
|
FILE_STATUS='good'
|
|
|
|
else
|
|
|
|
############
|
|
|
|
# Bad file #
|
|
|
|
############
|
|
|
|
FILE_STATUS='bad'
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-02-04 12:49:07 -05:00
|
|
|
#####################
|
|
|
|
# Check for ansible #
|
|
|
|
#####################
|
|
|
|
if [[ "$FILE_TYPE" == "ANSIBLE" ]]; then
|
|
|
|
########################################
|
|
|
|
# Make sure we dont lint certain files #
|
|
|
|
########################################
|
|
|
|
if [[ $FILE == *"vault.yml"* ]] || [[ $FILE == *"galaxy.yml"* ]]; then
|
|
|
|
# This is a file we dont look at
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
|
|
|
LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER/ansible" || exit; $LINTER_COMMAND "$FILE" 2>&1)
|
|
|
|
else
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
|
|
|
LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE" 2>&1)
|
|
|
|
fi
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
########################################
|
|
|
|
# Check for if it was supposed to pass #
|
|
|
|
########################################
|
|
|
|
if [[ "$FILE_STATUS" == "good" ]]; then
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
#########
|
|
|
|
# Error #
|
|
|
|
#########
|
|
|
|
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
|
|
|
|
echo "ERROR:[$LINT_CMD]"
|
2020-04-02 14:22:29 -04:00
|
|
|
echo "ERROR: Linter CMD:[$LINTER_COMMAND $FILE]"
|
2020-02-04 12:49:07 -05:00
|
|
|
# Increment the error count
|
|
|
|
(("ERRORS_FOUND_$FILE_TYPE++"))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
#######################################
|
|
|
|
# File status = bad, this should fail #
|
|
|
|
#######################################
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -eq 0 ]; then
|
|
|
|
#########
|
|
|
|
# Error #
|
|
|
|
#########
|
|
|
|
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
|
|
|
|
echo "ERROR! This file should have failed test case!"
|
|
|
|
echo "ERROR:[$LINT_CMD]"
|
2020-04-02 14:22:29 -04:00
|
|
|
echo "ERROR: Linter CMD:[$LINTER_COMMAND $FILE]"
|
2020-02-04 12:49:07 -05:00
|
|
|
# Increment the error count
|
|
|
|
(("ERRORS_FOUND_$FILE_TYPE++"))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] failed test case with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 12:05:55 -04:00
|
|
|
#### Function Footer ###########################################################
|
|
|
|
Footer()
|
2019-10-21 10:12:50 -04:00
|
|
|
{
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "The script has completed"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "----------------------------------------------"
|
2020-04-23 13:07:35 -04:00
|
|
|
echo ""
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "ERRORS FOUND in YAML:[$ERRORS_FOUND_YML]"
|
|
|
|
echo "ERRORS FOUND in JSON:[$ERRORS_FOUND_JSON]"
|
|
|
|
echo "ERRORS FOUND in XML:[$ERRORS_FOUND_XML]"
|
2020-02-03 15:54:43 -05:00
|
|
|
echo "ERRORS FOUND in MARKDOWN:[$ERRORS_FOUND_MARKDOWN]"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "ERRORS FOUND in BASH:[$ERRORS_FOUND_BASH]"
|
|
|
|
echo "ERRORS FOUND in PERL:[$ERRORS_FOUND_PERL]"
|
|
|
|
echo "ERRORS FOUND in PYTHON:[$ERRORS_FOUND_PYTHON]"
|
2020-02-04 13:01:36 -05:00
|
|
|
echo "ERRORS FOUND in COFFEESCRIPT:[$ERRORS_FOUND_COFFEESCRIPT]"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "ERRORS FOUND in RUBY:[$ERRORS_FOUND_RUBY]"
|
2019-10-22 13:21:42 -04:00
|
|
|
echo "ERRORS FOUND in ANSIBLE:[$ERRORS_FOUND_ANSIBLE]"
|
2020-04-02 13:42:07 -04:00
|
|
|
echo "ERRORS FOUND in JAVASCRIPT(eslint):[$ERRORS_FOUND_JAVASCRIPT_ES]"
|
|
|
|
echo "ERRORS FOUND in JAVASCRIPT(Standard):[$ERRORS_FOUND_JAVASCRIPT_STANDARD]"
|
|
|
|
echo "ERRORS FOUND in TYPESCRIPT(eslint):[$ERRORS_FOUND_TYPESCRIPT_ES]"
|
|
|
|
echo "ERRORS FOUND in TYPESCRIPT(Standard):[$ERRORS_FOUND_TYPESCRIPT_STANDARD]"
|
2020-01-09 17:08:01 -05:00
|
|
|
echo "ERRORS FOUND in DOCKER:[$ERRORS_FOUND_DOCKER]"
|
2020-02-28 10:51:29 -05:00
|
|
|
echo "ERRORS FOUND in GO:[$ERRORS_FOUND_GO]"
|
2020-03-11 15:18:21 -04:00
|
|
|
echo "ERRORS FOUND in TERRAFORM:[$ERRORS_FOUND_TERRAFORM]"
|
2020-04-23 13:07:35 -04:00
|
|
|
echo ""
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Exit with 1 if errors found #
|
|
|
|
###############################
|
2020-03-11 15:21:42 -04:00
|
|
|
if [ "$ERRORS_FOUND_YML" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_JSON" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_XML" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_MARKDOWN" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_BASH" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_PERL" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_PYTHON" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_COFFEESCRIPT" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_ANSIBLE" -ne 0 ] || \
|
2020-04-02 13:42:07 -04:00
|
|
|
[ "$ERRORS_FOUND_JAVASCRIPT_ES" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_JAVASCRIPT_STANDARD" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_TYPESCRIPT_ES" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_TYPESCRIPT_STANDARD" -ne 0 ] || \
|
2020-03-11 15:21:42 -04:00
|
|
|
[ "$ERRORS_FOUND_DOCKER" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_GO" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \
|
|
|
|
[ "$ERRORS_FOUND_RUBY" -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
# Failed exit
|
|
|
|
echo "Exiting with errors found!"
|
2019-10-21 10:12:50 -04:00
|
|
|
exit 1
|
|
|
|
else
|
2019-10-21 12:05:55 -04:00
|
|
|
# Successful exit
|
|
|
|
exit 0
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
################################################################################
|
2020-02-04 12:49:07 -05:00
|
|
|
#### Function RunTestCases #####################################################
|
|
|
|
RunTestCases()
|
|
|
|
{
|
|
|
|
# This loop will run the test cases and exclude user code
|
|
|
|
# This is called from the automation process to validate new code
|
|
|
|
# When a PR is opened, the new code is validated with the master branch
|
|
|
|
# version of linter.sh, and a new container is built with the latest codebase
|
|
|
|
# for testing. That container is spun up, and ran,
|
|
|
|
# with the flag: TEST_CASE_RUN=true
|
|
|
|
# So that the new code can be validated againt the test cases
|
|
|
|
|
|
|
|
#################
|
|
|
|
# Header prints #
|
|
|
|
#################
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "-------------- TEST CASE RUN -----------------"
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Test case languages #
|
|
|
|
#######################
|
|
|
|
TestCodebase "YML" "yamllint" "yamllint -c $YAML_LINTER_RULES" ".*\.\(yml\|yaml\)\$"
|
|
|
|
TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$"
|
|
|
|
TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$"
|
|
|
|
TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c $MD_LINTER_RULES" ".*\.\(md\)\$"
|
|
|
|
TestCodebase "BASH" "shellcheck" "shellcheck" ".*\.\(sh\)\$"
|
|
|
|
TestCodebase "PYTHON" "pylint" "pylint --rcfile $PYTHON_LINTER_RULES -E" ".*\.\(py\)\$"
|
|
|
|
TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$"
|
|
|
|
TestCodebase "RUBY" "rubocop" "rubocop -c $RUBY_LINTER_RULES" ".*\.\(rb\)\$"
|
2020-02-28 10:51:29 -05:00
|
|
|
TestCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$"
|
2020-02-04 13:20:22 -05:00
|
|
|
TestCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f $COFFEESCRIPT_LINTER_RULES" ".*\.\(coffee\)\$"
|
2020-04-02 14:06:11 -04:00
|
|
|
TestCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c $JAVASCRIPT_LINTER_RULES" ".*\.\(js\)\$"
|
|
|
|
TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard $JAVASCRIPT_STANDARD_LINTER_RULES" ".*\.\(js\)\$"
|
|
|
|
TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c $TYPESCRIPT_LINTER_RULES" ".*\.\(ts\)\$"
|
|
|
|
TestCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin $TYPESCRIPT_STANDARD_LINTER_RULES" ".*\.\(ts\)\$"
|
2020-02-04 12:49:07 -05:00
|
|
|
TestCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$"
|
|
|
|
TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint"
|
2020-03-11 15:18:21 -04:00
|
|
|
TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$"
|
2020-02-04 12:49:07 -05:00
|
|
|
|
|
|
|
#################
|
|
|
|
# Footer prints #
|
|
|
|
#################
|
|
|
|
# Call the footer to display run information
|
|
|
|
# and exit with error code
|
|
|
|
Footer
|
|
|
|
}
|
|
|
|
################################################################################
|
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
|
|
|
|
|
2019-10-21 15:12:37 -04:00
|
|
|
#######################
|
|
|
|
# Get Github Env Vars #
|
|
|
|
#######################
|
|
|
|
# Need to pull in all the Github variables
|
|
|
|
# needed to connect back and update checks
|
|
|
|
GetGitHubVars
|
|
|
|
|
2020-04-27 13:21:38 -04:00
|
|
|
##########################################
|
|
|
|
# Get the langugages we need to validate #
|
|
|
|
##########################################
|
|
|
|
if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then
|
|
|
|
# Get the flags for langugaes to validate
|
|
|
|
GetValidationInfo
|
|
|
|
fi
|
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
########################
|
|
|
|
# Get the linter rules #
|
|
|
|
########################
|
2020-03-11 15:18:21 -04:00
|
|
|
# Get YML rules
|
2020-02-03 11:27:40 -05:00
|
|
|
GetLinterRules "$YAML_FILE_NAME" "$YAML_LINTER_RULES"
|
2020-03-11 15:18:21 -04:00
|
|
|
# Get Markdown rules
|
2020-02-03 11:27:40 -05:00
|
|
|
GetLinterRules "$MD_FILE_NAME" "$MD_LINTER_RULES"
|
2020-03-11 15:18:21 -04:00
|
|
|
# Get Python rules
|
2020-02-03 11:27:40 -05:00
|
|
|
GetLinterRules "$PYTHON_FILE_NAME" "$PYTHON_LINTER_RULES"
|
2020-03-11 15:18:21 -04:00
|
|
|
# Get Ruby rules
|
2020-02-03 11:27:40 -05:00
|
|
|
GetLinterRules "$RUBY_FILE_NAME" "$RUBY_LINTER_RULES"
|
2020-03-11 15:18:21 -04:00
|
|
|
# Get Coffeescript rules
|
2020-02-04 13:20:22 -05:00
|
|
|
GetLinterRules "$COFFEE_FILE_NAME" "$COFFEESCRIPT_LINTER_RULES"
|
2020-03-11 15:18:21 -04:00
|
|
|
# Get Ansible rules
|
2020-02-03 11:27:40 -05:00
|
|
|
GetLinterRules "$ANSIBLE_FILE_NAME" "$ANSIBLE_LINTER_RULES"
|
2020-03-11 15:18:21 -04:00
|
|
|
# Get JavaScript rules
|
2020-02-03 11:27:40 -05:00
|
|
|
GetLinterRules "$JAVASCRIPT_FILE_NAME" "$JAVASCRIPT_LINTER_RULES"
|
2020-04-02 13:42:07 -04:00
|
|
|
# Get TypeScript rules
|
|
|
|
GetLinterRules "$TYPESCRIPT_FILE_NAME" "$TYPESCRIPT_LINTER_RULES"
|
2020-02-28 10:51:29 -05:00
|
|
|
# Get Golang rules
|
|
|
|
GetLinterRules "$GO_FILE_NAME" "$GO_LINTER_RULES"
|
2020-03-11 15:18:21 -04:00
|
|
|
# Get Docker rules
|
2020-02-03 11:27:40 -05:00
|
|
|
GetLinterRules "$DOCKER_FILE_NAME" "$DOCKER_LINTER_RULES"
|
2020-03-11 15:18:21 -04:00
|
|
|
# Get Terraform rules
|
|
|
|
GetLinterRules "$TERRAFORM_FILE_NAME" "$TERRAFORM_LINTER_RULES"
|
2020-02-03 11:27:40 -05:00
|
|
|
|
|
|
|
#################################
|
|
|
|
# Check if were in verbose mode #
|
|
|
|
#################################
|
2020-04-27 13:21:38 -04:00
|
|
|
if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
##################################
|
|
|
|
# Get and print all version info #
|
|
|
|
##################################
|
|
|
|
GetLinterVersions
|
|
|
|
fi
|
2020-01-08 14:34:05 -05:00
|
|
|
|
2020-02-04 12:49:07 -05:00
|
|
|
###########################################
|
|
|
|
# Check to see if this is a test case run #
|
|
|
|
###########################################
|
|
|
|
if [[ "$TEST_CASE_RUN" != "false" ]]; then
|
|
|
|
###########################
|
|
|
|
# Run only the test cases #
|
|
|
|
###########################
|
|
|
|
# Code will exit from inside this loop
|
|
|
|
RunTestCases
|
|
|
|
fi
|
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
#############################################
|
|
|
|
# check flag for validation of all codebase #
|
|
|
|
#############################################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
########################################
|
|
|
|
# Get list of files changed if env set #
|
|
|
|
########################################
|
2019-10-25 12:29:31 -04:00
|
|
|
BuildFileList
|
|
|
|
fi
|
2019-10-21 15:12:37 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
###############
|
|
|
|
# YML LINTING #
|
|
|
|
###############
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_YAML" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
######################
|
|
|
|
# Lint the Yml Files #
|
|
|
|
######################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "YML" "yamllint" "yamllint -c $YAML_LINTER_RULES" ".*\.\(yml\|yaml\)\$" "${FILE_ARRAY_YML[@]}"
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
################
|
|
|
|
# JSON LINTING #
|
|
|
|
################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_JSON" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
#######################
|
|
|
|
# Lint the json files #
|
|
|
|
#######################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "${FILE_ARRAY_JSON[@]}"
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
###############
|
|
|
|
# XML LINTING #
|
|
|
|
###############
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_XML" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
######################
|
|
|
|
# Lint the XML Files #
|
|
|
|
######################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "${FILE_ARRAY_XML[@]}"
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
####################
|
|
|
|
# MARKDOWN LINTING #
|
|
|
|
####################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_MD" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
###########################
|
|
|
|
# Lint the Markdown Files #
|
|
|
|
###########################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "MARKDOWN" "markdownlint" "markdownlint -c $MD_LINTER_RULES" ".*\.\(md\)\$" "${FILE_ARRAY_MD[@]}"
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
################
|
|
|
|
# BASH LINTING #
|
|
|
|
################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_BASH" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
#######################
|
|
|
|
# Lint the bash files #
|
|
|
|
#######################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "BASH" "shellcheck" "shellcheck" ".*\.\(sh\)\$" "${FILE_ARRAY_BASH[@]}"
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
##################
|
|
|
|
# PYTHON LINTING #
|
|
|
|
##################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_PYTHON" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
#########################
|
|
|
|
# Lint the python files #
|
|
|
|
#########################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "PYTHON" "pylint" "pylint --rcfile $PYTHON_LINTER_RULES -E" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON[@]}"
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
################
|
|
|
|
# PERL LINTING #
|
|
|
|
################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_PERL" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
#######################
|
|
|
|
# Lint the perl files #
|
|
|
|
#######################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}"
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
################
|
|
|
|
# RUBY LINTING #
|
|
|
|
################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_RUBY" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
#######################
|
|
|
|
# Lint the ruby files #
|
|
|
|
#######################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "RUBY" "rubocop" "rubocop -c $RUBY_LINTER_RULES" ".*\.\(rb\)\$" "${FILE_ARRAY_RUBY[@]}"
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
########################
|
|
|
|
# COFFEESCRIPT LINTING #
|
|
|
|
########################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_COFFEE" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
#########################
|
|
|
|
# Lint the coffee files #
|
|
|
|
#########################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
2020-02-04 13:20:22 -05:00
|
|
|
LintCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f $COFFEESCRIPT_LINTER_RULES" ".*\.\(coffee\)\$" "${FILE_ARRAY_COFFEESCRIPT[@]}"
|
2019-10-25 12:29:31 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2020-02-28 10:51:29 -05:00
|
|
|
##################
|
|
|
|
# GOLANG LINTING #
|
|
|
|
##################
|
|
|
|
if [ "$VALIDATE_GO" == "true" ]; then
|
|
|
|
#########################
|
|
|
|
# Lint the golang files #
|
|
|
|
#########################
|
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$" "${FILE_ARRAY_GO[@]}"
|
|
|
|
fi
|
|
|
|
|
2020-03-11 15:18:21 -04:00
|
|
|
#####################
|
|
|
|
# TERRAFORM LINTING #
|
|
|
|
#####################
|
|
|
|
if [ "$VALIDATE_TERRAFORM" == "true" ]; then
|
|
|
|
############################
|
|
|
|
# Lint the Terraform files #
|
|
|
|
############################
|
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM[@]}"
|
|
|
|
fi
|
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
###################
|
|
|
|
# ANSIBLE LINTING #
|
|
|
|
###################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_ANSIBLE" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
##########################
|
|
|
|
# Lint the Ansible files #
|
|
|
|
##########################
|
|
|
|
# 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
|
2019-10-25 12:29:31 -04:00
|
|
|
LintAnsibleFiles
|
|
|
|
fi
|
2019-10-22 13:21:42 -04:00
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
######################
|
|
|
|
# JAVASCRIPT LINTING #
|
|
|
|
######################
|
2020-04-02 13:42:07 -04:00
|
|
|
if [ "$VALIDATE_JAVASCRIPT_ES" == "true" ]; then
|
|
|
|
#############################
|
|
|
|
# Lint the Javascript files #
|
|
|
|
#############################
|
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c $JAVASCRIPT_LINTER_RULES" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_ES[@]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
######################
|
|
|
|
# JAVASCRIPT LINTING #
|
|
|
|
######################
|
|
|
|
if [ "$VALIDATE_JAVASCRIPT_STANDARD" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
#################################
|
|
|
|
# Get Javascript standard rules #
|
|
|
|
#################################
|
2020-04-02 13:48:35 -04:00
|
|
|
GetStandardRules "javascript"
|
2020-02-03 11:27:40 -05:00
|
|
|
#############################
|
|
|
|
# Lint the Javascript files #
|
|
|
|
#############################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
2020-04-02 13:42:07 -04:00
|
|
|
LintCodebase "JAVASCRIPT_STANDARD" "standard" "standard $JAVASCRIPT_STANDARD_LINTER_RULES" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_STANDARD[@]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
######################
|
|
|
|
# TYPESCRIPT LINTING #
|
|
|
|
######################
|
|
|
|
if [ "$VALIDATE_TYPESCRIPT_ES" == "true" ]; then
|
|
|
|
#############################
|
|
|
|
# Lint the Typescript files #
|
|
|
|
#############################
|
|
|
|
LintCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c $TYPESCRIPT_LINTER_RULES" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_ES[@]}"
|
|
|
|
fi
|
|
|
|
######################
|
|
|
|
# TYPESCRIPT LINTING #
|
|
|
|
######################
|
|
|
|
if [ "$VALIDATE_TYPESCRIPT_STANDARD" == "true" ]; then
|
|
|
|
#################################
|
|
|
|
# Get Typescript standard rules #
|
|
|
|
#################################
|
2020-04-02 13:48:35 -04:00
|
|
|
GetStandardRules "typescript"
|
2020-04-02 13:42:07 -04:00
|
|
|
#############################
|
|
|
|
# Lint the Typescript files #
|
|
|
|
#############################
|
|
|
|
LintCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin $TYPESCRIPT_STANDARD_LINTER_RULES" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_STANDARD[@]}"
|
2019-11-06 16:45:44 -05:00
|
|
|
fi
|
|
|
|
|
2020-02-03 11:27:40 -05:00
|
|
|
##################
|
|
|
|
# DOCKER LINTING #
|
|
|
|
##################
|
2020-01-09 17:08:01 -05:00
|
|
|
if [ "$VALIDATE_DOCKER" == "true" ]; then
|
2020-02-03 11:27:40 -05:00
|
|
|
#########################
|
|
|
|
# Lint the docker files #
|
|
|
|
#########################
|
2020-02-03 15:54:43 -05:00
|
|
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
|
|
|
LintCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}"
|
2020-01-09 17:08:01 -05:00
|
|
|
fi
|
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
##########
|
|
|
|
# Footer #
|
|
|
|
##########
|
|
|
|
Footer
|