From 0404c39203a47381ca5e7681c62ed9bb8bb1521f Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 28 Aug 2020 09:56:53 -0500 Subject: [PATCH 1/4] adding exec --- .automation/test/shell/shell_good_1.sh | 0 Dockerfile | 7 +++++++ README.md | 3 ++- lib/linter.sh | 18 ++++++++++++++++-- lib/worker.sh | 1 + 5 files changed, 26 insertions(+), 3 deletions(-) mode change 100644 => 100755 .automation/test/shell/shell_good_1.sh diff --git a/.automation/test/shell/shell_good_1.sh b/.automation/test/shell/shell_good_1.sh old mode 100644 new mode 100755 diff --git a/Dockerfile b/Dockerfile index 0c0d032a..32e81ef5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -216,6 +216,12 @@ RUN wget --tries=5 https://storage.googleapis.com/dart-archive/channels/stable/r && mv dart-sdk/bin/* /usr/bin/ && mv dart-sdk/lib/* /usr/lib/ && mv dart-sdk/include/* /usr/include/ \ && rm -r dart-sdk/ +################################ +# Create and install Bash-Exec # +################################ +RUN printf '#!/bin/bash \n\nif [[ -x "$1" ]]; then exit 0; else echo "Error: File:[$1] is not executable"; exit 1; fi' > /usr/bin/bash-exec \ + && chmod +x /usr/bin/bash-exec + ################ # Install Raku # ################ @@ -291,6 +297,7 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ VALIDATE_ANSIBLE=${VALIDATE_ANSIBLE} \ VALIDATE_ARM=${VALIDATE_ARM} \ VALIDATE_BASH=${VALIDATE_BASH} \ + VALIDATE_BASH_EXEC=${VALIDATE_BASH_EXEC} \ VALIDATE_CLOJURE=${VALIDATE_CLOJURE} \ VALIDATE_CLOUDFORMATION=${VALIDATE_CLOUDFORMATION} \ VALIDATE_COFFEE=${VALIDATE_COFFEE} \ diff --git a/README.md b/README.md index 33d5d34c..f2e0b516 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **R** | [lintr](https://github.com/jimhester/lintr) | | **Raku** | [Raku](https://raku.org) | | **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) | -| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) | +| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) / [Bash-exec] | | **SQL** | [sql-lint](https://github.com/joereynolds/sql-lint) | | **Terraform** | [tflint](https://github.com/terraform-linters/tflint) / [terrascan](https://github.com/accurics/terrascan) | | **TypeScript** | [eslint](https://eslint.org/) / [standard js](https://standardjs.com/) | @@ -196,6 +196,7 @@ But if you wish to select or exclude specific linters, we give you full control | **VALIDATE_ANSIBLE** | `true` | Flag to enable or disable the linting process of the Ansible language. | | **VALIDATE_ARM** | `true` | Flag to enable or disable the linting process of the ARM language. | | **VALIDATE_BASH** | `true` | Flag to enable or disable the linting process of the Bash language. | +| **VALIDATE_BASH_EXEC** | `true` | Flag to enable or disable the linting process of the Bash language to validate if file is stored as executable. | | **VALIDATE_CLOJURE** | `true` | Flag to enable or disable the linting process of the Clojure language. | | **VALIDATE_CLOUDFORMATION** | `true` | Flag to enable or disable the linting process of the AWS Cloud Formation language. | | **VALIDATE_COFFEE** | `true` | Flag to enable or disable the linting process of the Coffeescript language . | diff --git a/lib/linter.sh b/lib/linter.sh index 4e17890d..01a85925 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -133,7 +133,7 @@ YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" # Path to the ya ####################################### # Linter array for information prints # ####################################### -LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'black' 'cfn-lint' 'checkstyle' 'chktex' 'clj-kondo' 'coffeelint' +LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'black' 'bash-exec' 'cfn-lint' 'checkstyle' 'chktex' 'clj-kondo' 'coffeelint' 'dart' 'dockerfilelint' 'dotenv-linter' 'editorconfig-checker' 'eslint' 'flake8' 'golangci-lint' 'hadolint' 'htmlhint' 'jsonlint' 'ktlint' 'lintr' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'sql-lint' @@ -142,7 +142,7 @@ LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'black' 'cfn-lint' 'check ############################# # Language array for prints # ############################# -LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' +LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH-EXEC' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' 'DART' 'DOCKERFILE' 'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVA' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL' @@ -174,6 +174,7 @@ VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean t VALIDATE_ANSIBLE="${VALIDATE_ANSIBLE}" # Boolean to validate language VALIDATE_ARM="${VALIDATE_ARM}" # Boolean to validate language VALIDATE_BASH="${VALIDATE_BASH}" # Boolean to validate language +VALIDATE_BASH_EXEC="${VALIDATE_BASH_EXEC}" # Boolean to validate language VALIDATE_CLOUDFORMATION="${VALIDATE_CLOUDFORMATION}" # Boolean to validate language VALIDATE_CLOJURE="${VALIDATE_CLOJURE}" # Boolean to validate language VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language @@ -327,6 +328,8 @@ ERRORS_FOUND_ARM=0 # Count of errors found export ERRORS_FOUND_ARM # Workaround SC2034 ERRORS_FOUND_BASH=0 # Count of errors found export ERRORS_FOUND_BASH # Workaround SC2034 +ERRORS_FOUND_BASH_EXEC=0 # Count of errors found +export ERRORS_FOUND_BASH_EXEC # Workaround SC2034 ERRORS_FOUND_CLOUDFORMATION=0 # Count of errors found export ERRORS_FOUND_CLOUDFORMATION # Workaround SC2034 ERRORS_FOUND_CLOJURE=0 # Count of errors found @@ -1362,6 +1365,17 @@ if [ "${VALIDATE_BASH}" == "true" ]; then LintCodebase "BASH" "shellcheck" "shellcheck --color --external-sources" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" fi +##################### +# BASH-EXEC LINTING # +##################### +if [ "${VALIDATE_BASH_EXEC}" == "true" ]; then + ####################### + # Lint the bash files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "BASH-EXEC" "bash-exec" "bash-exec" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" +fi + ########################## # CLOUDFORMATION LINTING # ########################## diff --git a/lib/worker.sh b/lib/worker.sh index 16f0a8ba..d21b5552 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -614,6 +614,7 @@ function RunTestCases() { TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c ${ANSIBLE_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "ansible" TestCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" ".*\.\(json\)\$" "arm" TestCodebase "BASH" "shellcheck" "shellcheck --color --external-sources" ".*\.\(sh\|bash\|dash\|ksh\)\$" "shell" + TestCodebase "BASH-EXEC" "bash-exec" "bash-exec" ".*\.\(sh\|bash\|dash\|ksh\)\$" "shell" TestCodebase "CLOUDFORMATION" "cfn-lint" "cfn-lint --config-file ${CLOUDFORMATION_LINTER_RULES}" ".*\.\(json\|yml\|yaml\)\$" "cloudformation" TestCodebase "CLOJURE" "clj-kondo" "clj-kondo --config ${CLOJURE_LINTER_RULES} --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$" "clojure" TestCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f ${COFFEESCRIPT_LINTER_RULES}" ".*\.\(coffee\)\$" "coffeescript" From 920f7b673bbf701516ec7e158cd89d39201a23c9 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 28 Aug 2020 10:08:21 -0500 Subject: [PATCH 2/4] adding warning --- lib/worker.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/worker.sh b/lib/worker.sh index d21b5552..5e4acdb4 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -247,14 +247,22 @@ function LintCodebase() { # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ]; then - ######### - # Error # - ######### - error "Found errors in [${LINTER_NAME}] linter!" - error "[${LINT_CMD}]" - error "Linter CMD:[${LINTER_COMMAND} ${FILE}]" - # Increment the error count - (("ERRORS_FOUND_${FILE_TYPE}++")) + if [[ ${FILE_TYPE} == "BASH-EXEC" ]]; + ######## + # WARN # + ######## + warn "Warnings found in [${LINTER_NAME}] linter!" + warn "${LINT_CMD}" + else + ######### + # Error # + ######### + error "Found errors in [${LINTER_NAME}] linter!" + error "[${LINT_CMD}]" + error "Linter CMD:[${LINTER_COMMAND} ${FILE}]" + # Increment the error count + (("ERRORS_FOUND_${FILE_TYPE}++")) + fi ####################################################### # Store the linting as a temporary file in TAP format # From 40fddbad7912560ec92038635eaebd12ed04d490 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 28 Aug 2020 10:12:02 -0500 Subject: [PATCH 3/4] get name even --- lib/linter.sh | 6 +++--- lib/worker.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 01a85925..4a7f26b7 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -142,7 +142,7 @@ LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'black' 'bash-exec' 'cfn- ############################# # Language array for prints # ############################# -LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH-EXEC' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' +LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' 'DART' 'DOCKERFILE' 'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVA' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL' @@ -1366,14 +1366,14 @@ if [ "${VALIDATE_BASH}" == "true" ]; then fi ##################### -# BASH-EXEC LINTING # +# BASH_EXEC LINTING # ##################### if [ "${VALIDATE_BASH_EXEC}" == "true" ]; then ####################### # Lint the bash files # ####################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "BASH-EXEC" "bash-exec" "bash-exec" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" + LintCodebase "BASH_EXEC" "bash-exec" "bash-exec" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" fi ########################## diff --git a/lib/worker.sh b/lib/worker.sh index 5e4acdb4..c153e125 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -247,7 +247,7 @@ function LintCodebase() { # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ]; then - if [[ ${FILE_TYPE} == "BASH-EXEC" ]]; + if [[ ${FILE_TYPE} == "BASH_EXEC" ]]; ######## # WARN # ######## @@ -622,7 +622,7 @@ function RunTestCases() { TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c ${ANSIBLE_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "ansible" TestCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" ".*\.\(json\)\$" "arm" TestCodebase "BASH" "shellcheck" "shellcheck --color --external-sources" ".*\.\(sh\|bash\|dash\|ksh\)\$" "shell" - TestCodebase "BASH-EXEC" "bash-exec" "bash-exec" ".*\.\(sh\|bash\|dash\|ksh\)\$" "shell" + TestCodebase "BASH_EXEC" "bash-exec" "bash-exec" ".*\.\(sh\|bash\|dash\|ksh\)\$" "shell" TestCodebase "CLOUDFORMATION" "cfn-lint" "cfn-lint --config-file ${CLOUDFORMATION_LINTER_RULES}" ".*\.\(json\|yml\|yaml\)\$" "cloudformation" TestCodebase "CLOJURE" "clj-kondo" "clj-kondo --config ${CLOJURE_LINTER_RULES} --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$" "clojure" TestCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f ${COFFEESCRIPT_LINTER_RULES}" ".*\.\(coffee\)\$" "coffeescript" From a35df1c943e65249299e016c3868085243567388 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 28 Aug 2020 10:15:44 -0500 Subject: [PATCH 4/4] its friday --- lib/worker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/worker.sh b/lib/worker.sh index c153e125..7432f9b6 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -247,7 +247,7 @@ function LintCodebase() { # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ]; then - if [[ ${FILE_TYPE} == "BASH_EXEC" ]]; + if [[ ${FILE_TYPE} == "BASH_EXEC" ]]; then ######## # WARN # ########