From 20f1db9ad3b30e16a397661d24432bc1891cdf44 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 25 Oct 2019 11:29:31 -0500 Subject: [PATCH 1/7] updating code --- Dockerfile | 13 ++- README.md | 39 +++++++ lib/entrypoint.sh | 289 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 318 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index fd5a3614..c6d883b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,7 +58,18 @@ RUN wget -qO- "https://storage.googleapis.com/shellcheck/shellcheck-stable.linux ########################################### ENV GITHUB_SHA=${GITHUB_SHA} \ GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH} \ - GITHUB_WORKSPACE=${GITHUB_WORKSPACE} + GITHUB_WORKSPACE=${GITHUB_WORKSPACE} \ + VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} \ + VALIDATE_YAML=${VALIDATE_YAML} \ + VALIDATE_JSON=${VALIDATE_JSON} \ + VALIDATE_XML=${VALIDATE_XML} \ + VALIDATE_MD=${VALIDATE_MD} \ + VALIDATE_BASH=${VALIDATE_BASH} \ + VALIDATE_PERL=${VALIDATE_PERL} \ + VALIDATE_PYTHON=${VALIDATE_PYTHON} \ + VALIDATE_RUBY=${VALIDATE_RUBY} \ + VALIDATE_COFFEE=${VALIDATE_COFFEE} \ + VALIDATE_ANSIBLE=${VALIDATE_ANSIBLE} ############################# # Copy scripts to container # diff --git a/README.md b/README.md index b96a467e..557ee15a 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,47 @@ jobs: ################################ - name: Lint Code Base uses: docker://admiralawkbar/super-linter:latest + env: + VALIDATE_ALL_CODEBASE: false + VALIDATE_ANSIBLE: false ... ``` +## Env Vars +The super-linter allows you to pass the following `ENV` variables to be able to trigger different functionality: +- **VALIDATE_ALL_CODEBASE** + - Default: `true` + - Will parse the entire repository and find all files to validate across all types + - **NOTE:** When set to `false`, only **new** or **edited** files will be parsed for validation +- **VALIDATE_YAML** + - Default: `true` + - Flag to enable or disable the linting process of the language +- **VALIDATE_JSON** + - Default: `true` + - Flag to enable or disable the linting process of the language +- **VALIDATE_XML** + - Default: `true` + - Flag to enable or disable the linting process of the language +- **VALIDATE_MD** + - Default: `true` + - Flag to enable or disable the linting process of the language +- **VALIDATE_BASH** + - Default: `true` + - Flag to enable or disable the linting process of the language +- **VALIDATE_PERL** + - Default: `true` + - Flag to enable or disable the linting process of the language +- **VALIDATE_PYTHON** + - Default: `true` + - Flag to enable or disable the linting process of the language +- **VALIDATE_RUBY** + - Default: `true` + - Flag to enable or disable the linting process of the language +- **VALIDATE_COFFEE** + - Default: `true` + - Flag to enable or disable the linting process of the language +- **VALIDATE_ANSIBLE** + - Default: `true` + - Flag to enable or disable the linting process of the language ## Docker Hub diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index abda330f..add0027f 100755 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -31,9 +31,26 @@ ANSIBLE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$ANSIBLE_FILE_NAME" # Path to th ################### # GitHub ENV Vars # ################### -GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit -GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path -GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace +GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit +GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path +GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace +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 + +################ +# Default Vars # +################ +DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files +DEFAULT_VALIDATE_LANGUAGE='true' # Default to validate language ############ # Counters # @@ -100,7 +117,7 @@ GetLinterRules() exit 1 fi else - echo "Using Default rules at:[$YAML_LINTER_RULES]" + echo "Codebase does not have file:[.github/linters/$YAML_FILE_NAME], using Default rules at:[$YAML_LINTER_RULES]" fi ##################################### @@ -128,7 +145,7 @@ GetLinterRules() exit 1 fi else - echo "Using Default rules at:[$MD_LINTER_RULES]" + echo "Codebase does not have file:[.github/linters/$MD_FILE_NAME], using Default rules at:[$MD_LINTER_RULES]" fi ##################################### @@ -156,7 +173,7 @@ GetLinterRules() exit 1 fi else - echo "Using Default rules at:[$PYTHON_LINTER_RULES]" + echo "Codebase does not have file:[.github/linters/$PYTHON_FILE_NAME], using Default rules at:[$PYTHON_LINTER_RULES]" fi ##################################### @@ -184,7 +201,7 @@ GetLinterRules() exit 1 fi else - echo "Using Default rules at:[$RUBY_LINTER_RULES]" + echo "Codebase does not have file:[.github/linters/$RUBY_FILE_NAME], using Default rules at:[$RUBY_LINTER_RULES]" fi ##################################### @@ -212,7 +229,7 @@ GetLinterRules() exit 1 fi else - echo "Using Default rules at:[$COFFEE_LINTER_RULES]" + echo "Codebase does not have file:[.github/linters/$COFFEE_FILE_NAME], using Default rules at:[$COFFEE_LINTER_RULES]" fi ##################################### @@ -240,7 +257,7 @@ GetLinterRules() exit 1 fi else - echo "Using Default rules at:[$ANSIBLE_LINTER_RULES]" + echo "Codebase does not have file:[.github/linters/$ANSIBLE_FILE_NAME], using Default rules at:[$ANSIBLE_LINTER_RULES]" fi } ################################################################################ @@ -1246,6 +1263,189 @@ GetGitHubVars() else echo "Successfully found:[GITHUB_REPO]" fi + + ############################################ + # Print headers for user provided env vars # + ############################################ + echo "" + echo "--------------------------------------------" + echo "Gathering User provided information..." + + ############################### + # 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 + + ############################### + # 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 } ################################################################################ #### Function LintAnsibleFiles ################################################# @@ -1364,6 +1564,26 @@ LintAnsibleFiles() fi } ################################################################################ +#### Function BuildFileList #################################################### +BuildFileList() +{ + # Need to build a list of all files changed + # This can be pulled from the GITHUB_EVENT_PATH payload + + ################ + # print header # + ################ + echo "" + echo "----------------------------------------------" + echo "Gathering list of files edited, or added in the commit..." + echo "" + echo "Echoing file contents:" + echo "-----------------------------" + cat "$GITHUB_EVENT_PATH" + echo "-----------------------------" + +} +################################################################################ #### Function Footer ########################################################### Footer() { @@ -1378,6 +1598,7 @@ Footer() 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 COFFEE:[$ERRORS_FOUND_COFFEE]" echo "ERRORS FOUND in RUBY:[$ERRORS_FOUND_RUBY]" echo "ERRORS FOUND in ANSIBLE:[$ERRORS_FOUND_ANSIBLE]" @@ -1393,6 +1614,7 @@ Footer() [ $ERRORS_FOUND_BASH -ne 0 ] || \ [ $ERRORS_FOUND_PERL -ne 0 ] || \ [ $ERRORS_FOUND_PYTHON -ne 0 ] || \ + [ $ERRORS_FOUND_COFFEE -ne 0 ] || \ [ $ERRORS_FOUND_ANSIBLE -ne 0 ] || \ [ $ERRORS_FOUND_RUBY -ne 0 ]; then # Failed exit @@ -1424,59 +1646,82 @@ GetGitHubVars ######################## GetLinterRules -###################### -# Validate workspace # -###################### +######################################## +# Get list of files changed if env set # +######################################## +if [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then + BuildFileList +fi ###################### # Lint the Yml Files # ###################### -LintYmlFiles +if [ "$VALIDATE_YAML" == "true" ]; then + LintYmlFiles +fi ####################### # Lint the json files # ####################### -LintJsonFiles +if [ "$VALIDATE_JSON" == "true" ]; then + LintJsonFiles +fi ###################### # Lint the XML Files # ###################### -LintXmlFiles +if [ "$VALIDATE_XML" == "true" ]; then + LintXmlFiles +fi ########################### # Lint the Markdown Files # ########################### -LintMdFiles +if [ "$VALIDATE_MD" == "true" ]; then + LintMdFiles +fi ####################### # Lint the bash files # ####################### -LintBashFiles +if [ "$VALIDATE_BASH" == "true" ]; then + LintBashFiles +fi ######################### # Lint the python files # ######################### -LintPythonFiles +if [ "$VALIDATE_PYTHON" == "true" ]; then + LintPythonFiles +fi ####################### # Lint the perl files # ####################### -LintPerlFiles +if [ "$VALIDATE_PERL" == "true" ]; then + LintPerlFiles +fi ####################### # Lint the ruby files # ####################### -LintRubyFiles +if [ "$VALIDATE_RUBY" == "true" ]; then + LintRubyFiles +fi ######################### # Lint the coffee files # ######################### -LintCoffeeFiles +if [ "$VALIDATE_COFFEE" == "true" ]; then + LintCoffeeFiles +fi ########################## # Lint the Ansible files # ########################## -LintAnsibleFiles +if [ "$VALIDATE_ANSIBLE" == "true" ]; then + LintAnsibleFiles +fi ########## # Footer # From a9be7d5520e16cb53d20d87af7474c039af445e4 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 25 Oct 2019 14:22:57 -0500 Subject: [PATCH 2/7] adding more code --- lib/entrypoint.sh | 570 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 405 insertions(+), 165 deletions(-) diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index add0027f..064b3a11 100755 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -52,6 +52,19 @@ VALIDATE_ANSIBLE="${VALIDATE_ANSIBLE}" # Boolean to validate language DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files DEFAULT_VALIDATE_LANGUAGE='true' # Default to validate language +########################## +# Array of changed files # +########################## +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 + ############ # Counters # ############ @@ -303,11 +316,24 @@ LintJsonFiles() echo "Location:[$VALIDATE_INSTALL_CMD]" fi - ################################# - # Get list of all files to lint # - ################################# - # shellcheck disable=SC2207 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.json" 2>&1)) + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ############################################################ + # Check to see if we need to go through array or all files # + ############################################################ + if [ ${#FILE_ARRAY_JSON[@]} -ne 0 ]; then + # 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 ################## # Lint the files # @@ -405,11 +431,24 @@ LintYmlFiles() echo "Location:[$VALIDATE_INSTALL_CMD]" fi - ################################# - # 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)) + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ############################################################ + # Check to see if we need to go through array or all files # + ############################################################ + if [ ${#FILE_ARRAY_YML[@]} -ne 0 ]; then + # 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 ################## # Lint the files # @@ -507,11 +546,24 @@ LintXmlFiles() echo "Location:[$VALIDATE_INSTALL_CMD]" fi - ################################# - # Get list of all files to lint # - ################################# - # shellcheck disable=SC2207 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.xml" 2>&1)) + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ############################################################ + # Check to see if we need to go through array or all files # + ############################################################ + if [ ${#FILE_ARRAY_XML[@]} -ne 0 ]; then + # 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 ################## # Lint the files # @@ -609,11 +661,24 @@ LintMdFiles() echo "Location:[$VALIDATE_INSTALL_CMD]" fi - ################################# - # Get list of all files to lint # - ################################# - # shellcheck disable=SC2207 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.md" 2>&1)) + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ############################################################ + # Check to see if we need to go through array or all files # + ############################################################ + if [ ${#FILE_ARRAY_MD[@]} -ne 0 ]; then + # 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 ################## # Lint the files # @@ -711,11 +776,24 @@ LintBashFiles() echo "Location:[$VALIDATE_INSTALL_CMD]" fi - ################################# - # Get list of all files to lint # - ################################# - # shellcheck disable=SC2207 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.sh" 2>&1)) + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ############################################################ + # Check to see if we need to go through array or all files # + ############################################################ + if [ ${#FILE_ARRAY_BASH[@]} -ne 0 ]; then + # 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 ################## # Lint the files # @@ -814,11 +892,24 @@ LintPythonFiles() echo "Location:[$VALIDATE_INSTALL_CMD]" fi - ################################# - # Get list of all files to lint # - ################################# - # shellcheck disable=SC2207 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.py" 2>&1)) + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ############################################################ + # Check to see if we need to go through array or all files # + ############################################################ + if [ ${#FILE_ARRAY_PYTHON[@]} -ne 0 ]; then + # 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 ################## # Lint the files # @@ -917,11 +1008,24 @@ LintPerlFiles() echo "Location:[$VALIDATE_INSTALL_CMD]" fi - ################################# - # Get list of all files to lint # - ################################# - # shellcheck disable=SC2207 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.pl" 2>&1)) + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ############################################################ + # Check to see if we need to go through array or all files # + ############################################################ + if [ ${#FILE_ARRAY_PERL[@]} -ne 0 ]; then + # 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 ################## # Lint the files # @@ -1020,11 +1124,24 @@ LintRubyFiles() echo "Location:[$VALIDATE_INSTALL_CMD]" fi - ################################# - # Get list of all files to lint # - ################################# - # shellcheck disable=SC2207 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.rb" 2>&1)) + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ############################################################ + # Check to see if we need to go through array or all files # + ############################################################ + if [ ${#FILE_ARRAY_RUBY[@]} -ne 0 ]; then + # 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 ################## # Lint the files # @@ -1123,11 +1240,24 @@ LintCoffeeFiles() echo "Location:[$VALIDATE_INSTALL_CMD]" fi - ################################# - # Get list of all files to lint # - ################################# - # shellcheck disable=SC2207 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -name "*.coffee" 2>&1)) + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ############################################################ + # Check to see if we need to go through array or all files # + ############################################################ + if [ ${#FILE_ARRAY_COFFEE[@]} -ne 0 ]; then + # 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 ################## # Lint the files # @@ -1184,6 +1314,122 @@ LintCoffeeFiles() done } ################################################################################ +#### Function LintAnsibleFiles ################################################# +LintAnsibleFiles() +{ + ANSIBLE_DIR="$GITHUB_WORKSPACE/ansible" # Ansible directory + + ################ + # print header # + ################ + echo "" + echo "----------------------------------------------" + echo "Linting Ansible files..." + echo "----------------------------------------------" + 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 + + ###################################################### + # Only go into ansible linter if we have base folder # + ###################################################### + if [ -d "$ANSIBLE_DIR" ]; then + ################################# + # Get list of all files to lint # + ################################# + # shellcheck disable=SC2164,SC2010,SC2207 + LIST_FILES=($(cd "$ANSIBLE_DIR"; ls -I vault.yml -I galaxy.yml | grep ".yml" 2>&1)) + + ################## + # 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 "$ANSIBLE_DIR/$FILE" 2>&1) + + ############## + # File print # + ############## + echo "---------------------------" + echo "File:[$FILE]" + + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$("$LINTER_NAME" -v -c "$ANSIBLE_LINTER_FILE" "$ANSIBLE_DIR/$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_ANSIBLE++)) + else + ########### + # Success # + ########### + echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" + fi + done + else + ######################## + # No Ansible dir found # + ######################## + echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIR]" + echo "skipping ansible lint" + fi +} +################################################################################ #### Function GetGitHubVars #################################################### GetGitHubVars() { @@ -1448,122 +1694,6 @@ GetGitHubVars() fi } ################################################################################ -#### Function LintAnsibleFiles ################################################# -LintAnsibleFiles() -{ - ANSIBLE_DIR="$GITHUB_WORKSPACE/ansible" # Ansible directory - - ################ - # print header # - ################ - echo "" - echo "----------------------------------------------" - echo "Linting Ansible files..." - echo "----------------------------------------------" - 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 - - ###################################################### - # Only go into ansible linter if we have base folder # - ###################################################### - if [ -d "$ANSIBLE_DIR" ]; then - ################################# - # Get list of all files to lint # - ################################# - # shellcheck disable=SC2164,SC2010,SC2207 - LIST_FILES=($(cd "$ANSIBLE_DIR"; ls -I vault.yml -I galaxy.yml | grep ".yml" 2>&1)) - - ################## - # 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 "$ANSIBLE_DIR/$FILE" 2>&1) - - ############## - # File print # - ############## - echo "---------------------------" - echo "File:[$FILE]" - - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$("$LINTER_NAME" -v -c "$ANSIBLE_LINTER_FILE" "$ANSIBLE_DIR/$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_ANSIBLE++)) - else - ########### - # Success # - ########### - echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" - fi - done - else - ######################## - # No Ansible dir found # - ######################## - echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIR]" - echo "skipping ansible lint" - fi -} -################################################################################ #### Function BuildFileList #################################################### BuildFileList() { @@ -1577,11 +1707,121 @@ BuildFileList() echo "----------------------------------------------" echo "Gathering list of files edited, or added in the commit..." echo "" - echo "Echoing file contents:" - echo "-----------------------------" - cat "$GITHUB_EVENT_PATH" - echo "-----------------------------" + ################################################ + # Get the Array of files changed in the comits # + ################################################ + RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only master..$GITHUB_SHA 2>&1)) + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -ne 0 ]; then + # Error + echo "ERROR! failed tgo gain list of all files changed!" + echo "ERROR:[${RAW_FILE_ARRAY[*]}]" + exit 1 + fi + + ################################################# + # Itterate through the array of all files found # + ################################################# + for FILE in "${RAW_FILE_ARRAY[@]}" + do + ########################### + # Get the files extension # + ########################### + FILE_TYPE=$(basename "$FILE" | cut -f2 -d'.') + + ############################### + # Convert string to lowercase # + ############################### + FILE_TYPE=$(echo "$FILE_TYPE" | awk '{print tolower($0)}') + + ##################### + # Get the YML files # + ##################### + if [ "$FILE_TYPE" == "yml" ] || [ "$FILE_TYPE" == "yaml" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_YML+=("$FILE") + ###################### + # Get the JSON files # + ###################### + elif [ "$FILE_TYPE" == "json" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_JSON+=("$FILE") + ##################### + # Get the XML files # + ##################### + elif [ "$FILE_TYPE" == "xml" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_XML+=("$FILE") + ########################## + # 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") + ###################### + # Get the PERL files # + ###################### + elif [ "$FILE_TYPE" == "pl" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PERL+=("$FILE") + ###################### + # Get the RUBY files # + ###################### + elif [ "$FILE_TYPE" == "rb" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_RUBY+=("$FILE") + ######################## + # Get the PYTHON files # + ######################## + elif [ "$FILE_TYPE" == "py" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PYTHON+=("$FILE") + ######################## + # Get the COFFEE files # + ######################## + elif [ "$FILE_TYPE" == "coffee" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_COFFEE+=("$FILE") + else + ############################ + # Extension was not found! # + ############################ + echo "WARN! Failed to get file type for:[$FILE]!" + fi + done } ################################################################################ #### Function Footer ########################################################### From ffd73a80a59dad485201682060b6ddfb1a4875a8 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 25 Oct 2019 14:25:31 -0500 Subject: [PATCH 3/7] adding more code --- lib/entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index 064b3a11..33cb60bb 100755 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -1711,7 +1711,8 @@ BuildFileList() ################################################ # Get the Array of files changed in the comits # ################################################ - RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only master..$GITHUB_SHA 2>&1)) + # shellcheck disable=SC2207 + RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only "master..$GITHUB_SHA" 2>&1)) ####################### # Load the error code # From 52a30b11707411f4e7313bbdea517b6382ac7e3c Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 25 Oct 2019 15:56:04 -0500 Subject: [PATCH 4/7] adding it up --- Dockerfile | 2 +- lib/{entrypoint.sh => linter.sh} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/{entrypoint.sh => linter.sh} (100%) diff --git a/Dockerfile b/Dockerfile index c6d883b1..507d9544 100644 --- a/Dockerfile +++ b/Dockerfile @@ -84,6 +84,6 @@ COPY TEMPLATES /action/lib/.automation ###################### # Set the entrypoint # ###################### -ENTRYPOINT ["/action/lib/entrypoint.sh"] +ENTRYPOINT ["/action/lib/linter.sh"] #CMD tail -f /dev/null diff --git a/lib/entrypoint.sh b/lib/linter.sh similarity index 100% rename from lib/entrypoint.sh rename to lib/linter.sh From 40e60c3d53de00863e345bb18de9c2ec1f4dea12 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 28 Oct 2019 08:42:27 -0500 Subject: [PATCH 5/7] quotes --- lib/linter.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 33cb60bb..2d6b9bf0 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1712,7 +1712,7 @@ BuildFileList() # Get the Array of files changed in the comits # ################################################ # shellcheck disable=SC2207 - RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only "master..$GITHUB_SHA" 2>&1)) + RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only master..$GITHUB_SHA 2>&1)) ####################### # Load the error code # @@ -1724,7 +1724,7 @@ BuildFileList() ############################## if [ $ERROR_CODE -ne 0 ]; then # Error - echo "ERROR! failed tgo gain list of all files changed!" + echo "ERROR! Failed to gain a list of all files changed!" echo "ERROR:[${RAW_FILE_ARRAY[*]}]" exit 1 fi From b9c3a16631603e79e11ec0980a4c5e47e34577d7 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 28 Oct 2019 08:43:57 -0500 Subject: [PATCH 6/7] quotes --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 2d6b9bf0..439a2925 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1711,7 +1711,7 @@ BuildFileList() ################################################ # Get the Array of files changed in the comits # ################################################ - # shellcheck disable=SC2207 + # shellcheck disable=SC2207,SC2086 RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only master..$GITHUB_SHA 2>&1)) ####################### From 1c03d1d89baaeb903d318f52467639a37d55646d Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 28 Oct 2019 11:18:05 -0500 Subject: [PATCH 7/7] cleaned up language --- lib/linter.sh | 119 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 96 insertions(+), 23 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 439a2925..d144c8dc 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -324,7 +324,10 @@ LintJsonFiles() ############################################################ # Check to see if we need to go through array or all files # ############################################################ - if [ ${#FILE_ARRAY_JSON[@]} -ne 0 ]; then + 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 # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY_JSON[@]}") # Copy the array into list else @@ -439,7 +442,10 @@ LintYmlFiles() ############################################################ # Check to see if we need to go through array or all files # ############################################################ - if [ ${#FILE_ARRAY_YML[@]} -ne 0 ]; then + 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 # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY_YML[@]}") # Copy the array into list else @@ -554,7 +560,10 @@ LintXmlFiles() ############################################################ # Check to see if we need to go through array or all files # ############################################################ - if [ ${#FILE_ARRAY_XML[@]} -ne 0 ]; then + 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 # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY_XML[@]}") # Copy the array into list else @@ -669,7 +678,10 @@ LintMdFiles() ############################################################ # Check to see if we need to go through array or all files # ############################################################ - if [ ${#FILE_ARRAY_MD[@]} -ne 0 ]; then + 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 # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY_MD[@]}") # Copy the array into list else @@ -784,7 +796,10 @@ LintBashFiles() ############################################################ # Check to see if we need to go through array or all files # ############################################################ - if [ ${#FILE_ARRAY_BASH[@]} -ne 0 ]; then + 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 # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY_BASH[@]}") # Copy the array into list else @@ -900,7 +915,10 @@ LintPythonFiles() ############################################################ # Check to see if we need to go through array or all files # ############################################################ - if [ ${#FILE_ARRAY_PYTHON[@]} -ne 0 ]; then + 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 # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY_PYTHON[@]}") # Copy the array into list else @@ -1016,7 +1034,10 @@ LintPerlFiles() ############################################################ # Check to see if we need to go through array or all files # ############################################################ - if [ ${#FILE_ARRAY_PERL[@]} -ne 0 ]; then + 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 # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY_PERL[@]}") # Copy the array into list else @@ -1132,7 +1153,10 @@ LintRubyFiles() ############################################################ # Check to see if we need to go through array or all files # ############################################################ - if [ ${#FILE_ARRAY_RUBY[@]} -ne 0 ]; then + 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 # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY_RUBY[@]}") # Copy the array into list else @@ -1248,7 +1272,10 @@ LintCoffeeFiles() ############################################################ # Check to see if we need to go through array or all files # ############################################################ - if [ ${#FILE_ARRAY_COFFEE[@]} -ne 0 ]; then + 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 # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY_COFFEE[@]}") # Copy the array into list else @@ -1447,7 +1474,7 @@ GetGitHubVars() echo "ERROR:[$GITHUB_SHA]" exit 1 else - echo "Successfully found:[GITHUB_SHA]" + echo "Successfully found:[GITHUB_SHA], value:[$GITHUB_SHA]" fi ############################ @@ -1458,7 +1485,7 @@ GetGitHubVars() echo "ERROR:[$GITHUB_WORKSPACE]" exit 1 else - echo "Successfully found:[GITHUB_WORKSPACE]" + echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]" fi ############################ @@ -1469,7 +1496,7 @@ GetGitHubVars() echo "ERROR:[$GITHUB_EVENT_PATH]" exit 1 else - echo "Successfully found:[GITHUB_EVENT_PATH]" + echo "Successfully found:[GITHUB_EVENT_PATH], value:[$GITHUB_EVENT_PATH]" fi ################################################## @@ -1490,7 +1517,7 @@ GetGitHubVars() echo "ERROR:[$GITHUB_ORG]" exit 1 else - echo "Successfully found:[GITHUB_ORG]" + echo "Successfully found:[GITHUB_ORG], value:[$GITHUB_ORG]" fi ####################### @@ -1507,7 +1534,7 @@ GetGitHubVars() echo "ERROR:[$GITHUB_REPO]" exit 1 else - echo "Successfully found:[GITHUB_REPO]" + echo "Successfully found:[GITHUB_REPO], value:[$GITHUB_REPO]" fi ############################################ @@ -1530,7 +1557,7 @@ GetGitHubVars() echo "- Validating ALL files in code base..." else # Its false - echo "- Only validating New, or Edited files in code base..." + echo "- Only validating [new], or [edited] files in code base..." fi ############################### @@ -1706,13 +1733,32 @@ BuildFileList() echo "" echo "----------------------------------------------" echo "Gathering list of files edited, or added in the commit..." - echo "" + + ##################################################################### + # Switch codebase back to master to get a list of all files changed # + ##################################################################### + SWITCH_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git checkout master 2>&1) + + ####################### + # 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 ################################################ # Get the Array of files changed in the comits # ################################################ - # shellcheck disable=SC2207,SC2086 - RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only master..$GITHUB_SHA 2>&1)) + # shellcheck disable=SC2207 + RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only "master..$GITHUB_SHA" 2>&1)) ####################### # Load the error code # @@ -1737,12 +1783,14 @@ BuildFileList() ########################### # Get the files extension # ########################### - FILE_TYPE=$(basename "$FILE" | cut -f2 -d'.') + # 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)}') - ############################### - # Convert string to lowercase # - ############################### - FILE_TYPE=$(echo "$FILE_TYPE" | awk '{print tolower($0)}') + ######### + # DEBUG # + ######### + #echo "FILE_TYPE:[$FILE_TYPE]" ##################### # Get the YML files # @@ -1823,6 +1871,31 @@ BuildFileList() echo "WARN! Failed to get file type for:[$FILE]!" fi done + + ######################################### + # 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 # + ################ + echo "Successfully gathered list of files..." } ################################################################################ #### Function Footer ###########################################################