From 2c9f8b1aa2b70d12e59b8e2ef8cc6f5abbd6dbcf Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 3 Nov 2020 10:06:33 -0600 Subject: [PATCH] fixing logic --- lib/linter.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 6f0b52ca..58f35c97 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -407,11 +407,16 @@ GetLinterRules() { SECONDARY_FILE_NAME="$FILE_NAME.yml" fi + ############################### + # Set Flag for set Rules File # + ############################### + SET_RULES=0 + ##################################### # Validate we have the linter rules # ##################################### LANGUAGE_FILE_PATH="${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" - debug "Checking if the user-provided ${!LANGUAGE_FILE_NAME} exists at ${LANGUAGE_FILE_PATH}" + debug "Checking if the user-provided:[${!LANGUAGE_FILE_NAME}] and exists at:[${LANGUAGE_FILE_PATH}]" if [ -f "${LANGUAGE_FILE_PATH}" ]; then info "----------------------------------------------" info "User provided file:[${LANGUAGE_FILE_PATH}] exists, setting rules file..." @@ -420,12 +425,22 @@ GetLinterRules() { # Update the path to the file location # ######################################## eval "${LANGUAGE_LINTER_RULES}=${LANGUAGE_FILE_PATH}" - - # Check if we have secondary file name to look for - elif [ -n "$SECONDARY_FILE_NAME" ]; then + ###################### + # Set the rules flag # + ###################### + SET_RULES=1 + else + # Failed to find the primary rules file debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}]." + fi + + #################################################### + # Check if we have secondary file name to look for # + #################################################### + if [ -n "$SECONDARY_FILE_NAME" ] && [ "${SET_RULES}" -eq 0 ]; then + # Set the path SECONDARY_LANGUAGE_FILE_PATH="${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${SECONDARY_FILE_NAME}" - debug "${LANGUAGE_NAME} language rule file has a secondary rules file name to check (${SECONDARY_FILE_NAME}). Path: ${SECONDARY_LANGUAGE_FILE_PATH}" + debug "${LANGUAGE_NAME} language rule file has a secondary rules file name to check (${SECONDARY_FILE_NAME}). Path:[${SECONDARY_LANGUAGE_FILE_PATH}]" if [ -f "${SECONDARY_LANGUAGE_FILE_PATH}" ]; then info "----------------------------------------------" @@ -435,24 +450,47 @@ GetLinterRules() { # Update the path to the file location # ######################################## eval "${LANGUAGE_LINTER_RULES}=${SECONDARY_LANGUAGE_FILE_PATH}" + ###################### + # Set the rules flag # + ###################### + SET_RULES=1 fi - else + fi + + ############################################################## + # We didnt find rules from user, setting to default template # + ############################################################## + if [ "${SET_RULES}" -eq 0 ]; then ######################################################## # No user default provided, using the template default # ######################################################## eval "${LANGUAGE_LINTER_RULES}=${DEFAULT_RULES_LOCATION}/${!LANGUAGE_FILE_NAME}" debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}], nor the file:[${SECONDARY_LANGUAGE_FILE_PATH}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]" + ###################### + # Set the rules flag # + ###################### + SET_RULES=1 fi - debug " -> Language rules file variable (${LANGUAGE_LINTER_RULES}) value is: ${!LANGUAGE_LINTER_RULES}" + #################### + # Debug Print info # + #################### + debug " -> Language rules file variable (${LANGUAGE_LINTER_RULES}) value is:[${!LANGUAGE_LINTER_RULES}]" + ############################ + # Validate the file exists # + ############################ if [ -e "${!LANGUAGE_LINTER_RULES}" ]; then + # Found the rules file debug " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) exists." else # Here we expect a rules file, so fail if not available. fatal " -> ${LANGUAGE_LINTER_RULES} rules file (${!LANGUAGE_LINTER_RULES}) doesn't exist. Terminating..." fi + ###################### + # Export the results # + ###################### eval "export ${LANGUAGE_LINTER_RULES}" } ################################################################################