Adding the verbosity check

This commit is contained in:
Lucas Gravley 2020-04-27 12:46:05 -05:00
parent 27dd6e71a0
commit 2a16b17bda

View file

@ -339,15 +339,20 @@ GetStandardRules()
#### Function LintAnsibleFiles ################################################# #### Function LintAnsibleFiles #################################################
LintAnsibleFiles() LintAnsibleFiles()
{ {
######################
# Create Print Array #
######################
PRINT_ARRAY=()
################ ################
# print header # # print header #
################ ################
echo "" PRINT_ARRAY+=("")
echo "----------------------------------------------" PRINT_ARRAY+=("----------------------------------------------")
echo "----------------------------------------------" PRINT_ARRAY+=("----------------------------------------------")
echo "Linting [Ansible] files..." PRINT_ARRAY+=("Linting [Ansible] files...")
echo "----------------------------------------------" PRINT_ARRAY+=("----------------------------------------------")
echo "----------------------------------------------" PRINT_ARRAY+=("----------------------------------------------")
###################### ######################
# Name of the linter # # Name of the linter #
@ -387,6 +392,11 @@ LintAnsibleFiles()
########################## ##########################
LIST_FILES=() LIST_FILES=()
#######################
# Create flag to skip #
#######################
SKIP_FLAG=0
###################################################### ######################################################
# Only go into ansible linter if we have base folder # # Only go into ansible linter if we have base folder #
###################################################### ######################################################
@ -420,7 +430,24 @@ LintAnsibleFiles()
################################### ###################################
# Send message that were skipping # # Send message that were skipping #
################################### ###################################
echo "- Skipping Ansible lint run as file(s) that were modified were read only..." #echo "- Skipping Ansible lint run as file(s) that were modified were read only..."
############################
# Create flag to skip loop #
############################
SKIP_FLAG=1
fi
####################################
# Check if we have data to look at #
####################################
if [ $SKIP_FLAG -eq 0 ]; then
for LINE in "${PRINT_ARRAY[@]}"
do
#########################
# Print the header line #
#########################
echo "$LINE"
done
fi fi
################## ##################
@ -476,12 +503,17 @@ LintAnsibleFiles()
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
fi fi
done done
else else # No ansible directory found in path
######################## ###############################
# No Ansible dir found # # Check to see if debug is on #
######################## ###############################
echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIRECTORY]" if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then
echo "skipping ansible lint" ########################
# No Ansible dir found #
########################
echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIRECTORY]"
echo "skipping ansible lint"
fi
fi fi
} }
################################################################################ ################################################################################
@ -1316,15 +1348,20 @@ LintCodebase()
FILE_EXTENSIONS="$1" && shift # Pull the variable and remove from array path (Example: *.json) FILE_EXTENSIONS="$1" && shift # Pull the variable and remove from array path (Example: *.json)
FILE_ARRAY=("$@") # Array of files to validate (Example: $FILE_ARRAY_JSON) FILE_ARRAY=("$@") # Array of files to validate (Example: $FILE_ARRAY_JSON)
######################
# Create Print Array #
######################
PRINT_ARRAY=()
################ ################
# print header # # print header #
################ ################
echo "" PRINT_ARRAY+=("")
echo "----------------------------------------------" PRINT_ARRAY+=("----------------------------------------------")
echo "----------------------------------------------" PRINT_ARRAY+=("----------------------------------------------")
echo "Linting [$FILE_TYPE] files..." PRINT_ARRAY+=("Linting [$FILE_TYPE] files...")
echo "----------------------------------------------" PRINT_ARRAY+=("----------------------------------------------")
echo "----------------------------------------------" PRINT_ARRAY+=("----------------------------------------------")
####################################### #######################################
# Validate we have jsonlint installed # # Validate we have jsonlint installed #
@ -1347,8 +1384,10 @@ LintCodebase()
exit 1 exit 1
else else
# Success # Success
echo "Successfully found binary in system" if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then
echo "Location:[$VALIDATE_INSTALL_CMD]" echo "Successfully found binary in system"
echo "Location:[$VALIDATE_INSTALL_CMD]"
fi
fi fi
########################## ##########################
@ -1356,12 +1395,18 @@ LintCodebase()
########################## ##########################
LIST_FILES=() LIST_FILES=()
################
# Set the flag #
################
SKIP_FLAG=0
############################################################ ############################################################
# Check to see if we need to go through array or all files # # Check to see if we need to go through array or all files #
############################################################ ############################################################
if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
# No files found in commit and user has asked to not validate code base # No files found in commit and user has asked to not validate code base
echo " - No files found in chageset to lint for language:[$FILE_TYPE]" SKIP_FLAG=1
# echo " - No files found in chageset to lint for language:[$FILE_TYPE]"
elif [ ${#FILE_ARRAY[@]} -ne 0 ]; then elif [ ${#FILE_ARRAY[@]} -ne 0 ]; then
# We have files added to array of files to check # We have files added to array of files to check
LIST_FILES=("${FILE_ARRAY[@]}") # Copy the array into list LIST_FILES=("${FILE_ARRAY[@]}") # Copy the array into list
@ -1373,61 +1418,74 @@ LintCodebase()
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex "$FILE_EXTENSIONS" 2>&1)) LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex "$FILE_EXTENSIONS" 2>&1))
fi fi
################## if [ $SKIP_FLAG -eq 0 ]; then
# Lint the files # ######################
################## # Print Header array #
for FILE in "${LIST_FILES[@]}" ######################
do for LINE in "${PRINT_ARRAY[@]}"
##################### do
# Get the file name # #########################
##################### # Print the header info #
FILE_NAME=$(basename "$FILE" 2>&1) #########################
echo "$LINE"
done
##################################################### ##################
# Make sure we dont lint node modules or test cases # # Lint the files #
##################################################### ##################
if [[ $FILE == *"node_modules"* ]]; then for FILE in "${LIST_FILES[@]}"
# This is a node modules file do
continue #####################
elif [[ $FILE == *"$TEST_CASE_FOLDER"* ]]; then # Get the file name #
# This is the test cases, we should always skip #####################
continue FILE_NAME=$(basename "$FILE" 2>&1)
fi
############## #####################################################
# File print # # Make sure we dont lint node modules or test cases #
############## #####################################################
echo "---------------------------" if [[ $FILE == *"node_modules"* ]]; then
echo "File:[$FILE]" # This is a node modules file
continue
elif [[ $FILE == *"$TEST_CASE_FOLDER"* ]]; then
# This is the test cases, we should always skip
continue
fi
################################ ##############
# Lint the file with the rules # # File print #
################################ ##############
LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) echo "---------------------------"
echo "File:[$FILE]"
####################### ################################
# Load the error code # # Lint the file with the rules #
####################### ################################
ERROR_CODE=$? LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1)
############################## #######################
# Check the shell for errors # # Load the error code #
############################## #######################
if [ $ERROR_CODE -ne 0 ]; then ERROR_CODE=$?
#########
# Error # ##############################
######### # Check the shell for errors #
echo "ERROR! Found errors in [$LINTER_NAME] linter!" ##############################
echo "ERROR:[$LINT_CMD]" if [ $ERROR_CODE -ne 0 ]; then
# Increment the error count #########
(("ERRORS_FOUND_$FILE_TYPE++")) # Error #
else #########
########### echo "ERROR! Found errors in [$LINTER_NAME] linter!"
# Success # echo "ERROR:[$LINT_CMD]"
########### # Increment the error count
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" (("ERRORS_FOUND_$FILE_TYPE++"))
fi else
done ###########
# Success #
###########
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
fi
done
fi
} }
################################################################################ ################################################################################
#### Function TestCodebase ##################################################### #### Function TestCodebase #####################################################