From 91f6a0fa23c4cc431c42eed897c6e09cff12863f Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 21 Oct 2019 14:12:37 -0500 Subject: [PATCH] cleaning --- Dockerfile | 22 ++-- lib/entrypoint.sh | 329 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 289 insertions(+), 62 deletions(-) mode change 100644 => 100755 lib/entrypoint.sh diff --git a/Dockerfile b/Dockerfile index c9c1e6ec..6c3368bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,17 +22,11 @@ LABEL com.github.actions.name="GitHub Super-Linter" \ # Run APK installs # #################### RUN apk add --no-cache \ - bash git musl-dev curl gcc cabal \ + bash git musl-dev curl gcc \ npm nodejs \ libxml2-utils \ ruby ruby-bundler \ - py3-setuptools - -#################### -# Run Pip installs # -#################### -RUN pip install --upgrade --no-cache-dir \ - pip ansible-lint + py3-setuptools ansible-lint ##################### # Run Pip3 Installs # @@ -43,13 +37,14 @@ RUN pip3 install --upgrade --no-cache-dir \ #################### # Run NPM Installs # #################### -RUN npm -g install markdownlint-cli jsonlint prettyjson +RUN npm -g install \ + markdownlint-cli jsonlint prettyjson ###################### -# Run Cabal installs # +# Install shellcheck # ###################### -RUN cabal update \ - && cabal install ShellCheck +RUN wget -qO- "https://storage.googleapis.com/shellcheck/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv \ + && cp "shellcheck-stable/shellcheck" /usr/bin/ ########################################### # Load GitHub Env Vars for Github Actions # @@ -61,7 +56,8 @@ ENV GITHUB_WORKSPACE=${GITHUB_WORKSPACE} ########################### # Copy files to container # ########################### -COPY lib /action/lib +COPY lib /action/lib \ + && TEMPLATES /action/lib/.automation ###################### # Set the entrypoint # diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh old mode 100644 new mode 100755 index 20cc291f..5ac9948a --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -7,26 +7,44 @@ ########### # GLOBALS # ########### -YAML_LINTER_RULES='.automation/yaml-linter-rules.yml' # Path to the yaml lint rules -MD_LINTER_RULES='.automation/md-linter-rules.yml' # Path to the markdown lint rules -PYTHON_LINTER_FILE=".automation/pylintrc" # Name of the Linter file -RUBY_LINTER_FILE=".automation/.rubocop.yml" # Name of the Linter file -COFFEE_LINTER_FILE="Automation/coffeelint.json" # name of the Linter file +# Default Vars +DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location +# YAML Vars +YAML_FILE_NAME='yaml-linter-rules.yml' # Name of the file +YAML_LINTER_RULES="$DEFAULT_RULES_LOCATION/$YAML_FILE_NAME" # Path to the yaml lint rules +# MD Vars +MD_FILE_NAME='md-linter-rules.yml' # Name of the file +MD_LINTER_RULES="$DEFAULT_RULES_LOCATION/$MD_FILE_NAME" # Path to the markdown lint rules +# Python Vars +PYTHON_FILE_NAME='pylint.rc' # Name of the file +PYTHON_LINTER_RULES="$DEFAULT_RULES_LOCATION/$PYTHON_FILE_NAME" # Path to the python lint rules +# Ruby Vars +RUBY_FILE_NAME='.rubocop.yml' # Name of the file +RUBY_LINTER_RULES="$DEFAULT_RULES_LOCATION/$RUBY_FILE_NAME" # Path to the ruby lint rules +# Coffee Vars +COFFEE_FILE_NAME='coffeelint.json' # Name of the file +COFFEE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$COFFEE_FILE_NAME" # Path to the coffescript lint rules + +################### +# 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 ############ # Counters # ############ -ERRORS_FOUND_YML=0 # Count of errors found -ERRORS_FOUND_JSON=0 # Count of errors found -ERRORS_FOUND_XML=0 # Count of errors found -ERRORS_FOUND_MD=0 # Count of errors found - +ERRORS_FOUND_YML=0 # Count of errors found +ERRORS_FOUND_JSON=0 # Count of errors found +ERRORS_FOUND_XML=0 # Count of errors found +ERRORS_FOUND_MD=0 # Count of errors found ERRORS_FOUND_BASH=0 # Count of errors found ERRORS_FOUND_PERL=0 # Count of errors found ERRORS_FOUND_RUBY=0 # Count of errors found ERRORS_FOUND_PYTHON=0 # Count of errors found - ERRORS_FOUND_COFFEE=0 # Count of errors found + ################################################################################ ########################## FUNCTIONS BELOW ##################################### ################################################################################ @@ -36,7 +54,7 @@ Header() { echo "" echo "---------------------------------------------" - echo "---- Markup and Markdown Language Linter ----" + echo "------ Github Actions Language Linter -------" echo "---------------------------------------------" echo "" } @@ -49,17 +67,131 @@ GetLinterRules() ##################################### # Validate we have the linter rules # ##################################### - if [ ! -f "$YAML_LINTER_RULES" ]; then - echo "ERROR! Failed to find:[$YAML_LINTER_RULES] in root of code base!" - exit 1 + if [ -s "$GITHUB_WORKSPACE/.github/$YAML_FILE_NAME" ]; then + echo "User provided file:[$YAML_FILE_NAME], setting rules file..." + + #################################### + # Move users into default location # + #################################### + MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/$YAML_FILE_NAME" "$YAML_LINTER_RULES" 2>&1) + + ################### + # Load Error code # + ################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -ne 0 ]; then + echo "ERROR! Failed to set file:[$YAML_FILE_NAME] as default!" + echo "ERROR:[$MV_CMD]" + exit 1 + fi fi ##################################### # Validate we have the linter rules # ##################################### - if [ ! -f "$MD_LINTER_RULES" ]; then - echo "ERROR! Failed to find:[$MD_LINTER_RULES] in root of code base!" - exit 1 + if [ -s "$GITHUB_WORKSPACE/.github/$MD_FILE_NAME" ]; then + echo "User provided file:[$MD_FILE_NAME], setting rules file..." + + #################################### + # Move users into default location # + #################################### + MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/$MD_FILE_NAME" "$MD_LINTER_RULES" 2>&1) + + ################### + # Load Error code # + ################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -ne 0 ]; then + echo "ERROR! Failed to set file:[$MD_FILE_NAME] as default!" + echo "ERROR:[$MV_CMD]" + exit 1 + fi + fi + + ##################################### + # Validate we have the linter rules # + ##################################### + if [ -s "$GITHUB_WORKSPACE/.github/$PYTHON_FILE_NAME" ]; then + echo "User provided file:[$PYTHON_FILE_NAME], setting rules file..." + + #################################### + # Move users into default location # + #################################### + MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/$PYTHON_FILE_NAME" "$PYTHON_LINTER_RULES" 2>&1) + + ################### + # Load Error code # + ################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -ne 0 ]; then + echo "ERROR! Failed to set file:[$MD_FILE_NAME] as default!" + echo "ERROR:[$MV_CMD]" + exit 1 + fi + fi + + ##################################### + # Validate we have the linter rules # + ##################################### + if [ -s "$GITHUB_WORKSPACE/.github/$RUBY_FILE_NAME" ]; then + echo "User provided file:[$RUBY_FILE_NAME], setting rules file..." + + #################################### + # Move users into default location # + #################################### + MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/$RUBY_FILE_NAME" "$RUBY_LINTER_RULES" 2>&1) + + ################### + # Load Error code # + ################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -ne 0 ]; then + echo "ERROR! Failed to set file:[$RUBY_FILE_NAME] as default!" + echo "ERROR:[$MV_CMD]" + exit 1 + fi + fi + + ##################################### + # Validate we have the linter rules # + ##################################### + if [ -s "$GITHUB_WORKSPACE/.github/$COFFEE_FILE_NAME" ]; then + echo "User provided file:[$COFFEE_FILE_NAME], setting rules file..." + + #################################### + # Move users into default location # + #################################### + MV_CMD=$(mv "$GITHUB_WORKSPACE/.github/$COFFEE_FILE_NAME" "$COFFEE_LINTER_RULES" 2>&1) + + ################### + # Load Error code # + ################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -ne 0 ]; then + echo "ERROR! Failed to set file:[$COFFEE_FILE_NAME] as default!" + echo "ERROR:[$MV_CMD]" + exit 1 + fi fi } ################################################################################ @@ -70,9 +202,9 @@ LintJsonFiles() # print header # ################ echo "" - echo "--------------------------------" + echo "----------------------------------------------" echo "Linting JSON files..." - echo "--------------------------------" + echo "----------------------------------------------" echo "" ###################### @@ -109,7 +241,7 @@ LintJsonFiles() # Get list of all files to lint # ################################# # shellcheck disable=SC2207 - LIST_FILES=($(find . -type f -name "*.json" 2>&1)) + LIST_FILES=($(find "$GITHUB_WORKSPACE" -type f -name "*.json" 2>&1)) ################## # Lint the files # @@ -172,9 +304,9 @@ LintYmlFiles() # print header # ################ echo "" - echo "--------------------------------" + echo "----------------------------------------------" echo "Linting YAML files..." - echo "--------------------------------" + echo "----------------------------------------------" echo "" ###################### @@ -211,7 +343,7 @@ LintYmlFiles() # Get list of all files to lint # ################################# # shellcheck disable=SC2207 - LIST_FILES=($(find . -type f \( -name "*.yml" -or -name "*.yaml" \) 2>&1)) + LIST_FILES=($(find "$GITHUB_WORKSPACE" -type f \( -name "*.yml" -or -name "*.yaml" \) 2>&1)) ################## # Lint the files # @@ -274,9 +406,9 @@ LintXmlFiles() # print header # ################ echo "" - echo "--------------------------------" + echo "----------------------------------------------" echo "Linting XML files..." - echo "--------------------------------" + echo "----------------------------------------------" echo "" ###################### @@ -313,7 +445,7 @@ LintXmlFiles() # Get list of all files to lint # ################################# # shellcheck disable=SC2207 - LIST_FILES=($(find . -type f -name "*.xml" 2>&1)) + LIST_FILES=($(find "$GITHUB_WORKSPACE" -type f -name "*.xml" 2>&1)) ################## # Lint the files # @@ -376,9 +508,9 @@ LintMdFiles() # print header # ################ echo "" - echo "--------------------------------" + echo "----------------------------------------------" echo "Linting Markdown files..." - echo "--------------------------------" + echo "----------------------------------------------" echo "" ###################### @@ -415,7 +547,7 @@ LintMdFiles() # Get list of all files to lint # ################################# # shellcheck disable=SC2207 - LIST_FILES=($(find . -type f -name "*.md" 2>&1)) + LIST_FILES=($(find "$GITHUB_WORKSPACE" -type f -name "*.md" 2>&1)) ################## # Lint the files # @@ -478,9 +610,9 @@ LintBashFiles() # print header # ################ echo "" - echo "--------------------------------" + echo "----------------------------------------------" echo "Linting Bash files..." - echo "--------------------------------" + echo "----------------------------------------------" echo "" ###################### @@ -517,7 +649,7 @@ LintBashFiles() # Get list of all files to lint # ################################# # shellcheck disable=SC2207 - LIST_FILES=($(find . -type f -name "*.sh" 2>&1)) + LIST_FILES=($(find "$GITHUB_WORKSPACE" -type f -name "*.sh" 2>&1)) ################## # Lint the files # @@ -581,9 +713,9 @@ LintPythonFiles() # print header # ################ echo "" - echo "--------------------------------" + echo "----------------------------------------------" echo "Linting Python files..." - echo "--------------------------------" + echo "----------------------------------------------" echo "" ###################### @@ -620,7 +752,7 @@ LintPythonFiles() # Get list of all files to lint # ################################# # shellcheck disable=SC2207 - LIST_FILES=($(find . -type f -name "*.py" 2>&1)) + LIST_FILES=($(find "$GITHUB_WORKSPACE" -type f -name "*.py" 2>&1)) ################## # Lint the files # @@ -650,7 +782,7 @@ LintPythonFiles() ################################ # Lint the file with the rules # ################################ - LINT_CMD=$("$LINTER_NAME" --rcfile "$PYTHON_LINTER_FILE" -E "$FILE" 2>&1) + LINT_CMD=$("$LINTER_NAME" --rcfile "$PYTHON_LINTER_RULES" -E "$FILE" 2>&1) ####################### # Load the error code # @@ -684,9 +816,9 @@ LintPerlFiles() # print header # ################ echo "" - echo "--------------------------------" + echo "----------------------------------------------" echo "Linting Perl files..." - echo "--------------------------------" + echo "----------------------------------------------" echo "" ###################### @@ -723,7 +855,7 @@ LintPerlFiles() # Get list of all files to lint # ################################# # shellcheck disable=SC2207 - LIST_FILES=($(find . -type f -name "*.pl" 2>&1)) + LIST_FILES=($(find "$GITHUB_WORKSPACE" -type f -name "*.pl" 2>&1)) ################## # Lint the files # @@ -787,9 +919,9 @@ LintRubyFiles() # print header # ################ echo "" - echo "--------------------------------" + echo "----------------------------------------------" echo "Linting Ruby files..." - echo "--------------------------------" + echo "----------------------------------------------" echo "" ###################### @@ -826,7 +958,7 @@ LintRubyFiles() # Get list of all files to lint # ################################# # shellcheck disable=SC2207 - LIST_FILES=($(find . -type f -name "*.rb" 2>&1)) + LIST_FILES=($(find "$GITHUB_WORKSPACE" -type f -name "*.rb" 2>&1)) ################## # Lint the files # @@ -856,7 +988,7 @@ LintRubyFiles() ################################ # Lint the file with the rules # ################################ - LINT_CMD=$("$LINTER_NAME" -c "$RUBY_LINTER_FILE" "$FILE" 2>&1) + LINT_CMD=$("$LINTER_NAME" -c "$RUBY_LINTER_RULES" "$FILE" 2>&1) ####################### # Load the error code # @@ -890,9 +1022,9 @@ LintCoffeeFiles() # print header # ################ echo "" - echo "--------------------------------" + echo "----------------------------------------------" echo "Linting Coffee files..." - echo "--------------------------------" + echo "----------------------------------------------" echo "" ###################### @@ -929,7 +1061,7 @@ LintCoffeeFiles() # Get list of all files to lint # ################################# # shellcheck disable=SC2207 - LIST_FILES=($(find . -type f -name "*.coffee" 2>&1)) + LIST_FILES=($(find "$GITHUB_WORKSPACE" -type f -name "*.coffee" 2>&1)) ################## # Lint the files # @@ -959,7 +1091,7 @@ LintCoffeeFiles() ################################ # Lint the file with the rules # ################################ - LINT_CMD=$("$LINTER_NAME" -f "$COFFEE_LINTER_FILE" "$FILE" 2>&1) + LINT_CMD=$("$LINTER_NAME" -f "$COFFEE_LINTER_RULES" "$FILE" 2>&1) ####################### # Load the error code # @@ -986,6 +1118,87 @@ LintCoffeeFiles() done } ################################################################################ +#### Function GetGitHubVars #################################################### +GetGitHubVars() +{ + ########## + # Prints # + ########## + echo "--------------------------------------------" + echo "Gathering GitHub information..." + + ############################ + # Validate we have a value # + ############################ + if [ -z "$GITHUB_SHA" ]; then + echo "ERROR! Failed to get [GITHUB_SHA]!" + echo "ERROR:[$GITHUB_SHA]" + exit 1 + else + echo "Successfully found:[GITHUB_SHA]" + fi + + ############################ + # Validate we have a value # + ############################ + if [ -z "$GITHUB_WORKSPACE" ]; then + echo "ERROR! Failed to get [GITHUB_WORKSPACE]!" + echo "ERROR:[$GITHUB_WORKSPACE]" + exit 1 + else + echo "Successfully found:[GITHUB_WORKSPACE]" + fi + + ############################ + # Validate we have a value # + ############################ + if [ -z "$GITHUB_EVENT_PATH" ]; then + echo "ERROR! Failed to get [GITHUB_EVENT_PATH]!" + echo "ERROR:[$GITHUB_EVENT_PATH]" + exit 1 + else + echo "Successfully found:[GITHUB_EVENT_PATH]" + fi + + ################################################## + # Need to pull the GitHub Vars from the env file # + ################################################## + + ###################### + # Get the GitHub Org # + ###################### + # shellcheck disable=SC2002 + GITHUB_ORG=$(cat "$GITHUB_EVENT_PATH" | jq -r '.repository.owner.login' ) + + ############################ + # Validate we have a value # + ############################ + if [ -z "$GITHUB_ORG" ]; then + echo "ERROR! Failed to get [GITHUB_ORG]!" + echo "ERROR:[$GITHUB_ORG]" + exit 1 + else + echo "Successfully found:[GITHUB_ORG]" + fi + + ####################### + # Get the GitHub Repo # + ####################### + # shellcheck disable=SC2002 + GITHUB_REPO=$(cat "$GITHUB_EVENT_PATH"| jq -r '.repository.name' ) + + ############################ + # Validate we have a value # + ############################ + if [ -z "$GITHUB_REPO" ]; then + echo "ERROR! Failed to get [GITHUB_REPO]!" + echo "ERROR:[$GITHUB_REPO]" + exit 1 + else + echo "Successfully found:[GITHUB_REPO]" + fi +} +################################################################################ #### Function Footer ########################################################### Footer() { @@ -1006,7 +1219,14 @@ Footer() ############################### # Exit with 1 if errors found # ############################### - if [ $ERRORS_FOUND_YML -ne 0 ] || [ $ERRORS_FOUND_JSON -ne 0 ] || [ $ERRORS_FOUND_XML -ne 0 ] || [ $ERRORS_FOUND_MD -ne 0 ] || [ $ERRORS_FOUND_BASH -ne 0 ] || [ $ERRORS_FOUND_PERL -ne 0 ] || [ $ERRORS_FOUND_PYTHON -ne 0 ] || [ $ERRORS_FOUND_RUBY -ne 0 ]; then + if [ $ERRORS_FOUND_YML -ne 0 ] || \ + [ $ERRORS_FOUND_JSON -ne 0 ] || \ + [ $ERRORS_FOUND_XML -ne 0 ] || \ + [ $ERRORS_FOUND_MD -ne 0 ] || \ + [ $ERRORS_FOUND_BASH -ne 0 ] || \ + [ $ERRORS_FOUND_PERL -ne 0 ] || \ + [ $ERRORS_FOUND_PYTHON -ne 0 ] || \ + [ $ERRORS_FOUND_RUBY -ne 0 ]; then # Failed exit echo "Exiting with errors found!" exit 1 @@ -1024,11 +1244,22 @@ Footer() ########## Header +####################### +# Get Github Env Vars # +####################### +# Need to pull in all the Github variables +# needed to connect back and update checks +GetGitHubVars + ######################## # Get the linter rules # ######################## GetLinterRules +###################### +# Validate workspace # +###################### + ###################### # Lint the Yml Files # ######################