2019-10-23 11:42:28 -04:00
|
|
|
#!/bin/bash
|
2019-10-21 10:12:50 -04:00
|
|
|
|
|
|
|
################################################################################
|
2019-10-21 12:05:55 -04:00
|
|
|
########### EntryPoint for Super-Linter @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
|
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
|
2019-10-23 10:51:13 -04:00
|
|
|
COFFEE_FILE_NAME='.coffee-lint.json' # Name of the file
|
|
|
|
COFFEE_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
|
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
|
|
|
|
ANSIBLE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$ANSIBLE_FILE_NAME" # Path to the coffescript 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-01-09 17:08:01 -05:00
|
|
|
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard" "ansible-lint" "node_modules/dockerfilelint/bin/dockerfilelint")
|
2020-01-08 14:34:05 -05:00
|
|
|
|
2019-10-21 15:12:37 -04:00
|
|
|
###################
|
|
|
|
# GitHub ENV Vars #
|
|
|
|
###################
|
2019-10-25 12:29:31 -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
|
2019-12-03 14:47:23 -05:00
|
|
|
ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory
|
2019-10-25 12:29:31 -04:00
|
|
|
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
|
2019-11-06 16:45:44 -05:00
|
|
|
VALIDATE_JAVASCRIPT="${VALIDATE_JAVASCRIPT}" # Boolean to validate language
|
2020-01-09 17:08:01 -05:00
|
|
|
VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language
|
2020-01-09 11:29:18 -05:00
|
|
|
RUN_LOCAL="${RUN_LOCAL}" # Boolean to see if we are running locally
|
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-01-09 11:29:18 -05:00
|
|
|
DEFAULT_RUN_LOCAL='false' # default value for debugging
|
2019-12-03 14:47:23 -05:00
|
|
|
RAW_FILE_ARRAY=() # Array of all files that were changed
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Array of changed files #
|
|
|
|
##########################
|
2019-11-06 16:45:44 -05: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_COFFEE=() # Array of files to check
|
|
|
|
FILE_ARRAY_JAVASCRIPT=() # Array of files to check
|
2020-01-09 17:08:01 -05:00
|
|
|
FILE_ARRAY_DOCKER=() # Array of files to check
|
2019-10-25 15:22:57 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
############
|
|
|
|
# Counters #
|
|
|
|
############
|
2019-11-06 16:45:44 -05: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_MD=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_COFFEE=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_ANSIBLE=0 # Count of errors found
|
|
|
|
ERRORS_FOUND_JAVASCRIPT=0 # Count of errors found
|
2020-01-09 17:08:01 -05:00
|
|
|
ERRORS_FOUND_DOCKER=0 # Count of errors found
|
2020-01-07 15:38:05 -05:00
|
|
|
READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md
|
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 "---------------------------------------------"
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "------ Github Actions 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-12-13 09:06:25 -05:00
|
|
|
|
2019-12-13 09:48:07 -05:00
|
|
|
# echo "--- DEBUG ---"
|
|
|
|
# echo "---------------------------------------------"
|
|
|
|
# RUNNER=$(whoami)
|
|
|
|
# echo "Runner:[$RUNNER]"
|
|
|
|
# echo "ENV:"
|
|
|
|
# printenv
|
|
|
|
# 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 #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
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
|
2019-10-23 10:51:13 -04:00
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "Gathering Linter rules from repository, or defaulting..."
|
|
|
|
echo ""
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#####################################
|
|
|
|
# Validate we have the linter rules #
|
|
|
|
#####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
if [ -f "$GITHUB_WORKSPACE/.github/linters/$YAML_FILE_NAME" ]; then
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "User provided file:[$YAML_FILE_NAME], setting rules file..."
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Move users into default location #
|
|
|
|
####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/linters/$YAML_FILE_NAME" "$YAML_LINTER_RULES" 2>&1)
|
2019-10-21 15:12:37 -04:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Load Error code #
|
|
|
|
###################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
echo "ERROR! Failed to set file:[$YAML_FILE_NAME] as default!"
|
|
|
|
echo "ERROR:[$MV_CMD]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-23 10:51:13 -04:00
|
|
|
else
|
2019-10-25 12:29:31 -04:00
|
|
|
echo "Codebase does not have file:[.github/linters/$YAML_FILE_NAME], using Default rules at:[$YAML_LINTER_RULES]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#####################################
|
|
|
|
# Validate we have the linter rules #
|
|
|
|
#####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
if [ -f "$GITHUB_WORKSPACE/.github/linters/$MD_FILE_NAME" ]; then
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "User provided file:[$MD_FILE_NAME], setting rules file..."
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Move users into default location #
|
|
|
|
####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/linters/$MD_FILE_NAME" "$MD_LINTER_RULES" 2>&1)
|
2019-10-21 15:12:37 -04:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Load Error code #
|
|
|
|
###################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
echo "ERROR! Failed to set file:[$MD_FILE_NAME] as default!"
|
|
|
|
echo "ERROR:[$MV_CMD]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-23 10:51:13 -04:00
|
|
|
else
|
2019-10-25 12:29:31 -04:00
|
|
|
echo "Codebase does not have file:[.github/linters/$MD_FILE_NAME], using Default rules at:[$MD_LINTER_RULES]"
|
2019-10-21 15:12:37 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have the linter rules #
|
|
|
|
#####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
if [ -f "$GITHUB_WORKSPACE/.github/linters/$PYTHON_FILE_NAME" ]; then
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "User provided file:[$PYTHON_FILE_NAME], setting rules file..."
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Move users into default location #
|
|
|
|
####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/linters/$PYTHON_FILE_NAME" "$PYTHON_LINTER_RULES" 2>&1)
|
2019-10-21 15:12:37 -04:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Load Error code #
|
|
|
|
###################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-23 10:51:13 -04:00
|
|
|
echo "ERROR! Failed to set file:[$PYTHON_FILE_NAME] as default!"
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "ERROR:[$MV_CMD]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-23 10:51:13 -04:00
|
|
|
else
|
2019-10-25 12:29:31 -04:00
|
|
|
echo "Codebase does not have file:[.github/linters/$PYTHON_FILE_NAME], using Default rules at:[$PYTHON_LINTER_RULES]"
|
2019-10-21 15:12:37 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have the linter rules #
|
|
|
|
#####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
if [ -f "$GITHUB_WORKSPACE/.github/linters/$RUBY_FILE_NAME" ]; then
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "User provided file:[$RUBY_FILE_NAME], setting rules file..."
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Move users into default location #
|
|
|
|
####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/linters/$RUBY_FILE_NAME" "$RUBY_LINTER_RULES" 2>&1)
|
2019-10-21 15:12:37 -04:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Load Error code #
|
|
|
|
###################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
echo "ERROR! Failed to set file:[$RUBY_FILE_NAME] as default!"
|
|
|
|
echo "ERROR:[$MV_CMD]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-23 10:51:13 -04:00
|
|
|
else
|
2019-10-25 12:29:31 -04:00
|
|
|
echo "Codebase does not have file:[.github/linters/$RUBY_FILE_NAME], using Default rules at:[$RUBY_LINTER_RULES]"
|
2019-10-21 15:12:37 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have the linter rules #
|
|
|
|
#####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
if [ -f "$GITHUB_WORKSPACE/.github/linters/$COFFEE_FILE_NAME" ]; then
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "User provided file:[$COFFEE_FILE_NAME], setting rules file..."
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Move users into default location #
|
|
|
|
####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/linters/$COFFEE_FILE_NAME" "$COFFEE_LINTER_RULES" 2>&1)
|
2019-10-21 15:12:37 -04:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Load Error code #
|
|
|
|
###################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
echo "ERROR! Failed to set file:[$COFFEE_FILE_NAME] as default!"
|
|
|
|
echo "ERROR:[$MV_CMD]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-23 10:51:13 -04:00
|
|
|
else
|
2019-10-25 12:29:31 -04:00
|
|
|
echo "Codebase does not have file:[.github/linters/$COFFEE_FILE_NAME], using Default rules at:[$COFFEE_LINTER_RULES]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
2019-10-22 13:21:42 -04:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have the linter rules #
|
|
|
|
#####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
if [ -f "$GITHUB_WORKSPACE/.github/linters/$ANSIBLE_FILE_NAME" ]; then
|
2019-10-22 13:21:42 -04:00
|
|
|
echo "User provided file:[$ANSIBLE_FILE_NAME], setting rules file..."
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Move users into default location #
|
|
|
|
####################################
|
2019-10-23 11:23:16 -04:00
|
|
|
MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/linters/$ANSIBLE_FILE_NAME" "$ANSIBLE_LINTER_RULES" 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
|
|
|
|
echo "ERROR! Failed to set file:[$ANSIBLE_FILE_NAME] as default!"
|
|
|
|
echo "ERROR:[$MV_CMD]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-23 10:51:13 -04:00
|
|
|
else
|
2019-10-25 12:29:31 -04:00
|
|
|
echo "Codebase does not have file:[.github/linters/$ANSIBLE_FILE_NAME], using Default rules at:[$ANSIBLE_LINTER_RULES]"
|
2019-10-22 13:21:42 -04:00
|
|
|
fi
|
2019-11-06 16:45:44 -05:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have the linter rules #
|
|
|
|
#####################################
|
|
|
|
if [ -f "$GITHUB_WORKSPACE/.github/linters/$JAVASCRIPT_FILE_NAME" ]; then
|
|
|
|
echo "User provided file:[$JAVASCRIPT_FILE_NAME], setting rules file..."
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Move users into default location #
|
|
|
|
####################################
|
|
|
|
MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/linters/$JAVASCRIPT_FILE_NAME" "$JAVASCRIPT_LINTER_RULES" 2>&1)
|
|
|
|
|
|
|
|
###################
|
|
|
|
# Load Error code #
|
|
|
|
###################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
echo "ERROR! Failed to set file:[$JAVASCRIPT_FILE_NAME] as default!"
|
|
|
|
echo "ERROR:[$MV_CMD]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Codebase does not have file:[.github/linters/$JAVASCRIPT_FILE_NAME], using Default rules at:[$JAVASCRIPT_LINTER_RULES]"
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function LintJsonFiles ####################################################
|
|
|
|
LintJsonFiles()
|
|
|
|
{
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Linting JSON files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
2019-10-22 13:21:42 -04:00
|
|
|
LINTER_NAME="jsonlint"
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#######################################
|
|
|
|
# Validate we have yamllint installed #
|
|
|
|
#######################################
|
|
|
|
# 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
|
|
|
|
echo "ERROR! Failed to find [$LINTER_NAME] in system!"
|
|
|
|
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
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
if [ ${#FILE_ARRAY_JSON[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[JSON]"
|
|
|
|
elif [ ${#FILE_ARRAY_JSON[@]} -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_JSON[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.json" 2>&1))
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
#####################
|
|
|
|
# Get the file name #
|
|
|
|
#####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# This is a node modules file
|
|
|
|
continue
|
|
|
|
fi
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
|
|
|
LINT_CMD=$("$LINTER_NAME" "$FILE" 2>&1)
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
##############################
|
|
|
|
# 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_JSON++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
2019-10-21 10:12:50 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 12:05:55 -04:00
|
|
|
#### Function LintYmlFiles #####################################################
|
|
|
|
LintYmlFiles()
|
2019-10-21 10:12:50 -04:00
|
|
|
{
|
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 "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Linting YAML files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="yamllint"
|
2019-10-21 10:12:50 -04:00
|
|
|
|
|
|
|
#######################################
|
2019-10-21 12:05:55 -04:00
|
|
|
# Validate we have yamllint installed #
|
2019-10-21 10:12:50 -04:00
|
|
|
#######################################
|
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 #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
# Failed
|
|
|
|
echo "ERROR! Failed to find [$LINTER_NAME] in system!"
|
|
|
|
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
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
if [ ${#FILE_ARRAY_YML[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[YML]"
|
|
|
|
elif [ ${#FILE_ARRAY_YML[@]} -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_YML[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f \( -name "*.yml" -or -name "*.yaml" \) 2>&1))
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
#####################
|
|
|
|
# Get the file name #
|
|
|
|
#####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
# if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# # This is a node modules file
|
|
|
|
# continue
|
|
|
|
# fi
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
|
|
|
LINT_CMD=$("$LINTER_NAME" "$YAML_LINTER_RULES" "$FILE" 2>&1)
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
##############################
|
|
|
|
# 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_YML++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function LintXmlFiles #####################################################
|
|
|
|
LintXmlFiles()
|
|
|
|
{
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Linting XML files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
2019-10-21 10:12:50 -04:00
|
|
|
|
|
|
|
######################
|
2019-10-21 12:05:55 -04:00
|
|
|
# Name of the linter #
|
2019-10-21 10:12:50 -04:00
|
|
|
######################
|
2019-10-21 12:05:55 -04:00
|
|
|
LINTER_NAME="xmllint"
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#######################################
|
|
|
|
# Validate we have yamllint installed #
|
|
|
|
#######################################
|
|
|
|
# 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 #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
# Failed
|
|
|
|
echo "ERROR! Failed to find [$LINTER_NAME] in system!"
|
|
|
|
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
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
if [ ${#FILE_ARRAY_XML[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[XML]"
|
|
|
|
elif [ ${#FILE_ARRAY_XML[@]} -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_XML[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.xml" 2>&1))
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
#####################
|
|
|
|
# Get the file name #
|
|
|
|
#####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
# if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# # This is a node modules file
|
|
|
|
# continue
|
|
|
|
# fi
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
|
|
|
LINT_CMD=$("$LINTER_NAME" "$FILE" 2>&1)
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
##############################
|
|
|
|
# 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_XML++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function LintMdFiles ######################################################
|
|
|
|
LintMdFiles()
|
|
|
|
{
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Linting Markdown files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="markdownlint"
|
2019-10-21 10:12:50 -04:00
|
|
|
|
|
|
|
#######################################
|
2019-10-21 12:05:55 -04:00
|
|
|
# Validate we have yamllint installed #
|
2019-10-21 10:12:50 -04:00
|
|
|
#######################################
|
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 #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
# Failed
|
|
|
|
echo "ERROR! Failed to find [$LINTER_NAME] in system!"
|
|
|
|
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
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
if [ ${#FILE_ARRAY_MD[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[MARKDOWN]"
|
|
|
|
elif [ ${#FILE_ARRAY_MD[@]} -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_MD[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.md" 2>&1))
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
#####################
|
|
|
|
# Get the file name #
|
|
|
|
#####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
# if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# # This is a node modules file
|
|
|
|
# continue
|
|
|
|
# fi
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
|
|
|
LINT_CMD=$("$LINTER_NAME" -c "$MD_LINTER_RULES" "$FILE" 2>&1)
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# 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_MD++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
2019-10-21 10:12:50 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 12:05:55 -04:00
|
|
|
#### Function LintBashFiles ####################################################
|
|
|
|
LintBashFiles()
|
2019-10-21 10:12:50 -04:00
|
|
|
{
|
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 "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Linting Bash files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="shellcheck"
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Validate we have shellcheck installed #
|
|
|
|
#########################################
|
|
|
|
# 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 #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
# Failed
|
|
|
|
echo "ERROR! Failed to find $LINTER_NAME in system!"
|
|
|
|
echo "ERROR:[$VALIDATE_INSTALL_CMD]"
|
2019-10-21 10:12:50 -04:00
|
|
|
exit 1
|
|
|
|
else
|
2019-10-21 12:05:55 -04:00
|
|
|
# Success
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
if [ ${#FILE_ARRAY_BASH[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[BASH]"
|
|
|
|
elif [ ${#FILE_ARRAY_BASH[@]} -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_BASH[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.sh" 2>&1))
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
# if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# # This is a node modules file
|
|
|
|
# continue
|
|
|
|
# fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Get the filename #
|
|
|
|
####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
|
|
|
LINT_CMD=$("$LINTER_NAME" "$FILE" 2>&1)
|
2019-10-21 10:12:50 -04:00
|
|
|
|
|
|
|
#######################
|
2019-10-21 12:05:55 -04:00
|
|
|
# Load the error code #
|
2019-10-21 10:12:50 -04:00
|
|
|
#######################
|
2019-10-21 12:05:55 -04:00
|
|
|
ERROR_CODE=$?
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
##############################
|
|
|
|
# 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_BASH++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
2019-10-21 10:12:50 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 12:05:55 -04:00
|
|
|
#### Function LintPythonFiles ##################################################
|
|
|
|
LintPythonFiles()
|
2019-10-21 10:12:50 -04:00
|
|
|
{
|
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 "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Linting Python files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="pylint"
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have pylint installed #
|
|
|
|
#####################################
|
|
|
|
# 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 #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
# Failed
|
|
|
|
echo "ERROR! Failed to find $LINTER_NAME in system!"
|
|
|
|
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
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
if [ ${#FILE_ARRAY_PYTHON[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[PYTHON]"
|
|
|
|
elif [ ${#FILE_ARRAY_PYTHON[@]} -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_PYTHON[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.py" 2>&1))
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
# if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# # This is a node modules file
|
|
|
|
# continue
|
|
|
|
# fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Get the filename #
|
|
|
|
####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
2019-10-21 15:12:37 -04:00
|
|
|
LINT_CMD=$("$LINTER_NAME" --rcfile "$PYTHON_LINTER_RULES" -E "$FILE" 2>&1)
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
##############################
|
|
|
|
# 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_PYTHON++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
2019-10-21 10:12:50 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 12:05:55 -04:00
|
|
|
#### Function LintPerlFiles ####################################################
|
|
|
|
LintPerlFiles()
|
2019-10-21 10:12:50 -04:00
|
|
|
{
|
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 "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Linting Perl files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="perl"
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Validate we have perl installed #
|
|
|
|
###################################
|
|
|
|
# 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 #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
# Failed
|
|
|
|
echo "ERROR! Failed to find $LINTER_NAME in system!"
|
|
|
|
echo "ERROR:[$VALIDATE_INSTALL_CMD]"
|
|
|
|
exit 1
|
2019-10-21 10:12:50 -04:00
|
|
|
else
|
|
|
|
# Success
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
if [ ${#FILE_ARRAY_PERL[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[PERL]"
|
|
|
|
elif [ ${#FILE_ARRAY_PERL[@]} -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_PERL[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.pl" 2>&1))
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
# if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# # This is a node modules file
|
|
|
|
# continue
|
|
|
|
# fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Get the filename #
|
|
|
|
####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
|
|
|
LINT_CMD=$("$LINTER_NAME" -Mstrict -cw "$FILE" 2>&1)
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# 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_PERL++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
2019-10-21 10:12:50 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 12:05:55 -04:00
|
|
|
#### Function LintRubyFiles ####################################################
|
|
|
|
LintRubyFiles()
|
2019-10-21 10:12:50 -04:00
|
|
|
{
|
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 "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Linting Ruby files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="rubocop"
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
###################################
|
|
|
|
# Validate we have perl installed #
|
|
|
|
###################################
|
|
|
|
# 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 #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
# Failed
|
|
|
|
echo "ERROR! Failed to find $LINTER_NAME in system!"
|
|
|
|
echo "ERROR:[$VALIDATE_INSTALL_CMD]"
|
|
|
|
exit 1
|
2019-10-21 10:12:50 -04:00
|
|
|
else
|
|
|
|
# Success
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
if [ ${#FILE_ARRAY_RUBY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[RUBY]"
|
|
|
|
elif [ ${#FILE_ARRAY_RUBY[@]} -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_RUBY[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.rb" 2>&1))
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
# if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# # This is a node modules file
|
|
|
|
# continue
|
|
|
|
# fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Get the filename #
|
|
|
|
####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
2019-10-21 15:12:37 -04:00
|
|
|
LINT_CMD=$("$LINTER_NAME" -c "$RUBY_LINTER_RULES" "$FILE" 2>&1)
|
2019-10-21 10:12:50 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
#########
|
|
|
|
# Error #
|
|
|
|
#########
|
|
|
|
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
|
|
|
|
echo "ERROR:[$LINT_CMD]"
|
|
|
|
# Increment error count
|
|
|
|
((ERRORS_FOUND_RUBY++))
|
2019-10-21 10:12:50 -04:00
|
|
|
else
|
2019-10-21 12:05:55 -04:00
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
done
|
2019-10-21 10:12:50 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 12:05:55 -04:00
|
|
|
#### Function LintCoffeeFiles ##################################################
|
|
|
|
LintCoffeeFiles()
|
2019-10-21 10:12:50 -04:00
|
|
|
{
|
|
|
|
################
|
2019-10-21 12:05:55 -04:00
|
|
|
# print header #
|
2019-10-21 10:12:50 -04:00
|
|
|
################
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo "Linting Coffee files..."
|
2019-10-21 15:12:37 -04:00
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="coffeelint"
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#####################################
|
|
|
|
# Validate we have pylint installed #
|
|
|
|
#####################################
|
|
|
|
# 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
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
##############################
|
|
|
|
# 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
|
2019-10-21 10:12:50 -04:00
|
|
|
else
|
2019-10-21 12:05:55 -04:00
|
|
|
# Success
|
|
|
|
echo "Successfully found binary in system"
|
|
|
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
|
|
|
fi
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
2019-10-28 12:18:05 -04:00
|
|
|
if [ ${#FILE_ARRAY_COFFEE[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[COFFEE]"
|
|
|
|
elif [ ${#FILE_ARRAY_COFFEE[@]} -ne 0 ]; then
|
2019-10-25 15:22:57 -04:00
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_COFFEE[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.coffee" 2>&1))
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
# if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# # This is a node modules file
|
|
|
|
# continue
|
|
|
|
# fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Get the filename #
|
|
|
|
####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
2019-10-21 15:12:37 -04:00
|
|
|
LINT_CMD=$("$LINTER_NAME" -f "$COFFEE_LINTER_RULES" "$FILE" 2>&1)
|
2019-10-21 10:12:50 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2019-10-21 12:05:55 -04:00
|
|
|
#########
|
|
|
|
# Error #
|
|
|
|
#########
|
|
|
|
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
|
|
|
|
echo "ERROR:[$LINT_CMD]"
|
|
|
|
# Increment error count
|
|
|
|
((ERRORS_FOUND_COFFEE++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
2019-10-21 10:12:50 -04:00
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
done
|
2019-10-21 10:12:50 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2019-11-06 16:45:44 -05:00
|
|
|
#### Function LintJavascriptFiles ##############################################
|
|
|
|
LintJavascriptFiles()
|
|
|
|
{
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-11-06 16:45:44 -05:00
|
|
|
echo "Linting JavaScript files..."
|
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-11-06 16:45:44 -05:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="eslint"
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have pylint 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
|
|
|
|
|
2019-12-13 09:06:25 -05:00
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="standard"
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Validate we have pylint 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
|
|
|
|
|
2019-11-06 16:45:44 -05:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Check to see if we need to go through array or all files #
|
|
|
|
############################################################
|
|
|
|
if [ ${#FILE_ARRAY_JAVASCRIPT[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
2019-12-03 14:47:23 -05:00
|
|
|
echo " - No files found in chageset to lint for language:[JAVASCRIPT]"
|
2019-11-06 16:45:44 -05:00
|
|
|
elif [ ${#FILE_ARRAY_JAVASCRIPT[@]} -ne 0 ]; then
|
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_JAVASCRIPT[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.js" 2>&1))
|
|
|
|
fi
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Make sure we dont lint node modules #
|
|
|
|
#######################################
|
|
|
|
if [[ $FILE == *"node_modules"* ]]; then
|
|
|
|
# This is a node modules file
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Get the filename #
|
|
|
|
####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# Lint the file with ESLint #
|
|
|
|
#############################
|
|
|
|
Eslint "$FILE"
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Lint the file with Standard #
|
|
|
|
###############################
|
|
|
|
StandardLint "$FILE"
|
|
|
|
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function Eslint ###########################################################
|
|
|
|
Eslint()
|
|
|
|
{
|
|
|
|
####################
|
|
|
|
# Pull in the file #
|
|
|
|
####################
|
|
|
|
FILE=$1
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# Get the file name #
|
|
|
|
#####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
2019-12-13 10:10:30 -05:00
|
|
|
LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; eslint --no-eslintrc -c "$JAVASCRIPT_LINTER_RULES" "$FILE" 2>&1)
|
2019-11-06 16:45:44 -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 [eslint] linter!"
|
|
|
|
echo "ERROR:[$LINT_CMD]"
|
|
|
|
# Increment error count
|
|
|
|
((ERRORS_FOUND_JAVASCRIPT++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [eslint] successfully"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function StandardLint #####################################################
|
|
|
|
StandardLint()
|
|
|
|
{
|
2019-12-12 11:53:27 -05:00
|
|
|
####################
|
|
|
|
# Pull in the file #
|
|
|
|
####################
|
|
|
|
FILE=$1
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# Get the file name #
|
|
|
|
#####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
2019-12-12 11:34:58 -05:00
|
|
|
#########################################################################
|
|
|
|
# Need to get the ENV vars from the linter rules to run in command line #
|
|
|
|
#########################################################################
|
2019-12-13 09:06:25 -05:00
|
|
|
# Copy orig IFS to var
|
|
|
|
ORIG_IFS="$IFS"
|
2019-12-12 11:34:58 -05:00
|
|
|
# Set the IFS to newline
|
|
|
|
IFS=$'\n'
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Get list of all environment variables #
|
|
|
|
#########################################
|
|
|
|
# Only env vars that are marked as true
|
2019-12-12 11:37:08 -05:00
|
|
|
# shellcheck disable=SC2207
|
2019-12-12 11:34:58 -05:00
|
|
|
GET_ENV_ARRAY=($(yq .env "$JAVASCRIPT_LINTER_RULES" |grep true))
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# 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
|
|
|
|
fi
|
|
|
|
|
2019-12-13 09:06:25 -05:00
|
|
|
##########################
|
|
|
|
# Set IFS back to normal #
|
|
|
|
##########################
|
|
|
|
# Set IFS back to Orig
|
|
|
|
IFS="$ORIG_IFS"
|
|
|
|
|
2019-12-12 11:34:58 -05:00
|
|
|
######################
|
|
|
|
# Set the env string #
|
|
|
|
######################
|
|
|
|
ENV_STRING=''
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# 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
|
2019-11-06 16:45:44 -05:00
|
|
|
|
2019-12-12 11:53:27 -05:00
|
|
|
########################################
|
|
|
|
# Remove trailing and ending witespace #
|
|
|
|
########################################
|
|
|
|
ENV_STRING="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
2019-11-06 16:45:44 -05:00
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
2019-12-12 11:53:27 -05:00
|
|
|
echo " - Utilizing Env:[$ENV_STRING]"
|
2019-12-12 14:52:47 -05:00
|
|
|
# shellcheck disable=SC2086
|
2019-12-13 08:42:16 -05:00
|
|
|
STANDARD_LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; standard $ENV_STRING "$FILE" 2>&1)
|
2019-11-06 16:45:44 -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 [js standard] linter!"
|
|
|
|
echo "ERROR:[$STANDARD_LINT_CMD]"
|
|
|
|
# Increment error count
|
|
|
|
((ERRORS_FOUND_JAVASCRIPT++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [js standard] successfully"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-25 15:22:57 -04:00
|
|
|
#### Function LintAnsibleFiles #################################################
|
|
|
|
LintAnsibleFiles()
|
|
|
|
{
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-25 15:22:57 -04:00
|
|
|
echo "Linting Ansible files..."
|
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-25 15:22:57 -04:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="ansible-lint"
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Validate we have ansible-lint 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
|
|
|
|
|
2019-12-03 14:47:23 -05:00
|
|
|
##########################
|
|
|
|
# Initialize empty Array #
|
|
|
|
##########################
|
|
|
|
LIST_FILES=()
|
|
|
|
|
2019-10-25 15:22:57 -04:00
|
|
|
######################################################
|
|
|
|
# Only go into ansible linter if we have base folder #
|
|
|
|
######################################################
|
2019-12-03 14:47:23 -05:00
|
|
|
if [ -d "$ANSIBLE_DIRECTORY" ]; then
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# 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))
|
|
|
|
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 #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
|
2019-10-31 10:59:46 -04: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
|
2019-10-25 15:22:57 -04:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Get the filename #
|
|
|
|
####################
|
2019-12-03 14:47:23 -05:00
|
|
|
FILE_NAME=$(basename "$ANSIBLE_DIRECTORY/$FILE" 2>&1)
|
2019-10-25 15:22:57 -04:00
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
2019-12-03 14:47:23 -05:00
|
|
|
LINT_CMD=$("$LINTER_NAME" -v -c "$ANSIBLE_LINTER_RULES" "$ANSIBLE_DIRECTORY/$FILE" 2>&1)
|
2019-10-25 15:22:57 -04: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 #
|
|
|
|
########################
|
2019-12-03 14:47:23 -05:00
|
|
|
echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIRECTORY]"
|
2019-10-25 15:22:57 -04:00
|
|
|
echo "skipping ansible lint"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
################################################################################
|
2020-01-09 17:08:01 -05:00
|
|
|
#### Function LintDockerFiles ####################################################
|
|
|
|
LintDockerFiles()
|
|
|
|
{
|
|
|
|
################
|
|
|
|
# print header #
|
|
|
|
################
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "Linting Dockerfiles..."
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo "----------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Name of the linter #
|
|
|
|
######################
|
|
|
|
LINTER_NAME="dockerfilelint"
|
2020-01-09 20:08:31 -05:00
|
|
|
LINTER_PATH="/node_modules/dockerfilelint/bin/dockerfilelint"
|
2020-01-09 17:08:01 -05:00
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Validate we have shellcheck installed #
|
|
|
|
#########################################
|
|
|
|
# shellcheck disable=SC2230
|
|
|
|
VALIDATE_INSTALL_CMD=$(command -v "$LINTER_PATH" 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_DOCKER[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
# No files found in commit and user has asked to not validate code base
|
|
|
|
echo " - No files found in chageset to lint for language:[DOCKERFILE]"
|
|
|
|
elif [ ${#FILE_ARRAY_DOCKER[@]} -ne 0 ]; then
|
|
|
|
# We have files added to array of files to check
|
|
|
|
LIST_FILES=("${FILE_ARRAY_DOCKER[@]}") # Copy the array into list
|
|
|
|
else
|
|
|
|
#################################
|
|
|
|
# Get list of all files to lint #
|
|
|
|
#################################
|
|
|
|
# shellcheck disable=SC2207
|
|
|
|
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "Dockerfile" 2>&1))
|
|
|
|
fi
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Lint the files #
|
|
|
|
##################
|
|
|
|
for FILE in "${LIST_FILES[@]}"
|
|
|
|
do
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Get the filename #
|
|
|
|
####################
|
|
|
|
FILE_NAME=$(basename "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##############
|
|
|
|
# File print #
|
|
|
|
##############
|
|
|
|
echo "---------------------------"
|
|
|
|
echo "File:[$FILE]"
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Lint the file with the rules #
|
|
|
|
################################
|
2020-01-09 20:08:31 -05:00
|
|
|
LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; "$LINTER_PATH" "$FILE" 2>&1)
|
2020-01-09 17:08:01 -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_DOCKER++))
|
|
|
|
else
|
|
|
|
###########
|
|
|
|
# Success #
|
|
|
|
###########
|
|
|
|
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
2019-10-21 15:12:37 -04:00
|
|
|
#### Function GetGitHubVars ####################################################
|
|
|
|
GetGitHubVars()
|
|
|
|
{
|
|
|
|
##########
|
|
|
|
# Prints #
|
|
|
|
##########
|
|
|
|
echo "--------------------------------------------"
|
|
|
|
echo "Gathering GitHub information..."
|
|
|
|
|
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)}')
|
|
|
|
#################################
|
|
|
|
# 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
|
2019-10-25 12:29:31 -04:00
|
|
|
|
|
|
|
############################################
|
|
|
|
# Print headers for user provided env vars #
|
|
|
|
############################################
|
|
|
|
echo ""
|
|
|
|
echo "--------------------------------------------"
|
|
|
|
echo "Gathering User provided information..."
|
|
|
|
|
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 #
|
|
|
|
###############################
|
|
|
|
VALIDATE_JAVASCRIPT=$(echo "$VALIDATE_JAVASCRIPT" | awk '{print tolower($0)}')
|
|
|
|
######################################
|
|
|
|
# Validate we should check all files #
|
|
|
|
######################################
|
|
|
|
if [[ "$VALIDATE_JAVASCRIPT" != "false" ]]; then
|
|
|
|
# Set to true
|
|
|
|
VALIDATE_JAVASCRIPT="$DEFAULT_VALIDATE_LANGUAGE"
|
|
|
|
echo "- Validating [JAVASCRIPT] files in code base..."
|
|
|
|
else
|
|
|
|
# Its false
|
|
|
|
echo "- Excluding [JAVASCRIPT] files in code base..."
|
|
|
|
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
|
|
|
|
|
|
|
|
|
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
|
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 #
|
|
|
|
################
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "Pulling in code history and branches..."
|
2019-10-28 12:18:05 -04:00
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Switch codebase back to master to get a list of all files changed #
|
|
|
|
#####################################################################
|
2019-12-03 16:01:33 -05:00
|
|
|
SWITCH_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git pull; 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 #
|
|
|
|
################
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------"
|
2019-12-03 15:00:38 -05:00
|
|
|
echo "Generating Diff with:[git diff --name-only 'master..$GITHUB_SHA' --diff-filter=d]"
|
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 #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_COFFEE+=("$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 #
|
|
|
|
################################
|
|
|
|
FILE_ARRAY_JAVASCRIPT+=("$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-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
|
|
|
|
############################
|
|
|
|
# Extension was not found! #
|
|
|
|
############################
|
2019-12-06 08:51:40 -05:00
|
|
|
echo " - WARN! Failed to get filetype for:[$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
|
|
|
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
|
|
|
}
|
|
|
|
################################################################################
|
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 "----------------------------------------------"
|
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]"
|
|
|
|
echo "ERRORS FOUND IN MD:[$ERRORS_FOUND_MD]"
|
|
|
|
echo "ERRORS FOUND in BASH:[$ERRORS_FOUND_BASH]"
|
|
|
|
echo "ERRORS FOUND in PERL:[$ERRORS_FOUND_PERL]"
|
|
|
|
echo "ERRORS FOUND in PYTHON:[$ERRORS_FOUND_PYTHON]"
|
2019-10-25 12:29:31 -04:00
|
|
|
echo "ERRORS FOUND in COFFEE:[$ERRORS_FOUND_COFFEE]"
|
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]"
|
2019-11-06 16:45:44 -05:00
|
|
|
echo "ERRORS FOUND in JAVASCRIPT:[$ERRORS_FOUND_JAVASCRIPT]"
|
2020-01-09 17:08:01 -05:00
|
|
|
echo "ERRORS FOUND in DOCKER:[$ERRORS_FOUND_DOCKER]"
|
2019-12-06 08:51:40 -05:00
|
|
|
echo "----------------------------------------------"
|
2019-10-21 12:05:55 -04:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Exit with 1 if errors found #
|
|
|
|
###############################
|
2019-10-21 15:12:37 -04:00
|
|
|
if [ $ERRORS_FOUND_YML -ne 0 ] || \
|
|
|
|
[ $ERRORS_FOUND_JSON -ne 0 ] || \
|
|
|
|
[ $ERRORS_FOUND_XML -ne 0 ] || \
|
|
|
|
[ $ERRORS_FOUND_MD -ne 0 ] || \
|
|
|
|
[ $ERRORS_FOUND_BASH -ne 0 ] || \
|
|
|
|
[ $ERRORS_FOUND_PERL -ne 0 ] || \
|
|
|
|
[ $ERRORS_FOUND_PYTHON -ne 0 ] || \
|
2019-10-25 12:29:31 -04:00
|
|
|
[ $ERRORS_FOUND_COFFEE -ne 0 ] || \
|
2019-10-22 13:21:42 -04:00
|
|
|
[ $ERRORS_FOUND_ANSIBLE -ne 0 ] || \
|
2019-11-06 16:45:44 -05:00
|
|
|
[ $ERRORS_FOUND_JAVASCRIPT -ne 0 ] || \
|
2020-01-09 17:08:01 -05:00
|
|
|
[ $ERRORS_FOUND_DOCKER -ne 0 ] || \
|
2019-10-21 15:12:37 -04:00
|
|
|
[ $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
|
|
|
|
}
|
|
|
|
################################################################################
|
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
|
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
########################
|
|
|
|
# Get the linter rules #
|
|
|
|
########################
|
|
|
|
GetLinterRules
|
|
|
|
|
2020-01-08 14:34:05 -05:00
|
|
|
##################################
|
|
|
|
# Get and print all version info #
|
|
|
|
##################################
|
|
|
|
GetLinterVersions
|
|
|
|
|
2019-10-25 12:29:31 -04:00
|
|
|
########################################
|
|
|
|
# Get list of files changed if env set #
|
|
|
|
########################################
|
|
|
|
if [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
|
|
|
|
BuildFileList
|
|
|
|
fi
|
2019-10-21 15:12:37 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
######################
|
|
|
|
# Lint the Yml Files #
|
|
|
|
######################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_YAML" == "true" ]; then
|
|
|
|
LintYmlFiles
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2019-10-21 10:12:50 -04:00
|
|
|
#######################
|
2019-10-21 12:05:55 -04:00
|
|
|
# Lint the json files #
|
2019-10-21 10:12:50 -04:00
|
|
|
#######################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_JSON" == "true" ]; then
|
|
|
|
LintJsonFiles
|
|
|
|
fi
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
######################
|
|
|
|
# Lint the XML Files #
|
|
|
|
######################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_XML" == "true" ]; then
|
|
|
|
LintXmlFiles
|
|
|
|
fi
|
2019-10-21 10:12:50 -04:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
###########################
|
|
|
|
# Lint the Markdown Files #
|
|
|
|
###########################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_MD" == "true" ]; then
|
|
|
|
LintMdFiles
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Lint the bash files #
|
|
|
|
#######################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_BASH" == "true" ]; then
|
|
|
|
LintBashFiles
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
#########################
|
|
|
|
# Lint the python files #
|
|
|
|
#########################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_PYTHON" == "true" ]; then
|
|
|
|
LintPythonFiles
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Lint the perl files #
|
|
|
|
#######################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_PERL" == "true" ]; then
|
|
|
|
LintPerlFiles
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Lint the ruby files #
|
|
|
|
#######################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_RUBY" == "true" ]; then
|
|
|
|
LintRubyFiles
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
|
|
|
#########################
|
|
|
|
# Lint the coffee files #
|
|
|
|
#########################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_COFFEE" == "true" ]; then
|
|
|
|
LintCoffeeFiles
|
|
|
|
fi
|
2019-10-21 12:05:55 -04:00
|
|
|
|
2019-10-22 13:21:42 -04:00
|
|
|
##########################
|
|
|
|
# Lint the Ansible files #
|
|
|
|
##########################
|
2019-10-25 12:29:31 -04:00
|
|
|
if [ "$VALIDATE_ANSIBLE" == "true" ]; then
|
|
|
|
LintAnsibleFiles
|
|
|
|
fi
|
2019-10-22 13:21:42 -04:00
|
|
|
|
2019-11-06 16:45:44 -05:00
|
|
|
#############################
|
|
|
|
# Lint the Javascript files #
|
|
|
|
#############################
|
|
|
|
if [ "$VALIDATE_JAVASCRIPT" == "true" ]; then
|
|
|
|
LintJavascriptFiles
|
|
|
|
fi
|
|
|
|
|
2020-01-09 17:08:01 -05:00
|
|
|
#############################
|
|
|
|
# Lint the Dockerfiles #
|
|
|
|
#############################
|
|
|
|
if [ "$VALIDATE_DOCKER" == "true" ]; then
|
|
|
|
LintDockerFiles
|
|
|
|
fi
|
|
|
|
|
2019-11-06 16:45:44 -05:00
|
|
|
|
2019-10-21 12:05:55 -04:00
|
|
|
##########
|
|
|
|
# Footer #
|
|
|
|
##########
|
|
|
|
Footer
|