From 1e768c20f77f982cb17a8188d88f8e5582a4bb1e Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 12:03:37 -0500 Subject: [PATCH 01/12] adding flag --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 00d8c660..c5340d85 100644 --- a/Dockerfile +++ b/Dockerfile @@ -118,7 +118,8 @@ ENV GITHUB_SHA=${GITHUB_SHA} \ VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \ ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \ RUN_LOCAL=${RUN_LOCAL} \ - TEST_CASE_RUN=${TEST_CASE_RUN} + TEST_CASE_RUN=${TEST_CASE_RUN} \ + ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} ############################# # Copy scripts to container # From b616dafd41652195b5cf0f13b67117b049fe6c32 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 12:21:38 -0500 Subject: [PATCH 02/12] Cleanup of linter rules prints: --- README.md | 4 +-- {.github => docs}/run-linter-locally.md | 4 +++ lib/linter.sh | 45 +++++++++++++++---------- 3 files changed, 33 insertions(+), 20 deletions(-) rename {.github => docs}/run-linter-locally.md (97%) diff --git a/README.md b/README.md index 3c50cce7..edee40f7 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ The super-linter allows you to pass the following `ENV` variables to be able to - **VALIDATE_TERRAFORM** - Default: `true` - Flag to enable or disable the linting process of the language -- **VERBOSE_OUTPUT** +- **ACTIONS_RUNNER_DEBUG** - Default: `false` - Flag to enable additional information about the linter, versions, and additional output @@ -161,7 +161,7 @@ If you need to disable certain *rules* and *functionality*, you can view [Disabl The **Docker** container that is built from this repository is located at `https://cloud.docker.com/u/admiralawkbar/repository/docker/admiralawkbar/super-linter` ## Running Super-Linter locally (troubleshooting/debugging/enhancements) -If you find that you need to run super-linter locally, you can follow the documentation at [Running super-linter locally](https://github.com/github/super-linter/blob/master/.github/run-linter-locally.md) +If you find that you need to run super-linter locally, you can follow the documentation at [Running super-linter locally](https://github.com/github/super-linter/blob/master/docs/run-linter-locally.md) ### CI/CT/CD The **Super-Linter** has *CI/CT/CD* configured utilizing **GitHub** Actions. diff --git a/.github/run-linter-locally.md b/docs/run-linter-locally.md similarity index 97% rename from .github/run-linter-locally.md rename to docs/run-linter-locally.md index 4ebd60b2..4bfdee18 100644 --- a/.github/run-linter-locally.md +++ b/docs/run-linter-locally.md @@ -94,6 +94,10 @@ Once the container has been downloaded to your local environment, you can then b - `-e ANSIBLE_DIRECTORY=` - Default: `/ansible` - Flag to set the root directory for Ansible file location(s) + - **ACTIONS_RUNNER_DEBUG** + - `-e ACTIONS_RUNNER_DEBUG=` + - Default: `false` + - Flag to enable or disable additional debug info ## Troubleshooting diff --git a/lib/linter.sh b/lib/linter.sh index e044b22b..635938c9 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -85,8 +85,8 @@ TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only ############## # Debug Vars # ############## -RUN_LOCAL="${RUN_LOCAL}" # Boolean to see if we are running locally -VERBOSE_OUTPUT="${VERBOSE_OUTPUT}" # Boolean to see even more info (debug) +RUN_LOCAL="${RUN_LOCAL}" # Boolean to see if we are running locally +ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG}" # Boolean to see even more info (debug) ################ # Default Vars # @@ -97,7 +97,7 @@ DEFAULT_WORKSPACE='/tmp/lint' # Default workspace if run DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory DEFAULT_RUN_LOCAL='false' # Default value for debugging locally DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases -DEFAULT_VERBOSE_OUTPUT='false' # Default value for debugging output +DEFAULT_ACTIONS_RUNNER_DEBUG='false' # Default value for debugging output RAW_FILE_ARRAY=() # Array of all files that were changed READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore @@ -219,16 +219,11 @@ GetLinterRules() FILE_NAME="$1" # Name fo the linter file FILE_LOCATION="$2" # Location of the linter file - ################ - # print header # - ################ - echo "----------------------------------------------" - echo "Gathering users linter:[$FILE_NAME] rules from repository, or defaulting..." - ##################################### # Validate we have the linter rules # ##################################### if [ -f "$GITHUB_WORKSPACE/$LINTER_PATH/$FILE_NAME" ]; then + echo "----------------------------------------------" echo "User provided file:[$FILE_NAME], setting rules file..." #################################### @@ -253,7 +248,9 @@ GetLinterRules() ######################################################## # No user default provided, using the template default # ######################################################## - echo " -> Codebase does NOT have file:[$LINTER_PATH/$FILE_NAME], using Default rules at:[$FILE_LOCATION]" + if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + echo " -> Codebase does NOT have file:[$LINTER_PATH/$FILE_NAME], using Default rules at:[$FILE_LOCATION]" + fi fi } ################################################################################ @@ -378,7 +375,7 @@ LintAnsibleFiles() exit 1 else # Success - if [[ "$VERBOSE_OUTPUT" != "false" ]]; then + if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then # Success echo "Successfully found binary in system" echo "Location:[$VALIDATE_INSTALL_CMD]" @@ -624,13 +621,17 @@ GetGitHubVars() echo "Successfully found:[GITHUB_REPO], value:[$GITHUB_REPO]" fi fi - +} +################################################################################ +#### Function GetValidationInfo ################################################ +GetValidationInfo() +{ ############################################ # Print headers for user provided env vars # ############################################ echo "" echo "--------------------------------------------" - echo "Gathering User provided information..." + echo "Gathering user validation information..." ########################################### # Skip validation if were running locally # @@ -946,22 +947,22 @@ GetGitHubVars() ############################ # Get the run verbose flag # ############################ - if [ -z "$VERBOSE_OUTPUT" ]; then + if [ -z "$ACTIONS_RUNNER_DEBUG" ]; then ################################## # No flag passed, set to default # ################################## - VERBOSE_OUTPUT="$DEFAULT_VERBOSE_OUTPUT" + ACTIONS_RUNNER_DEBUG="$DEFAULT_ACTIONS_RUNNER_DEBUG" fi ############################### # Convert string to lowercase # ############################### - VERBOSE_OUTPUT=$(echo "$VERBOSE_OUTPUT" | awk '{print tolower($0)}') + ACTIONS_RUNNER_DEBUG=$(echo "$ACTIONS_RUNNER_DEBUG" | awk '{print tolower($0)}') ################### # Debug on runner # ################### - if [[ "$VERBOSE_OUTPUT" != "false" ]]; then + if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then echo "--- DEBUG ---" echo "---------------------------------------------" RUNNER=$(whoami) @@ -1749,6 +1750,14 @@ Header # needed to connect back and update checks GetGitHubVars +########################################## +# Get the langugages we need to validate # +########################################## +if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + # Get the flags for langugaes to validate + GetValidationInfo +fi + ######################## # Get the linter rules # ######################## @@ -1778,7 +1787,7 @@ GetLinterRules "$TERRAFORM_FILE_NAME" "$TERRAFORM_LINTER_RULES" ################################# # Check if were in verbose mode # ################################# -if [[ "$VERBOSE_OUTPUT" != "false" ]]; then +if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then ################################## # Get and print all version info # ################################## From 27dd6e71a03e7c717027936677bdcea4bff25df5 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 12:27:41 -0500 Subject: [PATCH 03/12] Cleanup git pull data --- lib/linter.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 635938c9..c3a371ab 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -982,14 +982,16 @@ BuildFileList() ################ # print header # ################ - echo "" - echo "----------------------------------------------" - echo "Pulling in code history and branches..." + if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + echo "" + echo "----------------------------------------------" + echo "Pulling in code history and branches..." + fi ##################################################################### # Switch codebase back to master to get a list of all files changed # ##################################################################### - SWITCH_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git pull; git checkout master 2>&1) + SWITCH_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git pull --quiet; git checkout master 2>&1) ####################### # Load the error code # @@ -1009,9 +1011,11 @@ BuildFileList() ################ # print header # ################ - echo "" - echo "----------------------------------------------" - echo "Generating Diff with:[git diff --name-only 'master..$GITHUB_SHA' --diff-filter=d]" + if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + echo "" + echo "----------------------------------------------" + echo "Generating Diff with:[git diff --name-only 'master..$GITHUB_SHA' --diff-filter=d]" + fi ################################################ # Get the Array of files changed in the comits # From 2a16b17bda929740969d66a140ef393914745230 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 12:46:05 -0500 Subject: [PATCH 04/12] Adding the verbosity check --- lib/linter.sh | 202 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 130 insertions(+), 72 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index c3a371ab..65488a4b 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -339,15 +339,20 @@ GetStandardRules() #### Function LintAnsibleFiles ################################################# LintAnsibleFiles() { + ###################### + # Create Print Array # + ###################### + PRINT_ARRAY=() + ################ # print header # ################ - echo "" - echo "----------------------------------------------" - echo "----------------------------------------------" - echo "Linting [Ansible] files..." - echo "----------------------------------------------" - echo "----------------------------------------------" + PRINT_ARRAY+=("") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("Linting [Ansible] files...") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") ###################### # Name of the linter # @@ -387,6 +392,11 @@ LintAnsibleFiles() ########################## LIST_FILES=() + ####################### + # Create flag to skip # + ####################### + SKIP_FLAG=0 + ###################################################### # Only go into ansible linter if we have base folder # ###################################################### @@ -420,7 +430,24 @@ LintAnsibleFiles() ################################### # 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 ################## @@ -476,12 +503,17 @@ LintAnsibleFiles() echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" fi done - else - ######################## - # No Ansible dir found # - ######################## - echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIRECTORY]" - echo "skipping ansible lint" + else # No ansible directory found in path + ############################### + # Check to see if debug is on # + ############################### + if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + ######################## + # No Ansible dir found # + ######################## + echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIRECTORY]" + echo "skipping ansible lint" + fi fi } ################################################################################ @@ -1316,15 +1348,20 @@ LintCodebase() 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) + ###################### + # Create Print Array # + ###################### + PRINT_ARRAY=() + ################ # print header # ################ - echo "" - echo "----------------------------------------------" - echo "----------------------------------------------" - echo "Linting [$FILE_TYPE] files..." - echo "----------------------------------------------" - echo "----------------------------------------------" + PRINT_ARRAY+=("") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("Linting [$FILE_TYPE] files...") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") ####################################### # Validate we have jsonlint installed # @@ -1347,8 +1384,10 @@ LintCodebase() exit 1 else # Success - echo "Successfully found binary in system" - echo "Location:[$VALIDATE_INSTALL_CMD]" + if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + echo "Successfully found binary in system" + echo "Location:[$VALIDATE_INSTALL_CMD]" + fi fi ########################## @@ -1356,12 +1395,18 @@ LintCodebase() ########################## LIST_FILES=() + ################ + # Set the flag # + ################ + SKIP_FLAG=0 + ############################################################ # Check to see if we need to go through array or all files # ############################################################ if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then # No files found in commit and user has asked to not validate code base - 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 # We have files added to array of files to check 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)) fi - ################## - # Lint the files # - ################## - for FILE in "${LIST_FILES[@]}" - do - ##################### - # Get the file name # - ##################### - FILE_NAME=$(basename "$FILE" 2>&1) + if [ $SKIP_FLAG -eq 0 ]; then + ###################### + # Print Header array # + ###################### + for LINE in "${PRINT_ARRAY[@]}" + do + ######################### + # Print the header info # + ######################### + echo "$LINE" + done - ##################################################### - # Make sure we dont lint node modules or test cases # - ##################################################### - if [[ $FILE == *"node_modules"* ]]; then - # 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 files # + ################## + for FILE in "${LIST_FILES[@]}" + do + ##################### + # Get the file name # + ##################### + FILE_NAME=$(basename "$FILE" 2>&1) - ############## - # File print # - ############## - echo "---------------------------" - echo "File:[$FILE]" + ##################################################### + # Make sure we dont lint node modules or test cases # + ##################################################### + if [[ $FILE == *"node_modules"* ]]; then + # 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 # - ################################ - LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) + ############## + # File print # + ############## + echo "---------------------------" + echo "File:[$FILE]" - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) - ############################## - # Check the shell for errors # - ############################## - if [ $ERROR_CODE -ne 0 ]; then - ######### - # Error # - ######### - echo "ERROR! Found errors in [$LINTER_NAME] linter!" - echo "ERROR:[$LINT_CMD]" - # Increment the error count - (("ERRORS_FOUND_$FILE_TYPE++")) - else - ########### - # Success # - ########### - echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" - fi - done + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -ne 0 ]; then + ######### + # Error # + ######### + echo "ERROR! Found errors in [$LINTER_NAME] linter!" + echo "ERROR:[$LINT_CMD]" + # Increment the error count + (("ERRORS_FOUND_$FILE_TYPE++")) + else + ########### + # Success # + ########### + echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" + fi + done + fi } ################################################################################ #### Function TestCodebase ##################################################### From 0d31bcda2cb173291c1c0305171cd2d2ce152f78 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 13:20:35 -0500 Subject: [PATCH 05/12] More logic --- lib/linter.sh | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 65488a4b..d7cc9ac3 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -102,7 +102,6 @@ RAW_FILE_ARRAY=() # Array of all files that READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore - ########################## # Array of changed files # ########################## @@ -248,7 +247,7 @@ GetLinterRules() ######################################################## # No user default provided, using the template default # ######################################################## - if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then echo " -> Codebase does NOT have file:[$LINTER_PATH/$FILE_NAME], using Default rules at:[$FILE_LOCATION]" fi fi @@ -380,7 +379,7 @@ LintAnsibleFiles() exit 1 else # Success - if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then # Success echo "Successfully found binary in system" echo "Location:[$VALIDATE_INSTALL_CMD]" @@ -507,7 +506,7 @@ LintAnsibleFiles() ############################### # Check to see if debug is on # ############################### - if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then ######################## # No Ansible dir found # ######################## @@ -991,10 +990,17 @@ GetValidationInfo() ############################### ACTIONS_RUNNER_DEBUG=$(echo "$ACTIONS_RUNNER_DEBUG" | awk '{print tolower($0)}') + ############################ + # Set to true if not false # + ############################ + if [ "$ACTIONS_RUNNER_DEBUG" != "false" ]; then + ACTIONS_RUNNER_DEBUG="true" + fi + ################### # Debug on runner # ################### - if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then echo "--- DEBUG ---" echo "---------------------------------------------" RUNNER=$(whoami) @@ -1014,7 +1020,7 @@ BuildFileList() ################ # print header # ################ - if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then echo "" echo "----------------------------------------------" echo "Pulling in code history and branches..." @@ -1043,7 +1049,7 @@ BuildFileList() ################ # print header # ################ - if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then echo "" echo "----------------------------------------------" echo "Generating Diff with:[git diff --name-only 'master..$GITHUB_SHA' --diff-filter=d]" @@ -1384,7 +1390,7 @@ LintCodebase() exit 1 else # Success - if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then + if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then echo "Successfully found binary in system" echo "Location:[$VALIDATE_INSTALL_CMD]" fi @@ -1815,7 +1821,7 @@ GetGitHubVars ########################################## # Get the langugages we need to validate # ########################################## -if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then +if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then # Get the flags for langugaes to validate GetValidationInfo fi @@ -1849,7 +1855,7 @@ GetLinterRules "$TERRAFORM_FILE_NAME" "$TERRAFORM_LINTER_RULES" ################################# # Check if were in verbose mode # ################################# -if [[ "$ACTIONS_RUNNER_DEBUG" != "false" ]]; then +if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then ################################## # Get and print all version info # ################################## From 1c6d7364d298040f31dc58d12a379a8a382e00dd Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 13:29:02 -0500 Subject: [PATCH 06/12] Fixing logic for empty array --- lib/linter.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/linter.sh b/lib/linter.sh index d7cc9ac3..353b882b 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1422,6 +1422,13 @@ LintCodebase() ################################# # shellcheck disable=SC2207,SC2086 LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex "$FILE_EXTENSIONS" 2>&1)) + + ############################################################ + # Set it back to empty if loaded with blanks from scanning # + ############################################################ + if [ ${#LIST_FILES[@]} -lt 1 ]; then + LIST_FILES=() + fi fi if [ $SKIP_FLAG -eq 0 ]; then From 97c264ca8bbe8fd6923407776491e23eca27a7d3 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 13:47:11 -0500 Subject: [PATCH 07/12] fixed more logic issues --- lib/linter.sh | 88 ++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 353b882b..00511ab2 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -685,6 +685,11 @@ GetValidationInfo() fi fi + ###################### + # Create Print Array # + ###################### + PRINT_ARRAY=() + ############################### # Convert string to lowercase # ############################### @@ -695,10 +700,10 @@ GetValidationInfo() if [[ "$VALIDATE_YAML" != "false" ]]; then # Set to true VALIDATE_YAML="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [YML] files in code base..." + PRINT_ARRAY+=("- Validating [YML] files in code base...") else # Its false - echo "- Excluding [YML] files in code base..." + PRINT_ARRAY+=("- Excluding [YML] files in code base...") fi ############################### @@ -711,10 +716,10 @@ GetValidationInfo() if [[ "$VALIDATE_JSON" != "false" ]]; then # Set to true VALIDATE_JSON="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [JSON] files in code base..." + PRINT_ARRAY+=("- Validating [JSON] files in code base...") else # Its false - echo "- Excluding [JSON] files in code base..." + PRINT_ARRAY+=("- Excluding [JSON] files in code base...") fi ############################### @@ -727,10 +732,10 @@ GetValidationInfo() if [[ "$VALIDATE_XML" != "false" ]]; then # Set to true VALIDATE_XML="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [XML] files in code base..." + PRINT_ARRAY+=("- Validating [XML] files in code base...") else # Its false - echo "- Excluding [XML] files in code base..." + PRINT_ARRAY+=("- Excluding [XML] files in code base...") fi ############################### @@ -743,10 +748,10 @@ GetValidationInfo() if [[ "$VALIDATE_MD" != "false" ]]; then # Set to true VALIDATE_MD="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [MARKDOWN] files in code base..." + PRINT_ARRAY+=("- Validating [MARKDOWN] files in code base...") else # Its false - echo "- Excluding [MARKDOWN] files in code base..." + PRINT_ARRAY+=("- Excluding [MARKDOWN] files in code base...") fi ############################### @@ -759,10 +764,10 @@ GetValidationInfo() if [[ "$VALIDATE_BASH" != "false" ]]; then # Set to true VALIDATE_BASH="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [BASH] files in code base..." + PRINT_ARRAY+=("- Validating [BASH] files in code base...") else # Its false - echo "- Excluding [BASH] files in code base..." + PRINT_ARRAY+=("- Excluding [BASH] files in code base...") fi ############################### @@ -775,10 +780,10 @@ GetValidationInfo() if [[ "$VALIDATE_PERL" != "false" ]]; then # Set to true VALIDATE_PERL="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [PERL] files in code base..." + PRINT_ARRAY+=("- Validating [PERL] files in code base...") else # Its false - echo "- Excluding [PERL] files in code base..." + PRINT_ARRAY+=("- Excluding [PERL] files in code base...") fi ############################### @@ -791,10 +796,10 @@ GetValidationInfo() if [[ "$VALIDATE_PYTHON" != "false" ]]; then # Set to true VALIDATE_PYTHON="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [PYTHON] files in code base..." + PRINT_ARRAY+=("- Validating [PYTHON] files in code base...") else # Its false - echo "- Excluding [PYTHON] files in code base..." + PRINT_ARRAY+=("- Excluding [PYTHON] files in code base...") fi ############################### @@ -807,10 +812,10 @@ GetValidationInfo() if [[ "$VALIDATE_RUBY" != "false" ]]; then # Set to true VALIDATE_RUBY="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [RUBY] files in code base..." + PRINT_ARRAY+=("- Validating [RUBY] files in code base...") else # Its false - echo "- Excluding [RUBY] files in code base..." + PRINT_ARRAY+=("- Excluding [RUBY] files in code base...") fi ############################### @@ -823,10 +828,10 @@ GetValidationInfo() if [[ "$VALIDATE_COFFEE" != "false" ]]; then # Set to true VALIDATE_COFFEE="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [COFFEE] files in code base..." + PRINT_ARRAY+=("- Validating [COFFEE] files in code base...") else # Its false - echo "- Excluding [COFFEE] files in code base..." + PRINT_ARRAY+=("- Excluding [COFFEE] files in code base...") fi ############################### @@ -839,10 +844,10 @@ GetValidationInfo() if [[ "$VALIDATE_ANSIBLE" != "false" ]]; then # Set to true VALIDATE_ANSIBLE="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [ANSIBLE] files in code base..." + PRINT_ARRAY+=("- Validating [ANSIBLE] files in code base...") else # Its false - echo "- Excluding [ANSIBLE] files in code base..." + PRINT_ARRAY+=("- Excluding [ANSIBLE] files in code base...") fi ############################### @@ -855,10 +860,10 @@ GetValidationInfo() if [[ "$VALIDATE_JAVASCRIPT_ES" != "false" ]]; then # Set to true VALIDATE_JAVASCRIPT_ES="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [JAVASCRIPT(eslint)] files in code base..." + PRINT_ARRAY+=("- Validating [JAVASCRIPT(eslint)] files in code base...") else # Its false - echo "- Excluding [JAVASCRIPT(eslint)] files in code base..." + PRINT_ARRAY+=("- Excluding [JAVASCRIPT(eslint)] files in code base...") fi ############################### @@ -871,10 +876,10 @@ GetValidationInfo() if [[ "$VALIDATE_JAVASCRIPT_STANDARD" != "false" ]]; then # Set to true VALIDATE_JAVASCRIPT_STANDARD="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [JAVASCRIPT(standard)] files in code base..." + PRINT_ARRAY+=("- Validating [JAVASCRIPT(standard)] files in code base...") else # Its false - echo "- Excluding [JAVASCRIPT(standard)] files in code base..." + PRINT_ARRAY+=("- Excluding [JAVASCRIPT(standard)] files in code base...") fi ############################### @@ -887,10 +892,10 @@ GetValidationInfo() if [[ "$VALIDATE_TYPESCRIPT_ES" != "false" ]]; then # Set to true VALIDATE_TYPESCRIPT_ES="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [TYPESCRIPT(eslint)] files in code base..." + PRINT_ARRAY+=("- Validating [TYPESCRIPT(eslint)] files in code base...") else # Its false - echo "- Excluding [TYPESCRIPT(eslint)] files in code base..." + PRINT_ARRAY+=("- Excluding [TYPESCRIPT(eslint)] files in code base...") fi ############################### @@ -903,10 +908,10 @@ GetValidationInfo() if [[ "$VALIDATE_TYPESCRIPT_STANDARD" != "false" ]]; then # Set to true VALIDATE_TYPESCRIPT_STANDARD="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [TYPESCRIPT(standard)] files in code base..." + PRINT_ARRAY+=("- Validating [TYPESCRIPT(standard)] files in code base...") else # Its false - echo "- Excluding [TYPESCRIPT(standard)] files in code base..." + PRINT_ARRAY+=("- Excluding [TYPESCRIPT(standard)] files in code base...") fi ############################### @@ -919,10 +924,10 @@ GetValidationInfo() if [[ "$VALIDATE_DOCKER" != "false" ]]; then # Set to true VALIDATE_DOCKER="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [DOCKER] files in code base..." + PRINT_ARRAY+=("- Validating [DOCKER] files in code base...") else # Its false - echo "- Excluding [DOCKER] files in code base..." + PRINT_ARRAY+=("- Excluding [DOCKER] files in code base...") fi ############################### @@ -935,10 +940,10 @@ GetValidationInfo() if [[ "$VALIDATE_GO" != "false" ]]; then # Set to true VALIDATE_GO="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [GOLANG] files in code base..." + PRINT_ARRAY+=("- Validating [GOLANG] files in code base...") else # Its false - echo "- Excluding [GOLANG] files in code base..." + PRINT_ARRAY+=("- Excluding [GOLANG] files in code base...") fi ############################### @@ -951,10 +956,10 @@ GetValidationInfo() if [[ "$VALIDATE_TERRAFORM" != "false" ]]; then # Set to true VALIDATE_TERRAFORM="$DEFAULT_VALIDATE_LANGUAGE" - echo "- Validating [TERRAFORM] files in code base..." + PRINT_ARRAY+=("- Validating [TERRAFORM] files in code base...") else # Its false - echo "- Excluding [TERRAFORM] files in code base..." + PRINT_ARRAY+=("- Excluding [TERRAFORM] files in code base...") fi ############################## @@ -1001,7 +1006,15 @@ GetValidationInfo() # Debug on runner # ################### if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then - echo "--- DEBUG ---" + ########################### + # Print the validate info # + ########################### + for LINE in "${PRINT_ARRAY[@]}" + do + echo "$LINE" + done + + echo "--- DEBUG INFO ---" echo "---------------------------------------------" RUNNER=$(whoami) echo "Runner:[$RUNNER]" @@ -1828,10 +1841,7 @@ GetGitHubVars ########################################## # Get the langugages we need to validate # ########################################## -if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then - # Get the flags for langugaes to validate - GetValidationInfo -fi +GetValidationInfo ######################## # Get the linter rules # From c6f74369b85d3fcc0f1ef2fe35aeee48d7c62a39 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:13:12 -0500 Subject: [PATCH 08/12] Cleanup footer prints --- lib/linter.sh | 57 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 00511ab2..10147d18 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -55,6 +55,13 @@ LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck" "pylint" "perl" "rubocop" "coffeelint" "eslint" "standard" "ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint") +############################# +# Language array for prints # +############################# +LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON' + 'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES' + 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM') + ################### # GitHub ENV Vars # ################### @@ -1440,10 +1447,20 @@ LintCodebase() # Set it back to empty if loaded with blanks from scanning # ############################################################ if [ ${#LIST_FILES[@]} -lt 1 ]; then + ###################### + # Set to empty array # + ###################### LIST_FILES=() + ############################# + # Skip as we found no files # + ############################# + SKIP_FLAG=1 fi fi + ############################### + # Check if any data was found # + ############################### if [ $SKIP_FLAG -eq 0 ]; then ###################### # Print Header array # @@ -1724,23 +1741,29 @@ Footer() echo "----------------------------------------------" echo "----------------------------------------------" echo "" - 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 MARKDOWN:[$ERRORS_FOUND_MARKDOWN]" - echo "ERRORS FOUND in BASH:[$ERRORS_FOUND_BASH]" - echo "ERRORS FOUND in PERL:[$ERRORS_FOUND_PERL]" - echo "ERRORS FOUND in PYTHON:[$ERRORS_FOUND_PYTHON]" - echo "ERRORS FOUND in COFFEESCRIPT:[$ERRORS_FOUND_COFFEESCRIPT]" - echo "ERRORS FOUND in RUBY:[$ERRORS_FOUND_RUBY]" - echo "ERRORS FOUND in ANSIBLE:[$ERRORS_FOUND_ANSIBLE]" - echo "ERRORS FOUND in JAVASCRIPT(eslint):[$ERRORS_FOUND_JAVASCRIPT_ES]" - echo "ERRORS FOUND in JAVASCRIPT(Standard):[$ERRORS_FOUND_JAVASCRIPT_STANDARD]" - echo "ERRORS FOUND in TYPESCRIPT(eslint):[$ERRORS_FOUND_TYPESCRIPT_ES]" - echo "ERRORS FOUND in TYPESCRIPT(Standard):[$ERRORS_FOUND_TYPESCRIPT_STANDARD]" - echo "ERRORS FOUND in DOCKER:[$ERRORS_FOUND_DOCKER]" - echo "ERRORS FOUND in GO:[$ERRORS_FOUND_GO]" - echo "ERRORS FOUND in TERRAFORM:[$ERRORS_FOUND_TERRAFORM]" + + ############################## + # Prints for errors if found # + ############################## + for LANGUAGE in "${LANGUAGE_ARRAY[@]}" + do + ########################### + # Build the error counter # + ########################### + ERROR_COUNTER="ERRORS_FOUND_$LANGUAGE" + + ################## + # Print if not 0 # + ################## + if [ "$ERROR_COUNTER" -ne 0 ]; then + # Print the goods + echo "ERRORS FOUND in $LANGUAGE:[$ERROR_COUNTER]" + fi + done + + ################# + # Footer prints # + ################# echo "" echo "----------------------------------------------" echo "" From 2db5868fcfb4cccc9503a08213d25bb8fc986aab Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:24:28 -0500 Subject: [PATCH 09/12] make a var? --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 10147d18..a6082db5 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1755,7 +1755,7 @@ Footer() ################## # Print if not 0 # ################## - if [ "$ERROR_COUNTER" -ne 0 ]; then + if [ ${ERROR_COUNTER} -ne 0 ]; then # Print the goods echo "ERRORS FOUND in $LANGUAGE:[$ERROR_COUNTER]" fi From 7cb80134b111af5e945e9f53c7a7d14afa0d586f Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:26:07 -0500 Subject: [PATCH 10/12] Quotes --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index a6082db5..24e27c80 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1755,7 +1755,7 @@ Footer() ################## # Print if not 0 # ################## - if [ ${ERROR_COUNTER} -ne 0 ]; then + if [ "${ERROR_COUNTER}" -ne 0 ]; then # Print the goods echo "ERRORS FOUND in $LANGUAGE:[$ERROR_COUNTER]" fi From 619307fe9fa875bc39e81836eda658f7d78a3a4f Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:38:43 -0500 Subject: [PATCH 11/12] get the value --- lib/linter.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 24e27c80..12c799db 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1755,9 +1755,9 @@ Footer() ################## # Print if not 0 # ################## - if [ "${ERROR_COUNTER}" -ne 0 ]; then + if [ "${!ERROR_COUNTER}" -ne 0 ]; then # Print the goods - echo "ERRORS FOUND in $LANGUAGE:[$ERROR_COUNTER]" + echo "ERRORS FOUND in $LANGUAGE:[${!ERROR_COUNTER}]" fi done From 79878c8ae93a8d99432ff4bf38ba627e6457fca0 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:55:21 -0500 Subject: [PATCH 12/12] adding more print --- lib/linter.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 12c799db..a794626e 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1761,13 +1761,6 @@ Footer() fi done - ################# - # Footer prints # - ################# - echo "" - echo "----------------------------------------------" - echo "" - ############################### # Exit with 1 if errors found # ############################### @@ -1792,6 +1785,13 @@ Footer() echo "Exiting with errors found!" exit 1 else + ################# + # Footer prints # + ################# + echo "" + echo "All file(s) linted successfully with no errors detected" + echo "----------------------------------------------" + echo "" # Successful exit exit 0 fi