From f2045eb49664d5801e2357f01a84bb2e7ff5d6ae Mon Sep 17 00:00:00 2001 From: Gabo Date: Fri, 24 Jul 2020 11:20:22 -0500 Subject: [PATCH 01/52] Fix YAML --- lib/buildFileList.sh | 2 +- lib/linter.sh | 14 +++++++------- lib/worker.sh | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 00aebf1f..2efc0fb3 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -106,7 +106,7 @@ function BuildFileList() { ################################ # Append the file to the array # ################################ - FILE_ARRAY_YML+=("${FILE}") + FILE_ARRAY_YAML+=("${FILE}") ########################################################## # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## diff --git a/lib/linter.sh b/lib/linter.sh index d712ab4b..6b2c8028 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -109,7 +109,7 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP' 'POWERSHELL' 'PROTOBUF' 'PYTHON' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' - 'TYPESCRIPT_STANDARD' 'XML' 'YML') + 'TYPESCRIPT_STANDARD' 'XML' 'YAML') ############################################ # Array for all languages that were linted # @@ -242,7 +242,7 @@ FILE_ARRAY_TSX=() # Array of files to check FILE_ARRAY_TYPESCRIPT_ES=() # Array of files to check FILE_ARRAY_TYPESCRIPT_STANDARD=() # Array of files to check FILE_ARRAY_XML=() # Array of files to check -FILE_ARRAY_YML=() # Array of files to check +FILE_ARRAY_YAML=() # Array of files to check ############ # Counters # @@ -315,8 +315,8 @@ ERRORS_FOUND_TYPESCRIPT_ES=0 # Count of errors found export ERRORS_FOUND_TYPESCRIPT_ES # Workaround SC2034 ERRORS_FOUND_XML=0 # Count of errors found export ERRORS_FOUND_XML # Workaround SC2034 -ERRORS_FOUND_YML=0 # Count of errors found -export ERRORS_FOUND_YML # Workaround SC2034 +ERRORS_FOUND_YAML=0 # Count of errors found +export ERRORS_FOUND_YAML # Workaround SC2034 ################################################################################ ########################## FUNCTIONS BELOW ##################################### @@ -1092,7 +1092,7 @@ GetLinterRules "RUBY" GetLinterRules "TERRAFORM" # Get TypeScript rules GetLinterRules "TYPESCRIPT" -# Get YML rules +# Get YAML rules GetLinterRules "YAML" ################################# @@ -1623,14 +1623,14 @@ if [ "${VALIDATE_XML}" == "true" ]; then fi ############### -# YML LINTING # +# YAML LINTING # ############### if [ "${VALIDATE_YAML}" == "true" ]; then ###################### # Lint the Yml Files # ###################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "YML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "${FILE_ARRAY_YML[@]}" + LintCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "${FILE_ARRAY_YAML[@]}" fi ########### diff --git a/lib/worker.sh b/lib/worker.sh index a7da7f04..70141d10 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -610,7 +610,7 @@ function RunTestCases() { TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" TestCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "xml" - TestCodebase "YML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "yml" + TestCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "yml" ################# # Footer prints # From 5fa6aca5c266e61a486a6d681b61a9cc7cd07f0f Mon Sep 17 00:00:00 2001 From: Casey Vega Date: Fri, 24 Jul 2020 10:27:54 -0700 Subject: [PATCH 02/52] add lua to super-linter --- .automation/test/lua/README.md | 13 +++++++++ .automation/test/lua/lua_bad_1.lua | 9 +++++++ .automation/test/lua/lua_good_1.lua | 12 +++++++++ .github/linters/.luacheckrc | 1 + Dockerfile | 22 ++++++++++++++++ README.md | 2 ++ TEMPLATES/.luacheckrc | 1 + docs/disabling-linters.md | 41 +++++++++++++++++++++++++++++ lib/buildFileList.sh | 9 +++++++ lib/linter.sh | 24 +++++++++++++++-- lib/worker.sh | 1 + 11 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 .automation/test/lua/README.md create mode 100644 .automation/test/lua/lua_bad_1.lua create mode 100644 .automation/test/lua/lua_good_1.lua create mode 100644 .github/linters/.luacheckrc create mode 100644 TEMPLATES/.luacheckrc diff --git a/.automation/test/lua/README.md b/.automation/test/lua/README.md new file mode 100644 index 00000000..db695378 --- /dev/null +++ b/.automation/test/lua/README.md @@ -0,0 +1,13 @@ +# Lua Test Cases +This folder holds the test cases for **Lua**. + +## Additional Docs +No Additional information is needed for this test case. + +## Good Test Cases +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. +- **Note:** They are linted utilizing the default linter rules. \ No newline at end of file diff --git a/.automation/test/lua/lua_bad_1.lua b/.automation/test/lua/lua_bad_1.lua new file mode 100644 index 00000000..2c31e39d --- /dev/null +++ b/.automation/test/lua/lua_bad_1.lua @@ -0,0 +1,9 @@ +package.loaded[...] = {} + +local function helper(...) + -- NYI +end + +function embrace(opt) + local opt = opt or "default" + return hepler(opt.."?") diff --git a/.automation/test/lua/lua_good_1.lua b/.automation/test/lua/lua_good_1.lua new file mode 100644 index 00000000..f7ade80b --- /dev/null +++ b/.automation/test/lua/lua_good_1.lua @@ -0,0 +1,12 @@ +local embracer = {} + +local function helper() + -- NYI wontfix +end + +function embracer.embrace(opt) + opt = opt or "default" + return helper(opt.."?") +end + +return embracer diff --git a/.github/linters/.luacheckrc b/.github/linters/.luacheckrc new file mode 100644 index 00000000..00aa308f --- /dev/null +++ b/.github/linters/.luacheckrc @@ -0,0 +1 @@ +--std max diff --git a/Dockerfile b/Dockerfile index 2d143824..57540fce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,12 +52,14 @@ ARG GLIBC_VERSION='2.31-r0' RUN apk add --update --no-cache \ ansible-lint \ bash \ + coreutils \ curl \ gcc \ git git-lfs\ go \ icu-libs \ jq \ + libc-dev \ libxml2-utils \ make \ musl-dev \ @@ -66,6 +68,7 @@ RUN apk add --update --no-cache \ perl \ php7 \ py3-setuptools \ + readline-dev \ ruby ruby-dev ruby-bundler ruby-rdoc ######################################## @@ -183,6 +186,24 @@ RUN wget https://storage.googleapis.com/dart-archive/channels/stable/release/${D RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories \ && apk add --update --no-cache rakudo zef +#################### +# Install luacheck # +#################### +RUN wget https://www.lua.org/ftp/lua-5.3.5.tar.gz -O - -q | tar -xzf - \ + && cd lua-5.3.5 \ + && make linux \ + && make install \ + && cd .. && rm -r lua-5.3.5/ + +RUN wget https://github.com/cvega/luarocks/archive/v3.3.1-super-linter.tar.gz -O - -q | tar -xzf - \ + && cd luarocks-3.3.1-super-linter \ + && ./configure --with-lua-include=/usr/local/include \ + && make \ + && make -b install \ + && cd .. && rm -r luarocks-3.3.1-super-linter/ + +RUN luarocks install luacheck + ########################################### # Load GitHub Env Vars for GitHub Actions # ########################################### @@ -218,6 +239,7 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ VALIDATE_JAVASCRIPT_STANDARD=${VALIDATE_JAVASCRIPT_STANDARD} \ VALIDATE_JSON=${VALIDATE_JSON} \ VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \ + VALIDATE_LUA=${VALIDATE_LUA} \ VALIDATE_MD=${VALIDATE_MD} \ VALIDATE_OPENAPI=${VALIDATE_OPENAPI} \ VALIDATE_PERL=${VALIDATE_PERL} \ diff --git a/README.md b/README.md index e9dd76be..10aa67be 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | | **JSON** | [jsonlint](https://github.com/zaach/jsonlint) | | **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | +| **Lua** | [luacheck](https://github.com/luarocks/luacheck) | | **Markdown** | [markdownlint](https://github.com/igorshubovych/markdownlint-cli#readme) | | **OpenAPI** | [spectral](https://github.com/stoplightio/spectral) | | **Perl** | [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) | @@ -201,6 +202,7 @@ and won't run anything unexpected. | **VALIDATE_JSON** | `true` | Flag to enable or disable the linting process of the JSON language. | | **VALIDATE_JSX** | `true` | Flag to enable or disable the linting process for jsx files (Utilizing: eslint) | | **VALIDATE_KOTLIN** | `true` | Flag to enable or disable the linting process of the Kotlin language. | +| **VALIDATE_LUA** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_MD** | `true` | Flag to enable or disable the linting process of the Markdown language. | | **VALIDATE_OPENAPI** | `true` | Flag to enable or disable the linting process of the OpenAPI language. | | **VALIDATE_PERL** | `true` | Flag to enable or disable the linting process of the Perl language. | diff --git a/TEMPLATES/.luacheckrc b/TEMPLATES/.luacheckrc new file mode 100644 index 00000000..00aa308f --- /dev/null +++ b/TEMPLATES/.luacheckrc @@ -0,0 +1 @@ +--std max diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 2d3632d4..fbdb578e 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -44,6 +44,7 @@ For some linters it is also possible to override rules on a case by case level w - [Clojure](#clojure) - [EDITORCONFIG-CHECKER](#editorconfig-checker) - [HTML](#html) +- [LUA](#lua) @@ -859,6 +860,46 @@ import package.b.* --- +## Lua +- [luarocks](https://github.com/luarocks/luacheck) + +### luacheck standard Config file +- `.github/linters/.luacheckrc` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.luacheckrc` +- See [luacheck](https://luacheck.readthedocs.io/en/stable/config.html) docs for additional + behaviors + +### luacheck disable single line +```lua +-- luacheck: globals g1 g2, ignore foo +local foo = g1(g2) -- No warnings emitted. +``` + +### luacheck disable code block +```lua +-- The following unused function is not reported. +local function f() -- luacheck: ignore + -- luacheck: globals g3 + g3() -- No warning. +end +``` + +### luacheck include/exclude files (via .luacheckrc) +```lua +include_files = {"src", "spec/*.lua", "scripts/*.lua", "*.rockspec", "*.luacheckrc"} +exclude_files = {"src/luacheck/vendor"} +``` + +### luacheck push/pop +```lua +-- luacheck: push ignore foo +foo() -- No warning. +-- luacheck: pop +foo() -- Warning is emitted. +``` +--- + ## Dart - [dartanalyzer](https://dart.dev/tools/dartanalyzer) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 00aebf1f..9d51364d 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -393,6 +393,15 @@ function BuildFileList() { # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 + elif [ "$FILE_TYPE" == "lua" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_LUA+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 ############################ # Get the Protocol Buffers files # ############################ diff --git a/lib/linter.sh b/lib/linter.sh index d712ab4b..ff2d8303 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -62,6 +62,9 @@ JAVASCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${JAVASCRIPT_FILE_NAME}" JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard # Default linter path LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory +# Lua Vars +LUA_FILE_NAME='.luacheckrc' # Name of the file +LUA_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${LUA_FILE_NAME}" # Path to the Lua lint rules # MD Vars MARKDOWN_FILE_NAME='.markdown-lint.yml' # Name of the file MARKDOWN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${MARKDOWN_FILE_NAME}" # Path to the markdown lint rules @@ -96,7 +99,7 @@ YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" ####################################### LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo' 'coffeelint' 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'golangci-lint' - 'htmlhint' 'jsonlint' 'ktlint' 'markdownlint' 'npm-groovy-lint' 'perl' + 'htmlhint' 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'terrascan' 'tflint' 'xmllint' 'yamllint') @@ -106,7 +109,7 @@ LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo' ############################# LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' - 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'MARKDOWN' 'OPENAPI' + 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP' 'POWERSHELL' 'PROTOBUF' 'PYTHON' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YML') @@ -151,6 +154,7 @@ VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to vali VALIDATE_JSON="${VALIDATE_JSON}" # Boolean to validate language VALIDATE_JSX="${VALIDATE_JSX}" # Boolean to validate language VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language +VALIDATE_LUA="${VALIDATE_LUA}" # Boolean to validate language VALIDATE_MARKDOWN="${VALIDATE_MD:-}" # Boolean to validate language VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language @@ -227,6 +231,7 @@ FILE_ARRAY_JAVASCRIPT_STANDARD=() # Array of files to check FILE_ARRAY_JSON=() # Array of files to check FILE_ARRAY_JSX=() # Array of files to check FILE_ARRAY_KOTLIN=() # Array of files to check +FILE_ARRAY_LUA=() # Array of files to check FILE_ARRAY_MARKDOWN=() # Array of files to check FILE_ARRAY_OPENAPI=() # Array of files to check FILE_ARRAY_PERL=() # Array of files to check @@ -283,6 +288,8 @@ ERRORS_FOUND_JSX=0 # Count of errors found export ERRORS_FOUND_JSX # Workaround SC2034 ERRORS_FOUND_KOTLIN=0 # Count of errors found export ERRORS_FOUND_KOTLIN # Workaround SC2034 +ERRORS_FOUND_LUA=0 # Count of errors found +export ERRORS_FOUND_LUA=0 # Workaround SC2034 ERRORS_FOUND_MARKDOWN=0 # Count of errors found export ERRORS_FOUND_MARKDOWN # Workaround SC2034 ERRORS_FOUND_OPENAPI=0 # Count of errors found @@ -1080,6 +1087,8 @@ GetLinterRules "GROOVY" GetLinterRules "HTML" # Get JavaScript rules GetLinterRules "JAVASCRIPT" +# Get LUA rules +GetLinterRules "LUA" # Get Markdown rules GetLinterRules "MARKDOWN" # Get PowerShell rules @@ -1397,6 +1406,17 @@ if [ "${VALIDATE_KOTLIN}" == "true" ]; then LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}" fi +############### +# LUA LINTING # +############### +if [ "${VALIDATE_LUA}" == "true" ]; then + ###################### + # Lint the Lua files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "LUA" "lua" "luacheck --config ${LUA_LINTER_RULES}" ".*\.\(lua\)\$" "${FILE_ARRAY_LUA[@]}" +fi + #################### # MARKDOWN LINTING # #################### diff --git a/lib/worker.sh b/lib/worker.sh index a7da7f04..4a2c0b1a 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -595,6 +595,7 @@ function RunTestCases() { TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript" TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json" TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin" + TestCodebase "LUA" "lua" "luacheck" ".*\.\(lua\)\$" "lua" TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown" TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl" TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php" From 1c11a23fd36b632c9a82ce0a089e947661961ca3 Mon Sep 17 00:00:00 2001 From: Gabo Date: Fri, 24 Jul 2020 14:03:26 -0500 Subject: [PATCH 03/52] Allo to pass yamllint config file --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e9dd76be..f9c77028 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,8 @@ and won't run anything unexpected. | **VALIDATE_TYPESCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the Typescript language. (Utilizing: standard) | | **VALIDATE_XML** | `true` | Flag to enable or disable the linting process of the XML language. | | **VALIDATE_YAML** | `true` | Flag to enable or disable the linting process of the YAML language. | +| **YAML_CONFIG_FILE** | `.yaml-lint.yml` | Filename for [Yamllint configuration](https://yamllint.readthedocs.io/en/stable/configuration.html) (ex: `.yaml-lint.yml`, `.yamllint.yml`) | + ### Template rules files From eafc73332b71f997f8d0569cdb56022f300835c4 Mon Sep 17 00:00:00 2001 From: Gabo Date: Fri, 24 Jul 2020 14:05:03 -0500 Subject: [PATCH 04/52] Allow to pass yamllint config file --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 6b2c8028..9e51f010 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -88,7 +88,7 @@ TYPESCRIPT_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" TYPESCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${TYPESCRIPT_FILE_NAME}" # Path to the Typescript lint rules TYPESCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard # YAML Vars -YAML_FILE_NAME='.yaml-lint.yml' # Name of the file +YAML_FILE_NAME="${YAML_CONFIG_FILE:-.yaml-lint.yml}" # Name of the file YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" # Path to the yaml lint rules ####################################### From 67cde9602e2aab954b0c1ac9dd0e221a889ca62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=A0?= Date: Sun, 26 Jul 2020 21:30:45 +0200 Subject: [PATCH 05/52] Add support for PHPCS and Psalm config files --- TEMPLATES/phpcs.xml | 6 ++++++ TEMPLATES/psalm.xml | 4 ++++ lib/linter.sh | 10 ++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100755 TEMPLATES/phpcs.xml create mode 100755 TEMPLATES/psalm.xml diff --git a/TEMPLATES/phpcs.xml b/TEMPLATES/phpcs.xml new file mode 100755 index 00000000..b319d759 --- /dev/null +++ b/TEMPLATES/phpcs.xml @@ -0,0 +1,6 @@ + + + + The default coding standard for usage with super-linter. Just includes PSR12. + + diff --git a/TEMPLATES/psalm.xml b/TEMPLATES/psalm.xml new file mode 100755 index 00000000..0eb2e126 --- /dev/null +++ b/TEMPLATES/psalm.xml @@ -0,0 +1,4 @@ + + + + diff --git a/lib/linter.sh b/lib/linter.sh index 17aa4e98..c5a829fa 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -68,6 +68,12 @@ MARKDOWN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${MARKDOWN_FILE_NAME}" # OpenAPI Vars OPENAPI_FILE_NAME='.openapirc.yml' # Name of the file OPENAPI_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${OPENAPI_FILE_NAME}" # Path to the OpenAPI lint rules +# PHPCS Vars +PHP_PHPCS_FILE_NAME='phpcs.xml' # Name of the file +PHP_PHPCS_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PHP_PHPCS_FILE_NAME}" # Path to the PHP CodeSniffer lint rules +# Psalm Vars +PHP_PSALM_FILE_NAME='psalm.xml' # Name of the file +PHP_PSALM_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PHP_PSALM_FILE_NAME}" # Path to the Psalm lint rules # Powershell Vars POWERSHELL_FILE_NAME='.powershell-psscriptanalyzer.psd1' # Name of the file POWERSHELL_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${POWERSHELL_FILE_NAME}" # Path to the Powershell lint rules @@ -1474,7 +1480,7 @@ if [ "${VALIDATE_PHP_PHPCS}" == "true" ]; then # Lint the PHP files using PHP CodeSniffer # ############################################ # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PHP_PHPCS" "phpcs" "phpcs" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PHPCS[@]}" + LintCodebase "PHP_PHPCS" "phpcs" "phpcs --standard=${PHP_PHPCS_LINTER_RULES}" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PHPCS[@]}" fi if [ "${VALIDATE_PHP_PSALM}" == "true" ]; then @@ -1482,7 +1488,7 @@ if [ "${VALIDATE_PHP_PSALM}" == "true" ]; then # Lint the PHP files using Psalm # ################################## # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PHP_PSALM" "psalm" "psalm" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PSALM[@]}" + LintCodebase "PHP_PSALM" "psalm" "psalm --config=${PHP_PSALM_LINTER_RULES}" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PSALM[@]}" fi ###################### From a8802c1fa602d0c5d708ae228b0bdf8d0947ef91 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2020 05:43:15 +0000 Subject: [PATCH 06/52] Bump actions/stale from v3.0.8 to v3.0.9 Bumps [actions/stale](https://github.com/actions/stale) from v3.0.8 to v3.0.9. - [Release notes](https://github.com/actions/stale/releases) - [Commits](https://github.com/actions/stale/compare/v3.0.8...1e5e734da7bd7ea04daf52d9f1c6540e83867b73) Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 4aecddcb..aac6767a 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -29,7 +29,7 @@ jobs: if: "github.event_name == 'schedule'" steps: - name: Mark issue stale - uses: actions/stale@v3.0.8 + uses: actions/stale@v3.0.9 with: repo-token: ${{ secrets.GITHUB_TOKEN }} stale-issue-message: "This issue has been automatically marked as stale because it has not had recent activity.\nIt will be closed in 14 days if no further activity occurs.\nThank you for your contributions.\n\nIf you think this issue should stay open, please remove the `O: stale 🤖` label or comment on the issue." From 8495208874e5e5a728493c2842390edcad30a169 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2020 05:44:27 +0000 Subject: [PATCH 07/52] Bump borkdude/clj-kondo from 2020.06.21 to 2020.07.26 Bumps borkdude/clj-kondo from 2020.06.21 to 2020.07.26. Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2d143824..b5bbefca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ ######################################### # Get dependency images as build stages # ######################################### -FROM borkdude/clj-kondo:2020.06.21 as clj-kondo +FROM borkdude/clj-kondo:2020.07.26 as clj-kondo FROM dotenvlinter/dotenv-linter:2.1.0 as dotenv-linter FROM mstruebing/editorconfig-checker:2.1.0 as editorconfig-checker FROM golangci/golangci-lint:v1.29.0 as golangci-lint From cc7b68f98557202f4b957a0087f0d33aeef24b65 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2020 05:44:37 +0000 Subject: [PATCH 08/52] Bump yoheimuta/protolint from v0.25.1 to v0.26.0 Bumps yoheimuta/protolint from v0.25.1 to v0.26.0. Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2d143824..d842c658 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ FROM borkdude/clj-kondo:2020.06.21 as clj-kondo FROM dotenvlinter/dotenv-linter:2.1.0 as dotenv-linter FROM mstruebing/editorconfig-checker:2.1.0 as editorconfig-checker FROM golangci/golangci-lint:v1.29.0 as golangci-lint -FROM yoheimuta/protolint:v0.25.1 as protolint +FROM yoheimuta/protolint:v0.26.0 as protolint FROM koalaman/shellcheck:v0.7.1 as shellcheck FROM wata727/tflint:0.18.0 as tflint From 99cb8a7ef5dd807d67a91cc70a966308a6156839 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2020 05:46:58 +0000 Subject: [PATCH 09/52] Bump eslint-plugin-jest from 23.18.0 to 23.18.2 in /dependencies Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 23.18.0 to 23.18.2. - [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases) - [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/master/CHANGELOG.md) - [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v23.18.0...v23.18.2) Signed-off-by: dependabot[bot] --- dependencies/package-lock.json | 164 ++++++++++++++++++++++++++++++++- dependencies/package.json | 2 +- 2 files changed, 162 insertions(+), 4 deletions(-) diff --git a/dependencies/package-lock.json b/dependencies/package-lock.json index 06703cc7..31315d49 100644 --- a/dependencies/package-lock.json +++ b/dependencies/package-lock.json @@ -3,6 +3,20 @@ "requires": true, "lockfileVersion": 1, "dependencies": { + "@amplitude/node": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@amplitude/node/-/node-0.3.3.tgz", + "integrity": "sha512-Uzg4MRAuD053Ex67Iu2lm2GovnVte1uKI3q7CXlMCYZ9ylZmAkPbTnjg9OVyD4f+IiUfgK4p3bE7r9p7jqSDLA==", + "requires": { + "@amplitude/types": "^0.3.2", + "tslib": "^1.9.3" + } + }, + "@amplitude/types": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@amplitude/types/-/types-0.3.2.tgz", + "integrity": "sha512-7+m7nhJMFGbpsppOUsCH8f4FOFyAxgKFuXkKknU/LP2CMYVjWEIoLTKKgaJPc2c8wXaK5KPXVetb8VeiGbuaGg==" + }, "@babel/code-frame": { "version": "7.10.4", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", @@ -742,6 +756,14 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.0.tgz", "integrity": "sha512-3YDiu347mtVtjpyV3u5kVqQLP242c06zwDOgpeRnybmXlYYsLbtTrUBUm8i8srONt+FWobl5aibnU1030PeeuA==" }, + "axios": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", + "requires": { + "follow-redirects": "1.5.10" + } + }, "babel-eslint": { "version": "10.1.0", "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.1.0.tgz", @@ -950,6 +972,15 @@ "restore-cursor": "^3.1.0" } }, + "cli-progress": { + "version": "3.8.2", + "resolved": "https://registry.npmjs.org/cli-progress/-/cli-progress-3.8.2.tgz", + "integrity": "sha512-qRwBxLldMSfxB+YGFgNRaj5vyyHe1yMpVeDL79c+7puGujdKJHQHydgqXDcrkvQgJ5U/d3lpf6vffSoVVUftVQ==", + "requires": { + "colors": "^1.1.2", + "string-width": "^4.2.0" + } + }, "cli-width": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-3.0.0.tgz", @@ -1159,6 +1190,11 @@ "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.2.0.tgz", "integrity": "sha512-vDPw+rDgn3bZe1+F/pyEwb1oMG2XTlRVgAa6B4KccTEpYgF8w6eQllVbQcfIJnZyvzFtFpxnpGtx8dd7DJp/Rw==" }, + "decode-html": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/decode-html/-/decode-html-2.0.0.tgz", + "integrity": "sha1-fQqIfORCgOYJeKcH67f4CB/WHqo=" + }, "deep-extend": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.1.tgz", @@ -1847,9 +1883,9 @@ } }, "eslint-plugin-jest": { - "version": "23.18.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.18.0.tgz", - "integrity": "sha512-wLPM/Rm1SGhxrFQ2TKM/BYsYPhn7ch6ZEK92S2o/vGkAAnDXM0I4nTIo745RIX+VlCRMFgBuJEax6XfTHMdeKg==", + "version": "23.18.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.18.2.tgz", + "integrity": "sha512-afVOE47F0PENnRlnePUHgrDbv1tsDlTAVrjL051oUETB2ImzBwa5GfmUAUhDjAEuxH+xkE6DsmEpZ8obXzUMqQ==", "requires": { "@typescript-eslint/experimental-utils": "^2.5.0" }, @@ -2117,6 +2153,27 @@ "to-regex-range": "^5.0.1" } }, + "find-java-home": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/find-java-home/-/find-java-home-1.1.0.tgz", + "integrity": "sha512-bSTCKNZ193UM/+ZZoNDzICAEHcVywovkhsWCkZALjCvRXQ+zXTe/XATrrP4CpxkaP6YFhQJOpyRpH0P2U/woDA==", + "requires": { + "which": "~1.0.5", + "winreg": "~1.2.2" + }, + "dependencies": { + "which": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/which/-/which-1.0.9.tgz", + "integrity": "sha1-RgwdoPgQED0DIam2M6+eV15kSG8=" + } + } + }, + "find-package-json": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/find-package-json/-/find-package-json-1.2.0.tgz", + "integrity": "sha512-+SOGcLGYDJHtyqHd87ysBhmaeQ95oWspDKnMXBrnQ9Eq4OkLNqejgoaD8xVWu6GPa0B6roa6KinCMEMcVeqONw==" + }, "find-root": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz", @@ -2146,6 +2203,29 @@ "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz", "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==" }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + }, + "dependencies": { + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -2161,6 +2241,16 @@ "mime-types": "^2.1.12" } }, + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2934,6 +3024,14 @@ "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-2.2.1.tgz", "integrity": "sha512-o6/yDBYccGvTz1+QFevz6l6OBZ2+fMVu2JZ9CIhzsYRX4mjaK5IyX9eldUdCmga16zlgQxyrj5pt9kzuj2C02w==" }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "requires": { + "graceful-fs": "^4.1.6" + } + }, "jsonlint": { "version": "1.6.3", "resolved": "https://registry.npmjs.org/jsonlint/-/jsonlint-1.6.3.tgz", @@ -3472,6 +3570,37 @@ "resolved": "https://registry.npmjs.org/normalize-selector/-/normalize-selector-0.2.0.tgz", "integrity": "sha1-0LFF62kRicY6eNIB3E/bEpPvDAM=" }, + "npm-groovy-lint": { + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/npm-groovy-lint/-/npm-groovy-lint-5.7.0.tgz", + "integrity": "sha512-Cq/ncgmNMI6USeazp2gingZj73ia6M+rpR5LfBK8ATSEdRZuIsnKTIGTuqMc/hrZyU4oMN0C/PYQj4DTO+TRFQ==", + "requires": { + "@amplitude/node": "^0.3.3", + "ansi-colors": "^4.1.1", + "axios": "^0.19.2", + "cli-progress": "^3.6.0", + "debug": "^4.1.1", + "decode-html": "^2.0.0", + "find-java-home": "^1.1.0", + "find-package-json": "^1.2.0", + "fs-extra": "^8.1.0", + "glob": "^7.1.6", + "import-fresh": "^3.2.1", + "ip": "^1.1.5", + "optionator": "^0.8.3", + "semver": "^7.1.3", + "strip-json-comments": "^3.0.1", + "uuid": "^8.2.0", + "xml2js": "^0.4.23" + }, + "dependencies": { + "uuid": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.2.0.tgz", + "integrity": "sha512-CYpGiFTUrmI6OBMkAdjSDM0k5h8SkkiTP4WAjQgDgNB1S3Ou9VBEvr6q0Kv2H1mMk7IWfxYGpMH5sd5AvcIV2Q==" + } + } + }, "num2fraction": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/num2fraction/-/num2fraction-1.2.2.tgz", @@ -4445,6 +4574,11 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + }, "semver": { "version": "7.3.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", @@ -5301,6 +5435,11 @@ "unist-util-is": "^4.0.0" } }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -5397,6 +5536,11 @@ "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, + "winreg": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/winreg/-/winreg-1.2.4.tgz", + "integrity": "sha1-ugZWKbepJRMOFXeRCM9UCZDpjRs=" + }, "wolfy87-eventemitter": { "version": "5.2.9", "resolved": "https://registry.npmjs.org/wolfy87-eventemitter/-/wolfy87-eventemitter-5.2.9.tgz", @@ -5446,6 +5590,20 @@ "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", "integrity": "sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=" }, + "xml2js": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", + "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "requires": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + } + }, + "xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" + }, "xregexp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-2.0.0.tgz", diff --git a/dependencies/package.json b/dependencies/package.json index 6e1d4695..b493cb56 100644 --- a/dependencies/package.json +++ b/dependencies/package.json @@ -9,7 +9,7 @@ "dockerfilelint": "^1.5.0", "eslint": "^7.5.0", "eslint-config-prettier": "^6.11.0", - "eslint-plugin-jest": "^23.18.0", + "eslint-plugin-jest": "^23.18.2", "htmlhint": "^0.14.1", "jsonlint": "^1.6.3", "markdownlint-cli": "^0.23.2", From 9fc054ab16f36f5cd74979912bf7e9ab16cbfc73 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Mon, 27 Jul 2020 16:11:33 -0500 Subject: [PATCH 10/52] Add log functions --- lib/linter.sh | 15 ++++++++++++++- lib/log.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 lib/log.sh diff --git a/lib/linter.sh b/lib/linter.sh index 5ccbafaf..f613ec16 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -10,7 +10,7 @@ # Source Function Files # ######################### # shellcheck source=/dev/null -source /action/lib/termColors.sh # Source the function script(s) +source /action/lib/log.sh # Source the function script(s) # shellcheck source=/dev/null source /action/lib/buildFileList.sh # Source the function script(s) # shellcheck source=/dev/null @@ -1030,6 +1030,19 @@ Footer() { exit 0 } + +################################################################################ +#### Function Cleanup ########################################################## +cleanup() { + local -ri EXIT_CODE=$? + + sudo sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/super-linter.log" || true + + exit ${EXIT_CODE} + trap - 0 1 2 3 6 14 15 +} +trap 'cleanup' 0 1 2 3 6 14 15 + ################################################################################ ############################### MAIN ########################################### ################################################################################ diff --git a/lib/log.sh b/lib/log.sh new file mode 100644 index 00000000..532a60a5 --- /dev/null +++ b/lib/log.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +declare -Agr B=( + [B]=$(echo -e "\e[44m") + [C]=$(echo -e "\e[46m") + [G]=$(echo -e "\e[42m") + [K]=$(echo -e "\e[40m") + [M]=$(echo -e "\e[45m") + [R]=$(echo -e "\e[41m") + [W]=$(echo -e "\e[47m") + [Y]=$(echo -e "\e[43m") +) +declare -Agr F=( + [B]=$(echo -e "\e[0;34m") + [C]=$(echo -e "\e[0;36m") + [G]=$(echo -e "\e[0;32m") + [K]=$(echo -e "\e[0;30m") + [M]=$(echo -e "\e[0;35m") + [R]=$(echo -e "\e[0;31m") + [W]=$(echo -e "\e[0;37m") + [Y]=$(echo -e "\e[0;33m") +) +readonly NC=$(echo -e "\e[0m") + +export B +export F +export NC + +# Log Functions +LOG_TEMP=$(mktemp) || echo "Failed to create temporary log file." +export LOG_TEMP +echo "super-linter Log" > "${LOG_TEMP}" +log() { + local TOTERM=${1:-} + local MESSAGE=${2:-} + echo -e "${MESSAGE:-}" | ( + if [[ -n ${TOTERM} ]]; then + tee -a "${LOG_TEMP}" >&2 + else + cat >> "${LOG_TEMP}" 2>&1 + fi + ) +} +trace() { log "${TRACE:-}" "${NC}$(date +"%F %T") ${F[B]}[TRACE ]${NC} $*${NC}"; } +debug() { log "${DEBUG:-}" "${NC}$(date +"%F %T") ${F[B]}[DEBUG ]${NC} $*${NC}"; } +info() { log "${VERBOSE:-}" "${NC}$(date +"%F %T") ${F[B]}[INFO ]${NC} $*${NC}"; } +notice() { log "true" "${NC}$(date +"%F %T") ${F[G]}[NOTICE]${NC} $*${NC}"; } +warn() { log "true" "${NC}$(date +"%F %T") ${F[Y]}[WARN ]${NC} $*${NC}"; } +error() { log "true" "${NC}$(date +"%F %T") ${F[R]}[ERROR ]${NC} $*${NC}"; } +fatal() { + log "true" "${NC}$(date +"%F %T") ${B[R]}${F[W]}[FATAL ]${NC} $*${NC}" + exit 1 +} From af13245484c01c5deca66a936a6d19c3de50b2c6 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Mon, 27 Jul 2020 16:20:06 -0500 Subject: [PATCH 11/52] First pass at log functions --- .automation/cleanup-docker.sh | 49 +++----- .../templates/ghe-config-apply.sh | 15 ++- .automation/upload-docker.sh | 116 ++++++++---------- lib/buildFileList.sh | 21 ++-- lib/linter.sh | 100 +++++++-------- lib/worker.sh | 68 +++++----- 6 files changed, 160 insertions(+), 209 deletions(-) diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index 889c4d65..7910f17b 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -52,9 +52,8 @@ ValidateInput() { # Validate GITHUB_WORKSPACE # ############################ if [ -z "${GITHUB_WORKSPACE}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_WORKSPACE]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_WORKSPACE}]${NC}" - exit 1 + error "Failed to get [GITHUB_WORKSPACE]!${NC}" + fatal "[${GITHUB_WORKSPACE}]${NC}" else echo "Successfully found:[GITHUB_WORKSPACE], value:[${GITHUB_WORKSPACE}]" fi @@ -64,15 +63,14 @@ ValidateInput() { ####################### if [ -z "${IMAGE_REPO}" ]; then # No repo was pulled - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [IMAGE_REPO]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${IMAGE_REPO}]${NC}" - exit 1 + error "Failed to get [IMAGE_REPO]!${NC}" + fatal "[${IMAGE_REPO}]${NC}" elif [[ ${IMAGE_REPO} == "github/super-linter" ]]; then # Found our main repo echo "Successfully found:[IMAGE_REPO], value:[${IMAGE_REPO}]" else # This is a fork and we cant pull vars or any info - echo -e "${NC}${F[Y]}WARN!${NC} No image to cleanup as this is a forked branch, and not being built with current automation!${NC}" + warn "No image to cleanup as this is a forked branch, and not being built with current automation!${NC}" exit 0 fi @@ -80,9 +78,8 @@ ValidateInput() { # Validate IMAGE_VERSION # ########################## if [ -z "${IMAGE_VERSION}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [IMAGE_VERSION]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${IMAGE_VERSION}]${NC}" - exit 1 + error "Failed to get [IMAGE_VERSION]!${NC}" + fatal "[${IMAGE_VERSION}]${NC}" else echo "Successfully found:[IMAGE_VERSION], value:[${IMAGE_VERSION}]" fi @@ -91,9 +88,8 @@ ValidateInput() { # Validate DOCKER_USERNAME # ############################ if [ -z "${DOCKER_USERNAME}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_USERNAME]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKER_USERNAME}]${NC}" - exit 1 + error "Failed to get [DOCKER_USERNAME]!${NC}" + fatal "[${DOCKER_USERNAME}]${NC}" else echo "Successfully found:[DOCKER_USERNAME], value:[${DOCKER_USERNAME}]" fi @@ -102,9 +98,8 @@ ValidateInput() { # Validate DOCKER_PASSWORD # ############################ if [ -z "${DOCKER_PASSWORD}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_PASSWORD]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKER_PASSWORD}]${NC}" - exit 1 + error "Failed to get [DOCKER_PASSWORD]!${NC}" + fatal "[${DOCKER_PASSWORD}]${NC}" else echo "Successfully found:[DOCKER_PASSWORD], value:[********]" fi @@ -121,10 +116,9 @@ ValidateInput() { ############################################# # Image is 'latest' and we will not destroy # ############################################# - echo "Image Tag is set to:[latest]..." - echo "We will never destroy latest..." - echo "Bye!" - exit 1 + error "Image Tag is set to:[latest]..." + error "We will never destroy latest..." + fatal "Bye!" fi } ################################################################################ @@ -154,9 +148,8 @@ LoginToDocker() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to authenticate to DockerHub!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LOGIN_CMD}]${NC}" - exit 1 + error "Failed to authenticate to DockerHub!${NC}" + fatal "[${LOGIN_CMD}]${NC}" else # SUCCESS echo "Successfully authenticated to DockerHub!" @@ -193,9 +186,8 @@ RemoveImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to gain token from DockerHub!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${TOKEN}]${NC}" - exit 1 + error "Failed to gain token from DockerHub!${NC}" + fatal "[${TOKEN}]${NC}" else # SUCCESS echo "Successfully gained auth token from DockerHub!" @@ -218,9 +210,8 @@ RemoveImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to remove tag from DockerHub!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${REMOVE_CMD}]${NC}" - exit 1 + error "Failed to remove tag from DockerHub!${NC}" + fatal "[${REMOVE_CMD}]${NC}" else # SUCCESS echo "Successfully [removed] Docker image tag:[${IMAGE_VERSION}] from DockerHub!" diff --git a/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh b/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh index 2d4b0eec..227caabc 100644 --- a/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh +++ b/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh @@ -53,8 +53,8 @@ CheckGHEPid() # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to sleep!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${SLEEP_CMD}]${NC}" + error "Failed to sleep!${NC}" + error "[${SLEEP_CMD}]${NC}" echo "Will try to call apply as last effort..." #################################### # Call config apply as last effort # @@ -117,8 +117,8 @@ CheckGHEProcess() # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to sleep!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${SLEEP_CMD}]${NC}" + error "Failed to sleep!${NC}" + error "[${SLEEP_CMD}]${NC}" echo "Will try to call apply as last effort..." #################################### # Call config apply as last effort # @@ -161,12 +161,11 @@ RunConfigApply() ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Errors - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to run config apply command!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${APPLY_CMD}]${NC}" - exit 1 + error "Failed to run config apply command!${NC}" + fatal "[${APPLY_CMD}]${NC}" else # Success - echo -e "${NC}${F[B]}Successfully ran ${F[C]}${GHE_APPLY_COMMAND}${NC}" + notice "Successfully ran ${F[C]}${GHE_APPLY_COMMAND}${NC}" fi } ################################################################################ diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index 42ea1c65..d4fccdf8 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -58,22 +58,20 @@ ValidateInput() { # Validate GITHUB_WORKSPACE # ############################# if [ -z "${GITHUB_WORKSPACE}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_WORKSPACE]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_WORKSPACE}]${NC}" - exit 1 + error "Failed to get [GITHUB_WORKSPACE]!${NC}" + fatal "[${GITHUB_WORKSPACE}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}" + notice "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}" fi ##################### # Validate REGISTRY # ##################### if [ -z "${REGISTRY}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [REGISTRY]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${REGISTRY}]${NC}" - exit 1 + error "Failed to get [REGISTRY]!${NC}" + fatal "[${REGISTRY}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[REGISTRY]${F[B]}, value:${F[W]}[${REGISTRY}]${NC}" + notice "Successfully found:${F[W]}[REGISTRY]${F[B]}, value:${F[W]}[${REGISTRY}]${NC}" fi ##################################################### @@ -84,22 +82,20 @@ ValidateInput() { # Validate GPR_USERNAME # ######################### if [ -z "${GPR_USERNAME}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GPR_USERNAME]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GPR_USERNAME}]${NC}" - exit 1 + error "Failed to get [GPR_USERNAME]!${NC}" + fatal "[${GPR_USERNAME}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GPR_USERNAME]${F[B]}, value:${F[W]}[${GPR_USERNAME}]${NC}" + notice "Successfully found:${F[W]}[GPR_USERNAME]${F[B]}, value:${F[W]}[${GPR_USERNAME}]${NC}" fi ###################### # Validate GPR_TOKEN # ###################### if [ -z "${GPR_TOKEN}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GPR_TOKEN]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GPR_TOKEN}]${NC}" - exit 1 + error "Failed to get [GPR_TOKEN]!${NC}" + fatal "[${GPR_TOKEN}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GPR_TOKEN]${F[B]}, value:${F[W]}[********]${NC}" + notice "Successfully found:${F[W]}[GPR_TOKEN]${F[B]}, value:${F[W]}[********]${NC}" fi ######################################## # See if we need values for Ducker hub # @@ -109,41 +105,37 @@ ValidateInput() { # Validate DOCKER_USERNAME # ############################ if [ -z "${DOCKER_USERNAME}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_USERNAME]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKER_USERNAME}]${NC}" - exit 1 + error "Failed to get [DOCKER_USERNAME]!${NC}" + fatal "[${DOCKER_USERNAME}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[DOCKER_USERNAME]${F[B]}, value:${F[W]}[${DOCKER_USERNAME}]${NC}" + notice "Successfully found:${F[W]}[DOCKER_USERNAME]${F[B]}, value:${F[W]}[${DOCKER_USERNAME}]${NC}" fi ############################ # Validate DOCKER_PASSWORD # ############################ if [ -z "${DOCKER_PASSWORD}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_PASSWORD]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKER_PASSWORD}]${NC}" - exit 1 + error "Failed to get [DOCKER_PASSWORD]!${NC}" + fatal "[${DOCKER_PASSWORD}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[DOCKER_PASSWORD]${F[B]}, value:${F[B]}[********]${NC}" + notice "Successfully found:${F[W]}[DOCKER_PASSWORD]${F[B]}, value:${F[B]}[********]${NC}" fi ########################################### # We were not passed a registry to update # ########################################### else - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find a valid registry!${NC}" - echo "Registry:[${REGISTRY}]" - exit 1 + error "Failed to find a valid registry!${NC}" + fatal "Registry:[${REGISTRY}]" fi ####################### # Validate IMAGE_REPO # ####################### if [ -z "${IMAGE_REPO}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [IMAGE_REPO]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${IMAGE_REPO}]${NC}" - exit 1 + error "Failed to get [IMAGE_REPO]!${NC}" + fatal "[${IMAGE_REPO}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[IMAGE_REPO]${F[B]}, value:${F[W]}[${IMAGE_REPO}]${NC}" + notice "Successfully found:${F[W]}[IMAGE_REPO]${F[B]}, value:${F[W]}[${IMAGE_REPO}]${NC}" ############################################### # Need to see if GPR registry and update name # ############################################### @@ -158,7 +150,7 @@ ValidateInput() { # Validate IMAGE_VERSION # ########################## if [ -z "${IMAGE_VERSION}" ]; then - echo -e "${NC}${F[Y]}WARN!${NC} Failed to get [IMAGE_VERSION]!${NC}" + warn "Failed to get [IMAGE_VERSION]!${NC}" echo "Pulling from Branch Name..." ############################## # Get the name of the branch # @@ -174,9 +166,8 @@ ValidateInput() { # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get branch name!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${BRANCH_NAME}]${NC}" - exit 1 + error "Failed to get branch name!${NC}" + fatal "[${BRANCH_NAME}]${NC}" fi ################################## @@ -190,7 +181,7 @@ ValidateInput() { IMAGE_VERSION="${BRANCH_NAME}" echo "Tag:[${IMAGE_VERSION}]" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[IMAGE_VERSION]${F[B]}, value:${F[W]}[${IMAGE_VERSION}]${NC}" + notice "Successfully found:${F[W]}[IMAGE_VERSION]${F[B]}, value:${F[W]}[${IMAGE_VERSION}]${NC}" fi ################################## @@ -221,11 +212,10 @@ ValidateInput() { # Validate DOCKERFILE_PATH # ############################ if [ -z "${DOCKERFILE_PATH}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKERFILE_PATH]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKERFILE_PATH}]${NC}" - exit 1 + error "Failed to get [DOCKERFILE_PATH]!${NC}" + fatal "[${DOCKERFILE_PATH}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[DOCKERFILE_PATH]${F[B]}, value:${F[W]}[${DOCKERFILE_PATH}]${NC}" + notice "Successfully found:${F[W]}[DOCKERFILE_PATH]${F[B]}, value:${F[W]}[${DOCKERFILE_PATH}]${NC}" fi } ################################################################################ @@ -263,12 +253,11 @@ Authenticate() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to authenticate to ${NAME}!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LOGIN_CMD}]${NC}" - exit 1 - else + error "Failed to authenticate to ${NAME}!${NC}" + fatal "[${LOGIN_CMD}]${NC}" +fatal else # SUCCESS - echo -e "${NC}${F[B]}Successfully authenticated to ${F[C]}${NAME}${F[B]}!${NC}" + notice "Successfully authenticated to ${F[C]}${NAME}${F[B]}!${NC}" fi } ################################################################################ @@ -288,10 +277,9 @@ BuildImage() { ################################ if [ ! -f "${DOCKERFILE_PATH}" ]; then # No file found - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to find Dockerfile at:[${DOCKERFILE_PATH}]${NC}" - echo "Please make sure you give full path!" - echo "Example:[/configs/Dockerfile] or [Dockerfile] if at root directory" - exit 1 + error "failed to find Dockerfile at:[${DOCKERFILE_PATH}]${NC}" + error "Please make sure you give full path!" + fatal "Example:[/configs/Dockerfile] or [Dockerfile] if at root directory" fi ################### @@ -309,11 +297,10 @@ BuildImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [build] Dockerfile!${NC}" - exit 1 + fatal "failed to [build] Dockerfile!${NC}" else # SUCCESS - echo -e "${NC}${F[B]}Successfully Built image!${NC}" + notice "Successfully Built image!${NC}" fi ######################################################## @@ -333,11 +320,10 @@ BuildImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [tag] Dockerfile!${NC}" - exit 1 + fatal "failed to [tag] Dockerfile!${NC}" else # SUCCESS - echo -e "${NC}${F[B]}Successfully tagged image!${NC}" + notice "Successfully tagged image!${NC}" fi fi } @@ -368,11 +354,10 @@ UploadImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [upload] Dockerfile!${NC}" - exit 1 + fatal "failed to [upload] Dockerfile!${NC}" else # SUCCESS - echo -e "${NC}${F[B]}Successfully Uploaded Docker image:${F[W]}[${IMAGE_VERSION}]${F[B]} to ${F[C]}${REGISTRY}${F[B]}!${NC}" + notice "Successfully Uploaded Docker image:${F[W]}[${IMAGE_VERSION}]${F[B]} to ${F[C]}${REGISTRY}${F[B]}!${NC}" fi ######################### @@ -391,9 +376,8 @@ UploadImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get information about built Image!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GET_INFO_CMD}]${NC}" - exit 1 + error "Failed to get information about built Image!${NC}" + fatal "[${GET_INFO_CMD}]${NC}" else ################ # Get the data # @@ -434,11 +418,10 @@ UploadImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [upload] MAJOR_TAG:[${MAJOR_TAG}] Dockerfile!${NC}" - exit 1 + fatal "failed to [upload] MAJOR_TAG:[${MAJOR_TAG}] Dockerfile!${NC}" else # SUCCESS - echo -e "${NC}${F[B]}Successfully Uploaded TAG:${F[W]}[${MAJOR_TAG}]${F[B]} of Docker image to ${F[C]}${REGISTRY}${F[B]}!${NC}" + notice "Successfully Uploaded TAG:${F[W]}[${MAJOR_TAG}]${F[B]} of Docker image to ${F[C]}${REGISTRY}${F[B]}!${NC}" fi fi } @@ -488,9 +471,8 @@ else ######### # ERROR # ######### - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Registry not set correctly!${NC}" - echo "Registry:[${REGISTRY}]" - exit 1 + error "Registry not set correctly!${NC}" + fatal "Registry:[${REGISTRY}]" fi #################### diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 05cdf29f..75d18b4c 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -41,8 +41,7 @@ function BuildFileList() { if [ ${ERROR_CODE} -ne 0 ]; then # Error echo "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${SWITCH_CMD}]${NC}" - exit 1 + fatal "[${SWITCH_CMD}]${NC}" fi ################ @@ -69,9 +68,8 @@ function BuildFileList() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Error - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to gain a list of all files changed!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${RAW_FILE_ARRAY[*]}]${NC}" - exit 1 + error "Failed to gain a list of all files changed!${NC}" + fatal "[${RAW_FILE_ARRAY[*]}]${NC}" fi ################################################ @@ -472,7 +470,7 @@ function BuildFileList() { ####################### # It is a bash script # ####################### - echo -e "${NC}${F[Y]}WARN!${NC} Found bash script without extension:[.sh]${NC}" + warn "Found bash script without extension:[.sh]${NC}" echo "Please update file with proper extensions." ################################ # Append the file to the array # @@ -486,7 +484,7 @@ function BuildFileList() { ####################### # It is a Ruby script # ####################### - echo -e "${NC}${F[Y]}WARN!${NC} Found ruby script without extension:[.rb]${NC}" + warn "Found ruby script without extension:[.rb]${NC}" echo "Please update file with proper extensions." ################################ # Append the file to the array # @@ -500,7 +498,7 @@ function BuildFileList() { ############################ # Extension was not found! # ############################ - echo -e "${NC}${F[Y]} - WARN!${NC} Failed to get filetype for:[${FILE}]!${NC}" + warn "Failed to get filetype for:[${FILE}]!${NC}" ########################################################## # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## @@ -526,9 +524,8 @@ function BuildFileList() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Error - echo "Failed to switch back to branch!" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${SWITCH2_CMD}]${NC}" - exit 1 + error "Failed to switch back to branch!" + fatal "[${SWITCH2_CMD}]${NC}" fi ################ @@ -536,5 +533,5 @@ function BuildFileList() { ################ echo "" echo "----------------------------------------------" - echo -e "${NC}${F[B]}Successfully gathered list of files...${NC}" + notice "Successfully gathered list of files...${NC}" } diff --git a/lib/linter.sh b/lib/linter.sh index f613ec16..9811ef5a 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -386,12 +386,12 @@ GetLinterVersions() { # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then - echo -e "${NC}[${LINTER}]: ${F[Y]}WARN!${NC} Failed to get version info for:${NC}" + warn "[${LINTER}]: Failed to get version info for:${NC}" else ########################## # Print the version info # ########################## - echo -e "${NC}${F[B]}Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}${NC}" + notice "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}${NC}" fi done @@ -474,9 +474,8 @@ GetStandardRules() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to gain list of ENV vars to load!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GET_ENV_ARRAY[*]}]${NC}" - exit 1 + error "Failed to gain list of ENV vars to load!${NC}" + fatal "[${GET_ENV_ARRAY[*]}]${NC}" fi ########################## @@ -691,8 +690,7 @@ GetGitHubVars() { fi if [ ! -d "${GITHUB_WORKSPACE}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Provided volume is not a directory!${NC}" - exit 1 + fatal "Provided volume is not a directory!${NC}" fi echo "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]" @@ -711,33 +709,30 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_SHA}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_SHA]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_SHA}]${NC}" - exit 1 + error "Failed to get [GITHUB_SHA]!${NC}" + fatal "[${GITHUB_SHA}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]${NC}" + notice "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]${NC}" fi ############################ # Validate we have a value # ############################ if [ -z "${GITHUB_WORKSPACE}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_WORKSPACE]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_WORKSPACE}]${NC}" - exit 1 + error "Failed to get [GITHUB_WORKSPACE]!${NC}" + fatal "[${GITHUB_WORKSPACE}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}" + notice "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}" fi ############################ # Validate we have a value # ############################ if [ -z "${GITHUB_EVENT_PATH}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_EVENT_PATH]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_EVENT_PATH}]${NC}" - exit 1 + error "Failed to get [GITHUB_EVENT_PATH]!${NC}" + fatal "[${GITHUB_EVENT_PATH}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}${NC}" + notice "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}${NC}" fi ################################################## @@ -753,11 +748,10 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_ORG}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_ORG]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_ORG}]${NC}" - exit 1 + error "Failed to get [GITHUB_ORG]!${NC}" + fatal "[${GITHUB_ORG}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]${NC}" + notice "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]${NC}" fi ####################### @@ -769,11 +763,10 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_REPO}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_REPO]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_REPO}]${NC}" - exit 1 + error "Failed to get [GITHUB_REPO]!${NC}" + fatal "[${GITHUB_REPO}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]${NC}" + notice "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]${NC}" fi fi @@ -781,16 +774,16 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_TOKEN]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_TOKEN}]${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!${NC}" + error "Failed to get [GITHUB_TOKEN]!${NC}" + error "[${GITHUB_TOKEN}]${NC}" + error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!${NC}" ################################################################################ # Need to set MULTI_STATUS to false as we cant hit API endpoints without token # ################################################################################ MULTI_STATUS='false' else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_TOKEN]${NC}" + notice "Successfully found:${F[W]}[GITHUB_TOKEN]${NC}" fi ############################### @@ -806,22 +799,20 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_REPOSITORY}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_REPOSITORY]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_REPOSITORY}]${NC}" - exit 1 + error "Failed to get [GITHUB_REPOSITORY]!${NC}" + fatal "[${GITHUB_REPOSITORY}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]${NC}" + notice "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]${NC}" fi ############################ # Validate we have a value # ############################ if [ -z "${GITHUB_RUN_ID}" ]; then - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_RUN_ID]!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_RUN_ID}]${NC}" - exit 1 + error "Failed to get [GITHUB_RUN_ID]!${NC}" + fatal "[${GITHUB_RUN_ID}]${NC}" else - echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]${NC}" + notice "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]${NC}" fi fi } @@ -833,16 +824,14 @@ function ValidatePowershellModules() { if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]]; then VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1) else - # Failed to find module - exit 1 + fatal "Failed to find module." fi ######################################### # validate we found the script analyzer # ######################################### if [[ ${VALIDATE_PSSA_CMD} != "Invoke-ScriptAnalyzer" ]]; then - # Failed to find module - exit 1 + fatal "Failed to find module." fi ####################### @@ -855,14 +844,13 @@ function ValidatePowershellModules() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Failed - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]${NC}" - exit 1 + error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!${NC}" + fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]${NC}" else # Success if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - echo -e "${NC}${F[B]}Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system${NC}" - echo -e "${NC}${F[B]}Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system${NC}" + notice "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system${NC}" + notice "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system${NC}" fi fi } @@ -944,7 +932,7 @@ Reports() { # Prints for warnings if found # ################################ for TEST in "${WARNING_ARRAY_TEST[@]}"; do - echo -e "${NC}${F[Y]}WARN!${NC} Expected file to compare with was not found for ${TEST}${NC}" + warn "Expected file to compare with was not found for ${TEST}${NC}" done } @@ -981,7 +969,7 @@ Footer() { ################### # Print the goods # ################### - echo -e "${NC}${B[R]}${F[W]}ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]${NC}" + error "ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]${NC}" ######################################### # Create status API for Failed language # @@ -1000,7 +988,7 @@ Footer() { # Exit with 0 if errors disabled # ################################## if [ "${DISABLE_ERRORS}" == "true" ]; then - echo -e "${NC}${F[Y]}WARN!${NC} Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]${NC}" + warn "Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]${NC}" exit 0 fi @@ -1014,8 +1002,7 @@ Footer() { # Check if error was found if [ "${!ERRORS_FOUND_LANGUAGE}" -ne 0 ]; then # Failed exit - echo -e "${NC}${F[R]}Exiting with errors found!${NC}" - exit 1 + fatal "Exiting with errors found!${NC}" fi done @@ -1023,7 +1010,7 @@ Footer() { # Footer prints Exit 0 # ######################## echo "" - echo -e "${NC}${F[G]}All file(s) linted successfully with no errors detected${NC}" + notice "All file(s) linted successfully with no errors detected${NC}" echo "----------------------------------------------" echo "" # Successful exit @@ -1057,9 +1044,8 @@ Header ############################################################## if [ -n "${OUTPUT_FORMAT}" ]; then if [ -d "${REPORT_OUTPUT_FOLDER}" ] ; then - echo "ERROR! Found ${REPORT_OUTPUT_FOLDER}" - echo "Please remove the folder and try again." - exit 1 + error "ERROR! Found ${REPORT_OUTPUT_FOLDER}" + fatal "Please remove the folder and try again." fi fi diff --git a/lib/worker.sh b/lib/worker.sh index ab23e60f..94fd2add 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -49,13 +49,12 @@ function LintCodebase() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Failed - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find [${LINTER_NAME}] in system!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${VALIDATE_INSTALL_CMD}]${NC}" - exit 1 + error "Failed to find [${LINTER_NAME}] in system!${NC}" + fatal "[${VALIDATE_INSTALL_CMD}]${NC}" else # Success if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - echo -e "${NC}${F[B]}Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}" + notice "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}" fi fi @@ -226,9 +225,9 @@ function LintCodebase() { ######### # Error # ######### - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [${LINTER_NAME}] linter!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LINT_CMD}]${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}" + error "Found errors in [${LINTER_NAME}] linter!${NC}" + error "[${LINT_CMD}]${NC}" + error "Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}" # Increment the error count (("ERRORS_FOUND_${FILE_TYPE}++")) @@ -243,7 +242,7 @@ function LintCodebase() { ########### # Success # ########### - echo -e "${NC}${F[B]} - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" + notice " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" ####################################################### # Store the linting as a temporary file in TAP format # @@ -302,12 +301,11 @@ function TestCodebase() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Failed - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find [${LINTER_NAME}] in system!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${VALIDATE_INSTALL_CMD}]${NC}" - exit 1 + error "Failed to find [${LINTER_NAME}] in system!${NC}" + fatal "[${VALIDATE_INSTALL_CMD}]${NC}" else # Success - echo -e "${NC}${F[B]}Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}" + notice "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}" fi ########################## @@ -454,16 +452,16 @@ function TestCodebase() { ######### # Error # ######### - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [${LINTER_NAME}] linter!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LINT_CMD}]${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}" + error "Found errors in [${LINTER_NAME}] linter!${NC}" + error "[${LINT_CMD}]${NC}" + error "Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}" # Increment the error count (("ERRORS_FOUND_${FILE_TYPE}++")) else ########### # Success # ########### - echo -e "${NC}${F[B]} - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" + notice " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" fi ####################################################### # Store the linting as a temporary file in TAP format # @@ -482,18 +480,18 @@ function TestCodebase() { ######### # Error # ######### - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [${LINTER_NAME}] linter!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} This file should have failed test case!${NC}" - echo -e "${NC}${B[R]}${F[W]}Command run:${NC}[\$${LINT_CMD}]${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LINT_CMD}]${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}" + error "Found errors in [${LINTER_NAME}] linter!${NC}" + error "This file should have failed test case!${NC}" + error "Command run:${NC}[\$${LINT_CMD}]${NC}" + error "[${LINT_CMD}]${NC}" + error "Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}" # Increment the error count (("ERRORS_FOUND_${FILE_TYPE}++")) else ########### # Success # ########### - echo -e "${NC}${F[B]} - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" + notice " - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" fi ####################################################### # Store the linting as a temporary file in TAP format # @@ -523,16 +521,16 @@ function TestCodebase() { ############################################# # We failed to compare the reporting output # ############################################# - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to assert TAP output:[${LINTER_NAME}]${NC}"! + error "Failed to assert TAP output:[${LINTER_NAME}]${NC}"! echo "Please validate the asserts!" cat "${TMPFILE}" exit 1 else # Success - echo -e "${NC}${F[B]}Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]${NC}" + notice "Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]${NC}" fi else - echo -e "${NC}${F[Y]}WARN!${NC} No TAP expected file found at:[${EXPECTED_FILE}]${NC}" + warn "No TAP expected file found at:[${EXPECTED_FILE}]${NC}" echo "skipping report assertions" ##################################### # Append the file type to the array # @@ -548,9 +546,8 @@ function TestCodebase() { ################################################# # We failed to find files and no tests were ran # ################################################# - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find any tests ran for the Linter:[${LINTER_NAME}]${NC}"! - echo "Please validate logic or that tests exist!" - exit 1 + error "Failed to find any tests ran for the Linter:[${LINTER_NAME}]${NC}"! + fatal "Please validate logic or that tests exist!" fi } ################################################################################ @@ -658,14 +655,13 @@ function LintAnsibleFiles() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Failed - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find ${LINTER_NAME} in system!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${VALIDATE_INSTALL_CMD}]${NC}" - exit 1 + error "Failed to find ${LINTER_NAME} in system!${NC}" + fatal "[${VALIDATE_INSTALL_CMD}]${NC}" else # Success if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then # Success - echo -e "${NC}${F[B]}Successfully found binary in system${NC}" + notice "Successfully found binary in system${NC}" echo "Location:[${VALIDATE_INSTALL_CMD}]" fi fi @@ -777,8 +773,8 @@ function LintAnsibleFiles() { ######### # Error # ######### - echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [${LINTER_NAME}] linter!${NC}" - echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LINT_CMD}]${NC}" + error "Found errors in [${LINTER_NAME}] linter!${NC}" + error "[${LINT_CMD}]${NC}" # Increment error count ((ERRORS_FOUND_ANSIBLE++)) @@ -794,7 +790,7 @@ function LintAnsibleFiles() { ########### # Success # ########### - echo -e "${NC}${F[B]} - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" + notice " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" ####################################################### # Store the linting as a temporary file in TAP format # @@ -820,7 +816,7 @@ function LintAnsibleFiles() { ######################## # No Ansible dir found # ######################## - echo -e "${NC}${F[Y]}WARN!${NC} No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]${NC}" + warn "No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]${NC}" echo "skipping ansible lint" fi fi From 008a3057c9c68c5d2305840f25d5cac5bdd42377 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Mon, 27 Jul 2020 16:35:53 -0500 Subject: [PATCH 12/52] Remove trailing NC on log functions --- .automation/cleanup-docker.sh | 32 +++++----- .../templates/ghe-config-apply.sh | 12 ++-- .automation/upload-docker.sh | 58 +++++++++---------- lib/buildFileList.sh | 8 +-- lib/linter.sh | 48 +++++++-------- lib/worker.sh | 38 ++++++------ 6 files changed, 98 insertions(+), 98 deletions(-) diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index 7910f17b..028a8aa6 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -52,8 +52,8 @@ ValidateInput() { # Validate GITHUB_WORKSPACE # ############################ if [ -z "${GITHUB_WORKSPACE}" ]; then - error "Failed to get [GITHUB_WORKSPACE]!${NC}" - fatal "[${GITHUB_WORKSPACE}]${NC}" + error "Failed to get [GITHUB_WORKSPACE]!" + fatal "[${GITHUB_WORKSPACE}]" else echo "Successfully found:[GITHUB_WORKSPACE], value:[${GITHUB_WORKSPACE}]" fi @@ -63,8 +63,8 @@ ValidateInput() { ####################### if [ -z "${IMAGE_REPO}" ]; then # No repo was pulled - error "Failed to get [IMAGE_REPO]!${NC}" - fatal "[${IMAGE_REPO}]${NC}" + error "Failed to get [IMAGE_REPO]!" + fatal "[${IMAGE_REPO}]" elif [[ ${IMAGE_REPO} == "github/super-linter" ]]; then # Found our main repo echo "Successfully found:[IMAGE_REPO], value:[${IMAGE_REPO}]" @@ -78,8 +78,8 @@ ValidateInput() { # Validate IMAGE_VERSION # ########################## if [ -z "${IMAGE_VERSION}" ]; then - error "Failed to get [IMAGE_VERSION]!${NC}" - fatal "[${IMAGE_VERSION}]${NC}" + error "Failed to get [IMAGE_VERSION]!" + fatal "[${IMAGE_VERSION}]" else echo "Successfully found:[IMAGE_VERSION], value:[${IMAGE_VERSION}]" fi @@ -88,8 +88,8 @@ ValidateInput() { # Validate DOCKER_USERNAME # ############################ if [ -z "${DOCKER_USERNAME}" ]; then - error "Failed to get [DOCKER_USERNAME]!${NC}" - fatal "[${DOCKER_USERNAME}]${NC}" + error "Failed to get [DOCKER_USERNAME]!" + fatal "[${DOCKER_USERNAME}]" else echo "Successfully found:[DOCKER_USERNAME], value:[${DOCKER_USERNAME}]" fi @@ -98,8 +98,8 @@ ValidateInput() { # Validate DOCKER_PASSWORD # ############################ if [ -z "${DOCKER_PASSWORD}" ]; then - error "Failed to get [DOCKER_PASSWORD]!${NC}" - fatal "[${DOCKER_PASSWORD}]${NC}" + error "Failed to get [DOCKER_PASSWORD]!" + fatal "[${DOCKER_PASSWORD}]" else echo "Successfully found:[DOCKER_PASSWORD], value:[********]" fi @@ -148,8 +148,8 @@ LoginToDocker() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - error "Failed to authenticate to DockerHub!${NC}" - fatal "[${LOGIN_CMD}]${NC}" + error "Failed to authenticate to DockerHub!" + fatal "[${LOGIN_CMD}]" else # SUCCESS echo "Successfully authenticated to DockerHub!" @@ -186,8 +186,8 @@ RemoveImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - error "Failed to gain token from DockerHub!${NC}" - fatal "[${TOKEN}]${NC}" + error "Failed to gain token from DockerHub!" + fatal "[${TOKEN}]" else # SUCCESS echo "Successfully gained auth token from DockerHub!" @@ -210,8 +210,8 @@ RemoveImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - error "Failed to remove tag from DockerHub!${NC}" - fatal "[${REMOVE_CMD}]${NC}" + error "Failed to remove tag from DockerHub!" + fatal "[${REMOVE_CMD}]" else # SUCCESS echo "Successfully [removed] Docker image tag:[${IMAGE_VERSION}] from DockerHub!" diff --git a/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh b/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh index 227caabc..9258978b 100644 --- a/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh +++ b/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh @@ -53,8 +53,8 @@ CheckGHEPid() # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ]; then - error "Failed to sleep!${NC}" - error "[${SLEEP_CMD}]${NC}" + error "Failed to sleep!" + error "[${SLEEP_CMD}]" echo "Will try to call apply as last effort..." #################################### # Call config apply as last effort # @@ -117,8 +117,8 @@ CheckGHEProcess() # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ]; then - error "Failed to sleep!${NC}" - error "[${SLEEP_CMD}]${NC}" + error "Failed to sleep!" + error "[${SLEEP_CMD}]" echo "Will try to call apply as last effort..." #################################### # Call config apply as last effort # @@ -161,8 +161,8 @@ RunConfigApply() ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Errors - error "Failed to run config apply command!${NC}" - fatal "[${APPLY_CMD}]${NC}" + error "Failed to run config apply command!" + fatal "[${APPLY_CMD}]" else # Success notice "Successfully ran ${F[C]}${GHE_APPLY_COMMAND}${NC}" diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index d4fccdf8..bbb1bae7 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -58,8 +58,8 @@ ValidateInput() { # Validate GITHUB_WORKSPACE # ############################# if [ -z "${GITHUB_WORKSPACE}" ]; then - error "Failed to get [GITHUB_WORKSPACE]!${NC}" - fatal "[${GITHUB_WORKSPACE}]${NC}" + error "Failed to get [GITHUB_WORKSPACE]!" + fatal "[${GITHUB_WORKSPACE}]" else notice "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}" fi @@ -68,8 +68,8 @@ ValidateInput() { # Validate REGISTRY # ##################### if [ -z "${REGISTRY}" ]; then - error "Failed to get [REGISTRY]!${NC}" - fatal "[${REGISTRY}]${NC}" + error "Failed to get [REGISTRY]!" + fatal "[${REGISTRY}]" else notice "Successfully found:${F[W]}[REGISTRY]${F[B]}, value:${F[W]}[${REGISTRY}]${NC}" fi @@ -82,8 +82,8 @@ ValidateInput() { # Validate GPR_USERNAME # ######################### if [ -z "${GPR_USERNAME}" ]; then - error "Failed to get [GPR_USERNAME]!${NC}" - fatal "[${GPR_USERNAME}]${NC}" + error "Failed to get [GPR_USERNAME]!" + fatal "[${GPR_USERNAME}]" else notice "Successfully found:${F[W]}[GPR_USERNAME]${F[B]}, value:${F[W]}[${GPR_USERNAME}]${NC}" fi @@ -92,8 +92,8 @@ ValidateInput() { # Validate GPR_TOKEN # ###################### if [ -z "${GPR_TOKEN}" ]; then - error "Failed to get [GPR_TOKEN]!${NC}" - fatal "[${GPR_TOKEN}]${NC}" + error "Failed to get [GPR_TOKEN]!" + fatal "[${GPR_TOKEN}]" else notice "Successfully found:${F[W]}[GPR_TOKEN]${F[B]}, value:${F[W]}[********]${NC}" fi @@ -105,8 +105,8 @@ ValidateInput() { # Validate DOCKER_USERNAME # ############################ if [ -z "${DOCKER_USERNAME}" ]; then - error "Failed to get [DOCKER_USERNAME]!${NC}" - fatal "[${DOCKER_USERNAME}]${NC}" + error "Failed to get [DOCKER_USERNAME]!" + fatal "[${DOCKER_USERNAME}]" else notice "Successfully found:${F[W]}[DOCKER_USERNAME]${F[B]}, value:${F[W]}[${DOCKER_USERNAME}]${NC}" fi @@ -115,8 +115,8 @@ ValidateInput() { # Validate DOCKER_PASSWORD # ############################ if [ -z "${DOCKER_PASSWORD}" ]; then - error "Failed to get [DOCKER_PASSWORD]!${NC}" - fatal "[${DOCKER_PASSWORD}]${NC}" + error "Failed to get [DOCKER_PASSWORD]!" + fatal "[${DOCKER_PASSWORD}]" else notice "Successfully found:${F[W]}[DOCKER_PASSWORD]${F[B]}, value:${F[B]}[********]${NC}" fi @@ -124,7 +124,7 @@ ValidateInput() { # We were not passed a registry to update # ########################################### else - error "Failed to find a valid registry!${NC}" + error "Failed to find a valid registry!" fatal "Registry:[${REGISTRY}]" fi @@ -132,8 +132,8 @@ ValidateInput() { # Validate IMAGE_REPO # ####################### if [ -z "${IMAGE_REPO}" ]; then - error "Failed to get [IMAGE_REPO]!${NC}" - fatal "[${IMAGE_REPO}]${NC}" + error "Failed to get [IMAGE_REPO]!" + fatal "[${IMAGE_REPO}]" else notice "Successfully found:${F[W]}[IMAGE_REPO]${F[B]}, value:${F[W]}[${IMAGE_REPO}]${NC}" ############################################### @@ -166,8 +166,8 @@ ValidateInput() { # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ]; then - error "Failed to get branch name!${NC}" - fatal "[${BRANCH_NAME}]${NC}" + error "Failed to get branch name!" + fatal "[${BRANCH_NAME}]" fi ################################## @@ -212,8 +212,8 @@ ValidateInput() { # Validate DOCKERFILE_PATH # ############################ if [ -z "${DOCKERFILE_PATH}" ]; then - error "Failed to get [DOCKERFILE_PATH]!${NC}" - fatal "[${DOCKERFILE_PATH}]${NC}" + error "Failed to get [DOCKERFILE_PATH]!" + fatal "[${DOCKERFILE_PATH}]" else notice "Successfully found:${F[W]}[DOCKERFILE_PATH]${F[B]}, value:${F[W]}[${DOCKERFILE_PATH}]${NC}" fi @@ -253,8 +253,8 @@ Authenticate() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - error "Failed to authenticate to ${NAME}!${NC}" - fatal "[${LOGIN_CMD}]${NC}" + error "Failed to authenticate to ${NAME}!" + fatal "[${LOGIN_CMD}]" fatal else # SUCCESS notice "Successfully authenticated to ${F[C]}${NAME}${F[B]}!${NC}" @@ -277,7 +277,7 @@ BuildImage() { ################################ if [ ! -f "${DOCKERFILE_PATH}" ]; then # No file found - error "failed to find Dockerfile at:[${DOCKERFILE_PATH}]${NC}" + error "failed to find Dockerfile at:[${DOCKERFILE_PATH}]" error "Please make sure you give full path!" fatal "Example:[/configs/Dockerfile] or [Dockerfile] if at root directory" fi @@ -297,7 +297,7 @@ BuildImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - fatal "failed to [build] Dockerfile!${NC}" + fatal "failed to [build] Dockerfile!" else # SUCCESS notice "Successfully Built image!${NC}" @@ -320,7 +320,7 @@ BuildImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - fatal "failed to [tag] Dockerfile!${NC}" + fatal "failed to [tag] Dockerfile!" else # SUCCESS notice "Successfully tagged image!${NC}" @@ -354,7 +354,7 @@ UploadImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - fatal "failed to [upload] Dockerfile!${NC}" + fatal "failed to [upload] Dockerfile!" else # SUCCESS notice "Successfully Uploaded Docker image:${F[W]}[${IMAGE_VERSION}]${F[B]} to ${F[C]}${REGISTRY}${F[B]}!${NC}" @@ -376,8 +376,8 @@ UploadImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - error "Failed to get information about built Image!${NC}" - fatal "[${GET_INFO_CMD}]${NC}" + error "Failed to get information about built Image!" + fatal "[${GET_INFO_CMD}]" else ################ # Get the data # @@ -418,7 +418,7 @@ UploadImage() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - fatal "failed to [upload] MAJOR_TAG:[${MAJOR_TAG}] Dockerfile!${NC}" + fatal "failed to [upload] MAJOR_TAG:[${MAJOR_TAG}] Dockerfile!" else # SUCCESS notice "Successfully Uploaded TAG:${F[W]}[${MAJOR_TAG}]${F[B]} of Docker image to ${F[C]}${REGISTRY}${F[B]}!${NC}" @@ -471,7 +471,7 @@ else ######### # ERROR # ######### - error "Registry not set correctly!${NC}" + error "Registry not set correctly!" fatal "Registry:[${REGISTRY}]" fi diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 75d18b4c..71851b2e 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -41,7 +41,7 @@ function BuildFileList() { if [ ${ERROR_CODE} -ne 0 ]; then # Error echo "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!" - fatal "[${SWITCH_CMD}]${NC}" + fatal "[${SWITCH_CMD}]" fi ################ @@ -68,8 +68,8 @@ function BuildFileList() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Error - error "Failed to gain a list of all files changed!${NC}" - fatal "[${RAW_FILE_ARRAY[*]}]${NC}" + error "Failed to gain a list of all files changed!" + fatal "[${RAW_FILE_ARRAY[*]}]" fi ################################################ @@ -525,7 +525,7 @@ function BuildFileList() { if [ ${ERROR_CODE} -ne 0 ]; then # Error error "Failed to switch back to branch!" - fatal "[${SWITCH2_CMD}]${NC}" + fatal "[${SWITCH2_CMD}]" fi ################ diff --git a/lib/linter.sh b/lib/linter.sh index 9811ef5a..7bb5ec81 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -474,8 +474,8 @@ GetStandardRules() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # ERROR - error "Failed to gain list of ENV vars to load!${NC}" - fatal "[${GET_ENV_ARRAY[*]}]${NC}" + error "Failed to gain list of ENV vars to load!" + fatal "[${GET_ENV_ARRAY[*]}]" fi ########################## @@ -690,7 +690,7 @@ GetGitHubVars() { fi if [ ! -d "${GITHUB_WORKSPACE}" ]; then - fatal "Provided volume is not a directory!${NC}" + fatal "Provided volume is not a directory!" fi echo "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]" @@ -709,8 +709,8 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_SHA}" ]; then - error "Failed to get [GITHUB_SHA]!${NC}" - fatal "[${GITHUB_SHA}]${NC}" + error "Failed to get [GITHUB_SHA]!" + fatal "[${GITHUB_SHA}]" else notice "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]${NC}" fi @@ -719,8 +719,8 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_WORKSPACE}" ]; then - error "Failed to get [GITHUB_WORKSPACE]!${NC}" - fatal "[${GITHUB_WORKSPACE}]${NC}" + error "Failed to get [GITHUB_WORKSPACE]!" + fatal "[${GITHUB_WORKSPACE}]" else notice "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}" fi @@ -729,8 +729,8 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_EVENT_PATH}" ]; then - error "Failed to get [GITHUB_EVENT_PATH]!${NC}" - fatal "[${GITHUB_EVENT_PATH}]${NC}" + error "Failed to get [GITHUB_EVENT_PATH]!" + fatal "[${GITHUB_EVENT_PATH}]" else notice "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}${NC}" fi @@ -748,8 +748,8 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_ORG}" ]; then - error "Failed to get [GITHUB_ORG]!${NC}" - fatal "[${GITHUB_ORG}]${NC}" + error "Failed to get [GITHUB_ORG]!" + fatal "[${GITHUB_ORG}]" else notice "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]${NC}" fi @@ -763,8 +763,8 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_REPO}" ]; then - error "Failed to get [GITHUB_REPO]!${NC}" - fatal "[${GITHUB_REPO}]${NC}" + error "Failed to get [GITHUB_REPO]!" + fatal "[${GITHUB_REPO}]" else notice "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]${NC}" fi @@ -774,9 +774,9 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then - error "Failed to get [GITHUB_TOKEN]!${NC}" - error "[${GITHUB_TOKEN}]${NC}" - error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!${NC}" + error "Failed to get [GITHUB_TOKEN]!" + error "[${GITHUB_TOKEN}]" + error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!" ################################################################################ # Need to set MULTI_STATUS to false as we cant hit API endpoints without token # @@ -799,8 +799,8 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_REPOSITORY}" ]; then - error "Failed to get [GITHUB_REPOSITORY]!${NC}" - fatal "[${GITHUB_REPOSITORY}]${NC}" + error "Failed to get [GITHUB_REPOSITORY]!" + fatal "[${GITHUB_REPOSITORY}]" else notice "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]${NC}" fi @@ -809,8 +809,8 @@ GetGitHubVars() { # Validate we have a value # ############################ if [ -z "${GITHUB_RUN_ID}" ]; then - error "Failed to get [GITHUB_RUN_ID]!${NC}" - fatal "[${GITHUB_RUN_ID}]${NC}" + error "Failed to get [GITHUB_RUN_ID]!" + fatal "[${GITHUB_RUN_ID}]" else notice "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]${NC}" fi @@ -844,8 +844,8 @@ function ValidatePowershellModules() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Failed - error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!${NC}" - fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]${NC}" + error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!" + fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]" else # Success if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then @@ -969,7 +969,7 @@ Footer() { ################### # Print the goods # ################### - error "ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]${NC}" + error "ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]" ######################################### # Create status API for Failed language # @@ -1002,7 +1002,7 @@ Footer() { # Check if error was found if [ "${!ERRORS_FOUND_LANGUAGE}" -ne 0 ]; then # Failed exit - fatal "Exiting with errors found!${NC}" + fatal "Exiting with errors found!" fi done diff --git a/lib/worker.sh b/lib/worker.sh index 94fd2add..6d79ffc8 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -49,8 +49,8 @@ function LintCodebase() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Failed - error "Failed to find [${LINTER_NAME}] in system!${NC}" - fatal "[${VALIDATE_INSTALL_CMD}]${NC}" + error "Failed to find [${LINTER_NAME}] in system!" + fatal "[${VALIDATE_INSTALL_CMD}]" else # Success if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then @@ -225,9 +225,9 @@ function LintCodebase() { ######### # Error # ######### - error "Found errors in [${LINTER_NAME}] linter!${NC}" - error "[${LINT_CMD}]${NC}" - error "Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}" + error "Found errors in [${LINTER_NAME}] linter!" + error "[${LINT_CMD}]" + error "Linter CMD:[${LINTER_COMMAND} ${FILE}]" # Increment the error count (("ERRORS_FOUND_${FILE_TYPE}++")) @@ -301,8 +301,8 @@ function TestCodebase() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Failed - error "Failed to find [${LINTER_NAME}] in system!${NC}" - fatal "[${VALIDATE_INSTALL_CMD}]${NC}" + error "Failed to find [${LINTER_NAME}] in system!" + fatal "[${VALIDATE_INSTALL_CMD}]" else # Success notice "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}" @@ -452,9 +452,9 @@ function TestCodebase() { ######### # Error # ######### - error "Found errors in [${LINTER_NAME}] linter!${NC}" - error "[${LINT_CMD}]${NC}" - error "Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}" + error "Found errors in [${LINTER_NAME}] linter!" + error "[${LINT_CMD}]" + error "Linter CMD:[${LINTER_COMMAND} ${FILE}]" # Increment the error count (("ERRORS_FOUND_${FILE_TYPE}++")) else @@ -480,11 +480,11 @@ function TestCodebase() { ######### # Error # ######### - error "Found errors in [${LINTER_NAME}] linter!${NC}" - error "This file should have failed test case!${NC}" - error "Command run:${NC}[\$${LINT_CMD}]${NC}" - error "[${LINT_CMD}]${NC}" - error "Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}" + error "Found errors in [${LINTER_NAME}] linter!" + error "This file should have failed test case!" + error "Command run:${NC}[\$${LINT_CMD}]" + error "[${LINT_CMD}]" + error "Linter CMD:[${LINTER_COMMAND} ${FILE}]" # Increment the error count (("ERRORS_FOUND_${FILE_TYPE}++")) else @@ -655,8 +655,8 @@ function LintAnsibleFiles() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Failed - error "Failed to find ${LINTER_NAME} in system!${NC}" - fatal "[${VALIDATE_INSTALL_CMD}]${NC}" + error "Failed to find ${LINTER_NAME} in system!" + fatal "[${VALIDATE_INSTALL_CMD}]" else # Success if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then @@ -773,8 +773,8 @@ function LintAnsibleFiles() { ######### # Error # ######### - error "Found errors in [${LINTER_NAME}] linter!${NC}" - error "[${LINT_CMD}]${NC}" + error "Found errors in [${LINTER_NAME}] linter!" + error "[${LINT_CMD}]" # Increment error count ((ERRORS_FOUND_ANSIBLE++)) From 4362d5cd9f352b1049bebc182c55a8a5008ba63c Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 21 Jul 2020 19:55:39 -0500 Subject: [PATCH 13/52] Add python vars and sort alphabetically --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 2aa7dec9..a3f331d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -247,6 +247,8 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ VALIDATE_POWERSHELL=${VALIDATE_POWERSHELL} \ VALIDATE_PROTOBUF=${VALIDATE_PROTOBUF} \ VALIDATE_PYTHON=${VALIDATE_PYTHON} \ + VALIDATE_PYTHON_PYLINT=${VALIDATE_PYTHON_PYLINT} \ + VALIDATE_PYTHON_FLAKE8=${VALIDATE_PYTHON_FLAKE8} \ VALIDATE_RAKU=${VALIDATE_RAKU} \ VALIDATE_RUBY=${VALIDATE_RUBY} \ VALIDATE_STATES=${VALIDATE_STATES} \ @@ -257,6 +259,7 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ VALIDATE_XML=${VALIDATE_XML} \ VALIDATE_YAML=${VALIDATE_YAML} + ############################# # Copy scripts to container # ############################# From 0ca744a9c70568603a44a2939cf2f0fd3d301cf6 Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 21 Jul 2020 19:55:56 -0500 Subject: [PATCH 14/52] Add flake8 dependency --- dependencies/Pipfile | 1 + dependencies/Pipfile.lock | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/dependencies/Pipfile b/dependencies/Pipfile index dbc906c9..0fcce921 100644 --- a/dependencies/Pipfile +++ b/dependencies/Pipfile @@ -11,6 +11,7 @@ pylint = "*" yq = "*" cfn-lint = "*" terrascan = "*" +flake8 = "*" [requires] python_version = "3.8" diff --git a/dependencies/Pipfile.lock b/dependencies/Pipfile.lock index 32180e96..962c1041 100644 --- a/dependencies/Pipfile.lock +++ b/dependencies/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "c62b95247cb67b10711da0012966cc031d5a9ec08885a45736c0ee77bba3a844" + "sha256": "f8ea3853c4bb4533103043533d08982436551678c827f59809c94bf0ee54a187" }, "pipfile-spec": 6, "requires": { @@ -28,6 +28,7 @@ "sha256:2f4078c2a41bf377eea06d71c9d2ba4eb8f6b1af2135bec27bbbb7d8f12bb703", "sha256:bc58d83eb610252fd8de6363e39d4f1d0619c894b0ed24603b881c02e64c7386" ], + "markers": "python_version >= '3.5'", "version": "==2.4.2" }, "attrs": { @@ -35,6 +36,7 @@ "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c", "sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==19.3.0" }, "aws-sam-translator": { @@ -80,13 +82,23 @@ "sha256:9e4d7ecfc600058e07ba661411a2b7de2fd0fafa17d1a7f7361cd47b1175c827", "sha256:a2aeea129088da402665e92e0b25b04b073c04b2dce4ab65caaa38b7ce2e1a99" ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'", "version": "==0.15.2" }, + "flake8": { + "hashes": [ + "sha256:15e351d19611c887e482fb960eae4d44845013cc142d42896e9862f775d8cf5c", + "sha256:f04b9fcbac03b0a3e58c0ab3a0ecc462e023a9faf046d57794184028123aa208" + ], + "index": "pypi", + "version": "==3.8.3" + }, "isort": { "hashes": [ "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1", "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==4.3.21" }, "jmespath": { @@ -94,6 +106,7 @@ "sha256:b85d0567b8666149a93172712e68920734333c0ce7e89b78b3e987f71e5ed4f9", "sha256:cdf6525904cc597730141d61b36f2e4b8ecc257c420fa2f4549bac2c2d0cb72f" ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'", "version": "==0.10.0" }, "jsonpatch": { @@ -109,6 +122,7 @@ "sha256:c192ba86648e05fdae4f08a17ec25180a9aef5008d973407b581798a83975362", "sha256:ff379fa021d1b81ab539f5ec467c7745beb1a5671463f9dcc2b2d458bd361c1e" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.0" }, "jsonschema": { @@ -148,6 +162,7 @@ "sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4", "sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.4.3" }, "mccabe": { @@ -172,6 +187,22 @@ ], "version": "==0.8.0" }, + "pycodestyle": { + "hashes": [ + "sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367", + "sha256:c58a7d2815e0e8d7972bf1803331fb0152f867bd89adf8a01dfd55085434192e" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.6.0" + }, + "pyflakes": { + "hashes": [ + "sha256:0d94e0e05a19e57a99444b6ddcf9a6eb2e5c68d3ca1e98e90707af8152c90a92", + "sha256:35b2d75ee967ea93b55750aa9edbbf72813e06a66ba54438df2cfac9e3c27fc8" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.2.0" + }, "pyhcl": { "hashes": [ "sha256:2d9b9dcdf1023d812bfed561ba72c99104c5b3f52e558d595130a44ce081b003" @@ -197,6 +228,7 @@ "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c", "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", "version": "==2.8.1" }, "pyyaml": { @@ -228,6 +260,7 @@ "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", "version": "==1.15.0" }, "terrascan": { From 794c61483616d73766a3bd5528d8d666d10a9d6f Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 21 Jul 2020 19:57:21 -0500 Subject: [PATCH 15/52] Add python vars --- lib/buildFileList.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 05cdf29f..7e1ad63e 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -263,7 +263,8 @@ function BuildFileList() { ################################ # Append the file to the array # ################################ - FILE_ARRAY_PYTHON+=("${FILE}") + FILE_ARRAY_PYTHON_PYLINT+=("${FILE}") + FILE_ARRAY_PYTHON_FLAKE8+=("${FILE}") ########################################################## # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## From 1fce9458ce6f78f201f12d42f92e4be95c6fef7f Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 21 Jul 2020 19:58:23 -0500 Subject: [PATCH 16/52] Sort alphabetically and configs for python flake8 --- lib/linter.sh | 55 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 5ccbafaf..4a10072b 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -78,8 +78,10 @@ POWERSHELL_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${POWERSHELL_FILE_NAME}" PROTOBUF_FILE_NAME='.protolintrc.yml' # Name of the file PROTOBUF_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PROTOBUF_FILE_NAME}" # Path to the Protocol Buffers lint rules # Python Vars -PYTHON_FILE_NAME='.python-lint' # Name of the file -PYTHON_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_FILE_NAME}" # Path to the python lint rules +PYTHON_PYLINT_FILE_NAME="${PYTHON_PYLINT_CONFIG_FILE:-.python-lint}" # Name of the file +PYTHON_PYLINT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_PYLINT_FILE_NAME}" # Path to the python lint rules +PYTHON_FLAKE8_FILE_NAME="${PYTHON_FLAKE8_CONFIG_FILE:-.flake8}" # Name of the file +PYTHON_FLAKE8_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_FLAKE8_FILE_NAME}" # Path to the python lint rules # Ruby Vars RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}" # Name of the file RUBY_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${RUBY_FILE_NAME}" # Path to the ruby lint rules @@ -97,22 +99,20 @@ YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" ####################################### # Linter array for information prints # ####################################### -LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo' - 'coffeelint' 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'golangci-lint' - 'htmlhint' 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' - 'protolint' 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' - 'standard' 'stylelint' 'terrascan' 'tflint' 'xmllint' 'yamllint') - +LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo' 'coffeelint' + 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'flake8' 'golangci-lint' 'htmlhint' + 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' + 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'terrascan' + 'tflint' 'xmllint' 'yamllint') ############################# # Language array for prints # ############################# -LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' - 'CSS' 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' - 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' - 'PERL' 'PHP' 'POWERSHELL' 'PROTOBUF' 'PYTHON' - 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' - 'TYPESCRIPT_STANDARD' 'XML' 'YAML') +LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' + 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' + 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP' 'POWERSHELL' + 'PROTOBUF' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' + 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YML') ############################################ # Array for all languages that were linted # @@ -160,7 +160,8 @@ VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to vali VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language VALIDATE_PHP="${VALIDATE_PHP}" # Boolean to validate language VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language -VALIDATE_PYTHON="${VALIDATE_PYTHON}" # Boolean to validate language +VALIDATE_PYTHON_PYLINT="${VALIDATE_PYTHON:-}" # Boolean to validate language +VALIDATE_PYTHON_FLAKE8="${VALIDATE_PYTHON_FLAKE8}" # Boolean to validate language VALIDATE_RAKU="${VALIDATE_RAKU}" # Boolean to validate language VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language VALIDATE_STATES="${VALIDATE_STATES}" # Boolean to validate language @@ -238,7 +239,8 @@ FILE_ARRAY_PERL=() # Array of files to check FILE_ARRAY_PHP=() # Array of files to check FILE_ARRAY_POWERSHELL=() # Array of files to check FILE_ARRAY_PROTOBUF=() # Array of files to check -FILE_ARRAY_PYTHON=() # Array of files to check +FILE_ARRAY_PYTHON_PYLINT=() # Array of files to check +FILE_ARRAY_PYTHON_FLAKE8=() # Array of files to check FILE_ARRAY_RAKU=() # Array of files to check FILE_ARRAY_RUBY=() # Array of files to check FILE_ARRAY_STATES=() # Array of files to check @@ -302,8 +304,10 @@ ERRORS_FOUND_POWERSHELL=0 # Count of errors found export ERRORS_FOUND_POWERSHELL # Workaround SC2034 ERRORS_FOUND_PROTOBUF=0 # Count of errors found export ERRORS_FOUND_PROTOBUF # Workaround SC2034 -ERRORS_FOUND_PYTHON=0 # Count of errors found -export ERRORS_FOUND_PYTHON # Workaround SC2034 +ERRORS_FOUND_PYTHON_PYLINT=0 # Count of errors found +export ERRORS_FOUND_PYTHON_PYLINT # Workaround SC2034 +ERRORS_FOUND_PYTHON_FLAKE8=0 # Count of errors found +export ERRORS_FOUND_PYTHON_FLAKE8 # Workaround SC2034 ERRORS_FOUND_RAKU=0 # Count of errors found export ERRORS_FOUND_RAKU # Workaround SC2034 ERRORS_FOUND_RUBY=0 # Count of errors found @@ -1511,12 +1515,23 @@ fi ################## # PYTHON LINTING # ################## -if [ "${VALIDATE_PYTHON}" == "true" ]; then +if [ "${VALIDATE_PYTHON_PYLINT}" == "true" ]; then ######################### # Lint the python files # ######################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PYTHON" "pylint" "pylint --rcfile ${PYTHON_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON[@]}" + LintCodebase "PYTHON" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_PYLINT[@]}" +fi + +################## +# PYTHON LINTING # +################## +if [ "${VALIDATE_PYTHON_FLAKE8}" == "true" ]; then + ######################### + # Lint the python files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PYTHON" "flake8" "flake8 --config=${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_FLAKE8[@]}" fi ################ From f372e4668b7a661eff017d44c62c26faa83176f5 Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 21 Jul 2020 19:59:05 -0500 Subject: [PATCH 17/52] Add python flake8 worker --- lib/worker.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/worker.sh b/lib/worker.sh index ab23e60f..7a9ddc59 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -602,7 +602,8 @@ function RunTestCases() { TestCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi" TestCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "powershell" TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "protobuf" - TestCodebase "PYTHON" "pylint" "pylint --rcfile ${PYTHON_LINTER_RULES}" ".*\.\(py\)\$" "python" + TestCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "python" + TestCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config ${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "python" TestCodebase "RAKU" "raku" "raku -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "raku" TestCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES}" ".*\.\(rb\)\$" "ruby" TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states" From 6c2e32ce14c7334f48637dfe46745d534bd7f99e Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 21 Jul 2020 19:54:30 -0500 Subject: [PATCH 18/52] Fix python test for flake8 --- .automation/test/python/python_good_1.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.automation/test/python/python_good_1.py b/.automation/test/python/python_good_1.py index e894c36f..a2f7c3e6 100644 --- a/.automation/test/python/python_good_1.py +++ b/.automation/test/python/python_good_1.py @@ -3,9 +3,9 @@ from os import getenv, path from pprint import pprint import sys -import click # pylint: disable=import-error -from dotenv import load_dotenv # pylint: disable=import-error -import requests # pylint: disable=import-error +import click # pylint: disable=import-error +from dotenv import load_dotenv # pylint: disable=import-error +import requests # pylint: disable=import-error env = load_dotenv() api_url = getenv('API_URL', default='https://api.github.com/graphql') @@ -13,8 +13,8 @@ github_token = getenv("GITHUB_TOKEN", default=None) if github_token is None: sys.exit("GitHub Token is not set." + - "Please set the GITHUB_TOKEN env variable in your system or " + - "the .env file of your project.") + "Please set the GITHUB_TOKEN env variable in your system or " + + "the .env file of your project.") client_id = getenv('CLIENT_ID', default='copy_labels.py') headers = { @@ -23,6 +23,7 @@ headers = { 'Content-Type': 'application/json' } + def create_label(repo_id, label): """ Create label in the supplied repo. @@ -52,6 +53,7 @@ def create_label(repo_id, label): return response + def get_labels(owner, repo): """ Gets a list of labels from the supplied repo. @@ -62,7 +64,7 @@ def get_labels(owner, repo): :return: A tuple with the GitHub id for the repository and a list of labels defined in the repository """ - query_variables = { "owner": owner, "name": repo, } + query_variables = {"owner": owner, "name": repo, } with open(path.join(path.dirname(__file__), 'queries/get_repo_data.gql'), 'r') as query_file: query = "".join(query_file.readlines()) @@ -83,6 +85,7 @@ def get_labels(owner, repo): '[ERROR] getting issue labels. Status Code: {status_code} - Message: {result}'.format( status_code=status_code, result=result["message"])) + def delete_label(label_id): """ Delete the specified label @@ -106,6 +109,7 @@ def delete_label(label_id): return result + @click.command() @click.option('--dry', is_flag=True) @click.argument('source_repo') @@ -149,7 +153,8 @@ def copy_labels(source_repo, target_repo, dry): print('Done') + if __name__ == "__main__": # Pylint doesn't know that @click.command takes care of injecting the # function parameters. Disabling Pylint error. - copy_labels() # pylint: disable=no-value-for-parameter + copy_labels() # pylint: disable=no-value-for-parameter From 3f5c87705974efa02f04c94960e4bf3db0fe00f4 Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 21 Jul 2020 21:47:48 -0500 Subject: [PATCH 19/52] Add flake template --- TEMPLATES/.flake8 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 TEMPLATES/.flake8 diff --git a/TEMPLATES/.flake8 b/TEMPLATES/.flake8 new file mode 100644 index 00000000..79a16af7 --- /dev/null +++ b/TEMPLATES/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 120 \ No newline at end of file From 925f12a67866ae4a99d1352df7e29a24d3a7e244 Mon Sep 17 00:00:00 2001 From: Gabo Date: Wed, 22 Jul 2020 13:24:37 -0500 Subject: [PATCH 20/52] Add line at EOF --- TEMPLATES/.flake8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TEMPLATES/.flake8 b/TEMPLATES/.flake8 index 79a16af7..6deafc26 100644 --- a/TEMPLATES/.flake8 +++ b/TEMPLATES/.flake8 @@ -1,2 +1,2 @@ [flake8] -max-line-length = 120 \ No newline at end of file +max-line-length = 120 From 675b42880e2c4d6cbb8f00db7218ccbd59b43b45 Mon Sep 17 00:00:00 2001 From: Gabo Date: Wed, 22 Jul 2020 13:30:40 -0500 Subject: [PATCH 21/52] Add glake8 to .github/linters --- .github/linters/.flake8 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/linters/.flake8 diff --git a/.github/linters/.flake8 b/.github/linters/.flake8 new file mode 100644 index 00000000..6deafc26 --- /dev/null +++ b/.github/linters/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 120 From 107bd8eea4a6dd54ebef14af563f1a3a7dd20b9c Mon Sep 17 00:00:00 2001 From: Gabo Date: Wed, 22 Jul 2020 14:04:55 -0500 Subject: [PATCH 22/52] Update docs --- README.md | 5 +- docs/disabling-linters.md | 1778 +++++++++++++++++++------------------ 2 files changed, 910 insertions(+), 873 deletions(-) diff --git a/README.md b/README.md index 4c09d542..d90ac812 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **PHP** | [PHP](https://www.php.net/) | | **PowerShell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) | | **Protocol Buffers** | [protolint](https://github.com/yoheimuta/protolint) | -| **Python3** | [pylint](https://www.pylint.org/) | +| **Python3** | [pylint](https://www.pylint.org/) [flake8](https://flake8.pycqa.org/en/latest/) | | **Raku** | [raku](https://raku.org) | | **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) | | **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) | @@ -208,7 +208,8 @@ and won't run anything unexpected. | **VALIDATE_PERL** | `true` | Flag to enable or disable the linting process of the Perl language. | | **VALIDATE_PHP** | `true` | Flag to enable or disable the linting process of the PHP language. | | **VALIDATE_PROTOBUF** | `true` | Flag to enable or disable the linting process of the Protobuf language. | -| **VALIDATE_PYTHON** | `true` | Flag to enable or disable the linting process of the Python language. | +| **VALIDATE_PYTHON_PYLINT** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: pylint) | +| **VALIDATE_PYTHON_FLAKE8** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: flake8) | | **VALIDATE_POWERSHELL** | `true` | Flag to enable or disable the linting process of the Powershell language. | | **VALIDATE_RAKU** | `true` | Flag to enable or disable the linting process of the Raku language. | | **VALIDATE_RUBY** | `true` | Flag to enable or disable the linting process of the Ruby language. | diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index fbdb578e..599bf126 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -14,40 +14,862 @@ For some linters it is also possible to override rules on a case by case level w ## Table of Linters -- [Ruby](#ruby) -- [Shell](#shell) -- [Ansible](#ansible) -- [YAML](#yaml) -- [AWS CloudFormation templates](#aws-cloud-formation) -- [Python](#python3) -- [JSON](#json) -- [Markdown](#markdown) -- [Perl](#perl) -- [Raku](#raku) -- [PHP](#php) -- [XML](#xml) -- [Coffeescript](#coffeescript) -- [Javascript Eslint](#javascript-eslint) -- [Javascript Standard](#javascript-standard) -- [Typescript Eslint](#typescript-eslint) -- [Typescript Standard](#typescript-standard) -- [Golang](#golang) -- [Groovy](#groovy) -- [Dockerfile](#dockerfile) -- [Terraform](#terraform) -- [CSS](#css) -- [DART](#dart) -- [ENV](#dotenv-linter) -- [Kotlin](#kotlin) -- [OpenAPI](#openapi) -- [Protocol Buffers](#protocol-buffers) -- [Clojure](#clojure) -- [EDITORCONFIG-CHECKER](#editorconfig-checker) -- [HTML](#html) -- [LUA](#lua) +- [Disabling linters and Rules](#disabling-linters-and-rules) + - [Table of Linters](#table-of-linters) + - [Ansible](#ansible) + - [AWS CloudFormation templates](#aws-cloudformation-templates) + - [Clojure](#clojure) + - [Coffeescript](#coffeescript) + - [CSS](#css) + - [Dart](#dart) + - [Dockerfile](#dockerfile) + - [EDITORCONFIG-CHECKER](#editorconfig-checker) + - [ENV](#env) + - [Golang](#golang) + - [Groovy](#groovy) + - [HTML](#html) + - [Javascript eslint](#javascript-eslint) + - [Javascript standard](#javascript-standard) + - [JSON](#json) + - [Kotlin](#kotlin) + - [Lua](#lua) + - [Markdown](#markdown) + - [OpenAPI](#openapi) + - [Perl](#perl) + - [PHP](#php) + - [Protocol Buffers](#protocol-buffers) + - [Python3 pylint](#python3-pylint) + - [Python3 flake8](#python3-flake8) + - [Raku](#raku) + - [Ruby](#ruby) + - [Shell](#shell) + - [Terraform](#terraform) + - [Typescript eslint](#typescript-eslint) + - [Typescript standard](#typescript-standard) + - [XML](#xml) + - [YAML](#yaml) +--- + +## Ansible + +- [ansible-lint](https://github.com/ansible/ansible-lint) + +### Ansible-lint Config file + +- `.github/linters/.ansible-lint.yml` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.ansible-lint.yml` + +### Ansible-lint disable single line + +```yml +- name: this would typically fire GitHasVersionRule 401 and BecomeUserWithoutBecomeRule 501 + become_user: alice # noqa 401 501 + git: src=/path/to/git/repo dest=checkout +``` + +### Ansible-lint disable code block + +```yml +- name: this would typically fire GitHasVersionRule 401 + git: src=/path/to/git/repo dest=checkout + tags: + - skip_ansible_lint +``` + +### Ansible-lint disable entire file + +```yml +- name: this would typically fire GitHasVersionRule 401 + git: src=/path/to/git/repo dest=checkout + tags: + - skip_ansible_lint +``` + +--- + +## AWS CloudFormation templates + +- [cfn-lint](https://github.com/aws-cloudformation/cfn-python-lint/) + +### cfn-lint Config file + +- `.github/linters/.cfnlintrc.yml` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.cfnlintrc.yml` + +### cfn-lint disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### cfn-lint disable code block + +You can disable both [template](https://github.com/aws-cloudformation/cfn-python-lint/#template-based-metadata) or [resource](https://github.com/aws-cloudformation/cfn-python-lint/#resource-based-metadata) via [metadata](https://github.com/aws-cloudformation/cfn-python-lint/#metadata): + +```yaml +Resources: + myInstance: + Type: AWS::EC2::Instance + Metadata: + cfn-lint: + config: + ignore_checks: + - E3030 + Properties: + InstanceType: nt.x4superlarge + ImageId: ami-abc1234 +``` + +### cfn-lint disable entire file + +If you need to ignore an entire file, you can update the `.github/linters/.cfnlintrc.yml` to ignore certain files and locations + +```yaml +ignore_templates: + - codebuild.yaml +``` + +--- + +## Clojure + +- [clj-kondo](https://github.com/borkdude/clj-kondo) +- Since clj-kondo approaches static analysis in a very Clojure way, it is advised to read the [configuration docs](https://github.com/borkdude/clj-kondo/blob/master/doc/config.md) + +### clj-kondo standard Config file + +- `.github/linters/.clj-kondo/config.edn` + +### clj-kondo disable single line + +- There is currently **No** way to disable rules in a single line + +### clj-kondo disable code block + +- There is currently **No** way to disable rules in a code block + +### clj-kondo disable entire file + +```clojure +{:output {:exclude-files ["path/to/file"]}} +``` + +--- + +## Coffeescript + +- [coffeelint](https://coffeelint.github.io/) + +### coffeelint Config file + +- `.github/linters/.coffee-lint.yml` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.coffee.yml` + +### coffeelint disable single line + +```Coffeescript +# coffeelint: disable=max_line_length +foo = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" +# coffeelint: enable=max_line_length +``` + +### coffeelint disable code block + +```Coffeescript +# coffeelint: disable +foo = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" +bar = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" +baz = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" +taz = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" +# coffeelint: enable +``` + +### coffeelint disable entire file + +- You can encapsulate the entire file with the _code block format_ to disable an entire file from being parsed + +--- + +## CSS + +- [stylelint](https://stylelint.io/) + +### stylelint standard Config file + +- `.github/linters/.stylelintrc.json` + +### stylelint disable single line + +```css +#id { + /* stylelint-disable-next-line declaration-no-important */ + color: pink !important; +} +``` + +### stylelint disable code block + +```css +/* stylelint-disable */ +a { +} +/* stylelint-enable */ +``` + +### stylelint disable entire file + +- You can disable entire files with the `ignoreFiles` property in `.stylelintrc.json` + +```json +{ + "ignoreFiles": [ + "styles/ignored/wildcards/*.css", + "styles/ignored/specific-file.css" + ] +} +``` + +--- + +## Dart + +- [dartanalyzer](https://dart.dev/tools/dartanalyzer) + +### dartanalyzer standard Config file + +- `.github/linters/.dart-lint.yml` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/anaylsis_options.yaml` + +### dartanalyzer disable single line + +```dart +int x = ''; // ignore: invalid_assignment +``` + +### dartanalyzer disable code block + +- You can make [rule exceptions](https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis) for the entire file. + +```dart +// ignore_for_file: unused_import, unused_local_variable +``` + +### dartanalyzer disable entire file + +- You can disable entire files with the `analyzer.exclude` property in `anaylsis_options.yaml` + +```dart +analyzer: + exclude: + - file +``` + +--- + +## Dockerfile + +- [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) + +### Dockerfilelint standard Config file + +- `.github/linters/.dockerfilelintrc` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.dockerfilelintrc` + +### Dockerfilelint disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### Dockerfilelint disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### Dockerfilelint disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + +## EDITORCONFIG-CHECKER +- [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) + +### editorconfig-checker Config file +- `.github/linters/.ecrc` +- This linter will also use the [`.editorconfig`](https://editorconfig.org/) of your project + +### editorconfig-checker disable single line + +```js + // editorconfig-checker-disable-line +``` + +### editorconfig-checker disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### editorconfig-checker disable entire file + +```js +// editorconfig-checker-disable-file +``` + +- You can disable entire files with the `Exclude` property in `.ecrc` + +```json +{ + "Exclude": ["path/to/file", "^regular\\/expression\\.ext$"] +} +``` + +--- + +## ENV + +- [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) + +### dotenv-linter Config file + +- There is no top level _configuration file_ available at this time + +### dotenv-linter disable single line + +```env +# Comment line will be ignored +``` + +### dotenv-linter disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### dotenv-linter disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + +## Golang + +- [golangci-lint](https://github.com/golangci/golangci-lint) + +### golangci-lint standard Config file + +- `.github/linters/.golangci.yml` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.golangci.yml` + +### golangci-lint disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### golangci-lint disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### golangci-lint disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + +## Groovy +- [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) + +### groovy-lint standard Config file +- `.github/linters/.groovylintrc.json` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.groovylintrc.json` + +### groovy-lint disable single line +```groovy +def variable = 1; // groovylint-disable-line + +// groovylint-disable-next-line +def variable = 1; + +/* groovylint-disable-next-line */ +def variable = 1; + +def variable = 1; /* groovylint-disable-line */ +``` + +### groovy-lint disable code block +```groovy +/* groovylint-disable */ + +def variable = 1; + +/* groovylint-enable */ +``` + +### groovy-lint disable entire file +- At the top line of the file add the line: +```groovy +/* groovylint-disable */ +``` + +--- + +## HTML + +- [htmlhint](https://htmlhint.com/) + +### htmlhint standard Config file + +- `.github/linters/.htmlhintrc` + +### htmlhint disable single line + +- There is currently **No** way to disable rules in a single line + +### htmlhint disable code block + +- There is currently **No** way to disable rules in a code block + +### htmlhint disable entire file + +- There is currently **No** way to disable rules in an entire file + +--- + +## Javascript eslint + +- [eslint](https://eslint.org/) + +### Javascript eslint Config file + +- `.github/linters/.eslintrc.yml` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.eslintrc.yml` + +### Javascript eslint disable single line + +```javascript +var thing = new Thing(); // eslint-disable-line no-use-before-define +thing.sayHello(); + +function Thing() { + this.sayHello = function () { + console.log("hello"); + }; +} +``` + +### Javascript eslint disable code block + +```javascript +/*eslint-disable */ + +//suppress all warnings between comments +alert("foo"); + +/*eslint-enable */ +``` + +### Javascript eslint disable entire file + +- Place at the top of the file: + +```javascript +/* eslint-disable */ +``` + +--- + +## Javascript standard + +- [standard js](https://standardjs.com/) + +### Javascript standard Config file + +- There is no top level _configuration file_ available at this time + +### Javascript standard disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### Javascript standard disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### Javascript standard disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + +## JSON + +- [jsonlint](https://github.com/zaach/jsonlint) + +### JsonLint Config file + +- There is no top level _configuration file_ available at this time + +### JsonLint disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### JsonLint disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### JsonLint disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + +## Kotlin + +- [ktlint](https://github.com/pinterest/ktlint) + +### ktlint Config file + +- There is no top level _configuration file_ available at this time + +### ktlint disable single line + +```kotlin +import package.* // ktlint-disable no-wildcard-imports +``` + +### ktlint disable code block + +```kotlin +/* ktlint-disable no-wildcard-imports */ +import package.a.* +import package.b.* +/* ktlint-enable no-wildcard-imports */ +``` + +### ktlint disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + +## Lua + +- [luarocks](https://github.com/luarocks/luacheck) + +### luacheck standard Config file +- `.github/linters/.luacheckrc` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.luacheckrc` +- See [luacheck](https://luacheck.readthedocs.io/en/stable/config.html) docs for additional + behaviors + +### luacheck disable single line +```lua +-- luacheck: globals g1 g2, ignore foo +local foo = g1(g2) -- No warnings emitted. +``` + +### luacheck disable code block +```lua +-- The following unused function is not reported. +local function f() -- luacheck: ignore + -- luacheck: globals g3 + g3() -- No warning. +end +``` + +### luacheck include/exclude files (via .luacheckrc) +```lua +include_files = {"src", "spec/*.lua", "scripts/*.lua", "*.rockspec", "*.luacheckrc"} +exclude_files = {"src/luacheck/vendor"} +``` + +### luacheck push/pop +```lua +-- luacheck: push ignore foo +foo() -- No warning. +-- luacheck: pop +foo() -- Warning is emitted. +``` + +--- + +## Markdown + +- [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli#readme) +- [markdownlint rule documentation](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md) +- [markdownlint inline comment syntax](https://github.com/DavidAnson/markdownlint#configuration) + +### markdownlint Config file + +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.markdown-lint.yml` + +### markdownlint disable single line + +```markdown +## Here is some document + +Here is some random data + + + +any violation you want + + + +Here is more data + +``` + +### markdownlint disable code block + +```markdown +## Here is some document + +Here is some random data + + + +any violations you want + + + +Here is more data +``` + +### markdownlint disable entire file + +- You can encapsulate the entire file with the _code block format_ to disable an entire file from being parsed + +--- + +## OpenAPI + +- [spectral](https://github.com/stoplightio/spectral) + +### OpenAPI Config file + +- `.github/linters/.openapirc.yml` +- You can add, extend, and disable rules +- Documentation at [Spectral Custom Rulesets](https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/guides/4-custom-rulesets.md) +- File should be located at: `.github/linters/.openapirc.yml` + +### OpenAPI disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### OpenAPI disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### OpenAPI disable entire file + +- There is currently **No** way to disable rules inline of the file(s) +- However, you can make [rule exceptions](https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/guides/6-exceptions.md?srn=gh/stoplightio/spectral/docs/guides/6-exceptions.md) in the config for individual file(s). + +--- + +## Perl + +- [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) + +### Perl Config file + +- There is no top level _configuration file_ available at this time + +### Perl disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### Perl disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### Perl disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + +## PHP + +- [PHP](https://www.php.net/) + +### PHP Config file + +- There is no top level _configuration file_ available at this time + +### PHP disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### PHP disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### PHP disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + +## Protocol Buffers + +- [protolint](https://github.com/yoheimuta/protolint) + +### protolint Config file + +- `.github/linters/.protolintrc.yml` +- You can add, extend, and disable rules +- Documentation at [Rules](https://github.com/yoheimuta/protolint#rules) and [Configuring](https://github.com/yoheimuta/protolint#configuring) + +### protolint disable single line + +```protobuf +enum Foo { + // protolint:disable:next ENUM_FIELD_NAMES_UPPER_SNAKE_CASE + firstValue = 0; + second_value = 1; // protolint:disable:this ENUM_FIELD_NAMES_UPPER_SNAKE_CASE + THIRD_VALUE = 2; +} +``` + +### protolint disable code block + +```protobuf +// protolint:disable ENUM_FIELD_NAMES_UPPER_SNAKE_CASE +enum Foo { + firstValue = 0; + second_value = 1; + THIRD_VALUE = 2; +} +// protolint:enable ENUM_FIELD_NAMES_UPPER_SNAKE_CASE +``` + +### protolint disable entire file + +- You can disable entire files with the `lint.files.exclude` property in `.protolintrc.yml` + +```yaml +# Lint directives. +lint: + # Linter files to walk. + files: + # The specific files to exclude. + exclude: + - path/to/file +``` + +--- + +## Python3 pylint + +- [pylint](https://www.pylint.org/) + +### Pylint Config file + +- `.github/linters/.python-lint` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.python-lint` + +### Pylint disable single line + +```python +global VAR # pylint: disable=global-statement +``` + +### Pylint disable code block + +```python +"""pylint option block-disable""" + +__revision__ = None + +class Foo(object): + """block-disable test""" + + def __init__(self): + pass + + def meth1(self, arg): + """this issues a message""" + print(self) + + def meth2(self, arg): + """and this one not""" + # pylint: disable=unused-argument + print(self\ + + "foo") + + def meth3(self): + """test one line disabling""" + # no error + print(self.baz) # pylint: disable=no-member + # error + print(self.baz) +``` + +### Pylint disable entire file + +```python +#!/bin/python3 +# pylint: skip-file + +var = "terrible code down here..." +``` + +--- + +## Python3 flake8 + +- [flake8](https://flake8.pycqa.org/en/latest/) + +### flake8 Config file + +- `.github/linters/.flake8` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.flake8` + +### flake8 disable single line + +```python +example = lambda: 'example' # noqa: E731 +``` + +### flake8 disable entire file + +```python +#!/bin/python3 +# flake8: noqa + +var = "terrible code down here..." +``` + +--- + +## Raku + +- [raku](https://raku.org) + +### Raku Config file + +- There is no top level _configuration file_ available at this time + +### Raku disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### Raku disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### Raku disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + + --- ## Ruby @@ -141,452 +963,25 @@ moreThings() --- -## Ansible +## Terraform -- [ansible-lint](https://github.com/ansible/ansible-lint) +- [tflint](https://github.com/terraform-linters/tflint) -### Ansible-lint Config file +### tflint standard Config file -- `.github/linters/.ansible-lint.yml` +- `.github/linters/.tflint.hcl` - You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.ansible-lint.yml` +- File should be located at: `.github/linters/.tflint.hcl` -### Ansible-lint disable single line - -```yml -- name: this would typically fire GitHasVersionRule 401 and BecomeUserWithoutBecomeRule 501 - become_user: alice # noqa 401 501 - git: src=/path/to/git/repo dest=checkout -``` - -### Ansible-lint disable code block - -```yml -- name: this would typically fire GitHasVersionRule 401 - git: src=/path/to/git/repo dest=checkout - tags: - - skip_ansible_lint -``` - -### Ansible-lint disable entire file - -```yml -- name: this would typically fire GitHasVersionRule 401 - git: src=/path/to/git/repo dest=checkout - tags: - - skip_ansible_lint -``` - ---- - -## YAML - -- [YamlLint](https://github.com/adrienverge/yamllint) - -### Yamllint Config file - -- `.github/linters/.yaml-lint.yml` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.yaml-lint.yml` - -### Yamllint disable single line - -```yml -This line is waaaaaaaaaay too long # yamllint disable-line -``` - -### Yamllint disable code block - -```yml -# yamllint disable rule:colons -- Key: value - dolor: sit, - foo: bar -# yamllint enable -``` - -### Yamllint disable entire file - -If you need to ignore an entire file, you can update the `.github/linters/.yaml-lint.yml` to ignore certain files and locations - -```yml -# For all rules -ignore: | - *.dont-lint-me.yaml - /bin/ - !/bin/*.lint-me-anyway.yaml - -rules: - key-duplicates: - ignore: | - generated - *.template.yaml - trailing-spaces: - ignore: | - *.ignore-trailing-spaces.yaml - /ascii-art/* -``` - ---- - -## Python3 - -- [pylint](https://www.pylint.org/) - -### Pylint Config file - -- `.github/linters/.python-lint` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.python-lint` - -### Pylint disable single line - -```python -global VAR # pylint: disable=global-statement -``` - -### Pylint disable code block - -```python -"""pylint option block-disable""" - -__revision__ = None - -class Foo(object): - """block-disable test""" - - def __init__(self): - pass - - def meth1(self, arg): - """this issues a message""" - print(self) - - def meth2(self, arg): - """and this one not""" - # pylint: disable=unused-argument - print(self\ - + "foo") - - def meth3(self): - """test one line disabling""" - # no error - print(self.baz) # pylint: disable=no-member - # error - print(self.baz) -``` - -### Pylint disable entire file - -```python -#!/bin/python3 -# pylint: skip-file - -var = "terrible code down here..." -``` - ---- - -## AWS CloudFormation templates - -- [cfn-lint](https://github.com/aws-cloudformation/cfn-python-lint/) - -### cfn-lint Config file - -- `.github/linters/.cfnlintrc.yml` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.cfnlintrc.yml` - -### cfn-lint disable single line +### tflint disable single line - There is currently **No** way to disable rules inline of the file(s) -### cfn-lint disable code block - -You can disable both [template](https://github.com/aws-cloudformation/cfn-python-lint/#template-based-metadata) or [resource](https://github.com/aws-cloudformation/cfn-python-lint/#resource-based-metadata) via [metadata](https://github.com/aws-cloudformation/cfn-python-lint/#metadata): - -```yaml -Resources: - myInstance: - Type: AWS::EC2::Instance - Metadata: - cfn-lint: - config: - ignore_checks: - - E3030 - Properties: - InstanceType: nt.x4superlarge - ImageId: ami-abc1234 -``` - -### cfn-lint disable entire file - -If you need to ignore an entire file, you can update the `.github/linters/.cfnlintrc.yml` to ignore certain files and locations - -```yaml -ignore_templates: - - codebuild.yaml -``` - ---- - -## JSON - -- [jsonlint](https://github.com/zaach/jsonlint) - -### JsonLint Config file - -- There is no top level _configuration file_ available at this time - -### JsonLint disable single line +### tflint disable code block - There is currently **No** way to disable rules inline of the file(s) -### JsonLint disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### JsonLint disable entire file - -- There is currently **No** way to disable rules inline of the file(s) - ---- - -## Markdown - -- [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli#readme) -- [markdownlint rule documentation](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md) -- [markdownlint inline comment syntax](https://github.com/DavidAnson/markdownlint#configuration) - -### markdownlint Config file - -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.markdown-lint.yml` - -### markdownlint disable single line - -```markdown -## Here is some document - -Here is some random data - - - -any violation you want - - - -Here is more data -``` - -### markdownlint disable code block - -```markdown -## Here is some document - -Here is some random data - - - -any violations you want - - - -Here is more data -``` - -### markdownlint disable entire file - -- You can encapsulate the entire file with the _code block format_ to disable an entire file from being parsed - ---- - -## Perl - -- [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) - -### Perl Config file - -- There is no top level _configuration file_ available at this time - -### Perl disable single line - -- There is currently **No** way to disable rules inline of the file(s) - -### Perl disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### Perl disable entire file - -- There is currently **No** way to disable rules inline of the file(s) - ---- - -## Raku - -- [raku](https://raku.org) - -### Raku Config file - -- There is no top level _configuration file_ available at this time - -### Raku disable single line - -- There is currently **No** way to disable rules inline of the file(s) - -### Raku disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### Raku disable entire file - -- There is currently **No** way to disable rules inline of the file(s) - ---- - ---- - -## PHP - -- [PHP](https://www.php.net/) - -### PHP Config file - -- There is no top level _configuration file_ available at this time - -### PHP disable single line - -- There is currently **No** way to disable rules inline of the file(s) - -### PHP disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### PHP disable entire file - -- There is currently **No** way to disable rules inline of the file(s) - ---- - -## XML - -- [XML](http://xmlsoft.org/) - -### LibXML Config file - -- There is no top level _configuration file_ available at this time - -### LibXML disable single line - -- There is currently **No** way to disable rules inline of the file(s) - -### LibXML disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### LibXML disable entire file - -- There is currently **No** way to disable rules inline of the file(s) - ---- - -## Coffeescript - -- [coffeelint](https://coffeelint.github.io/) - -### coffeelint Config file - -- `.github/linters/.coffee-lint.yml` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.coffee.yml` - -### coffeelint disable single line - -```Coffeescript -# coffeelint: disable=max_line_length -foo = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" -# coffeelint: enable=max_line_length -``` - -### coffeelint disable code block - -```Coffeescript -# coffeelint: disable -foo = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" -bar = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" -baz = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" -taz = "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width" -# coffeelint: enable -``` - -### coffeelint disable entire file - -- You can encapsulate the entire file with the _code block format_ to disable an entire file from being parsed - ---- - -## Javascript eslint - -- [eslint](https://eslint.org/) - -### Javascript eslint Config file - -- `.github/linters/.eslintrc.yml` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.eslintrc.yml` - -### Javascript eslint disable single line - -```javascript -var thing = new Thing(); // eslint-disable-line no-use-before-define -thing.sayHello(); - -function Thing() { - this.sayHello = function () { - console.log("hello"); - }; -} -``` - -### Javascript eslint disable code block - -```javascript -/*eslint-disable */ - -//suppress all warnings between comments -alert("foo"); - -/*eslint-enable */ -``` - -### Javascript eslint disable entire file - -- Place at the top of the file: - -```javascript -/* eslint-disable */ -``` - ---- - -## Javascript standard - -- [standard js](https://standardjs.com/) - -### Javascript standard Config file - -- There is no top level _configuration file_ available at this time - -### Javascript standard disable single line - -- There is currently **No** way to disable rules inline of the file(s) - -### Javascript standard disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### Javascript standard disable entire file +### tflint disable entire file - There is currently **No** way to disable rules inline of the file(s) @@ -656,431 +1051,72 @@ alert("foo"); --- -## Golang +## XML -- [golangci-lint](https://github.com/golangci/golangci-lint) +- [XML](http://xmlsoft.org/) -### golangci-lint standard Config file - -- `.github/linters/.golangci.yml` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.golangci.yml` - -### golangci-lint disable single line - -- There is currently **No** way to disable rules inline of the file(s) - -### golangci-lint disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### golangci-lint disable entire file - -- There is currently **No** way to disable rules inline of the file(s) - ---- - -## Groovy -- [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) - -### groovy-lint standard Config file -- `.github/linters/.groovylintrc.json` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.groovylintrc.json` - -### groovy-lint disable single line -```groovy -def variable = 1; // groovylint-disable-line - -// groovylint-disable-next-line -def variable = 1; - -/* groovylint-disable-next-line */ -def variable = 1; - -def variable = 1; /* groovylint-disable-line */ -``` - -### groovy-lint disable code block -```groovy -/* groovylint-disable */ - -def variable = 1; - -/* groovylint-enable */ -``` - -### groovy-lint disable entire file -- At the top line of the file add the line: -```groovy -/* groovylint-disable */ -``` - ---- - -## Dockerfile - -- [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) - -### Dockerfilelint standard Config file - -- `.github/linters/.dockerfilelintrc` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.dockerfilelintrc` - -### Dockerfilelint disable single line - -- There is currently **No** way to disable rules inline of the file(s) - -### Dockerfilelint disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### Dockerfilelint disable entire file - -- There is currently **No** way to disable rules inline of the file(s) - ---- - -## Terraform - -- [tflint](https://github.com/terraform-linters/tflint) - -### tflint standard Config file - -- `.github/linters/.tflint.hcl` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.tflint.hcl` - -### tflint disable single line - -- There is currently **No** way to disable rules inline of the file(s) - -### tflint disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### tflint disable entire file - -- There is currently **No** way to disable rules inline of the file(s) - ---- - -## CSS - -- [stylelint](https://stylelint.io/) - -### stylelint standard Config file - -- `.github/linters/.stylelintrc.json` - -### stylelint disable single line - -```css -#id { - /* stylelint-disable-next-line declaration-no-important */ - color: pink !important; -} -``` - -### stylelint disable code block - -```css -/* stylelint-disable */ -a { -} -/* stylelint-enable */ -``` - -### stylelint disable entire file - -- You can disable entire files with the `ignoreFiles` property in `.stylelintrc.json` - -```json -{ - "ignoreFiles": [ - "styles/ignored/wildcards/*.css", - "styles/ignored/specific-file.css" - ] -} -``` - ---- - -## ENV - -- [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) - -### dotenv-linter Config file +### LibXML Config file - There is no top level _configuration file_ available at this time -### dotenv-linter disable single line - -```env -# Comment line will be ignored -``` - -### dotenv-linter disable code block +### LibXML disable single line - There is currently **No** way to disable rules inline of the file(s) -### dotenv-linter disable entire file +### LibXML disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### LibXML disable entire file - There is currently **No** way to disable rules inline of the file(s) --- -## Kotlin +## YAML -- [ktlint](https://github.com/pinterest/ktlint) +- [YamlLint](https://github.com/adrienverge/yamllint) -### ktlint Config file +### Yamllint Config file -- There is no top level _configuration file_ available at this time - -### ktlint disable single line - -```kotlin -import package.* // ktlint-disable no-wildcard-imports -``` - -### ktlint disable code block - -```kotlin -/* ktlint-disable no-wildcard-imports */ -import package.a.* -import package.b.* -/* ktlint-enable no-wildcard-imports */ -``` - -### ktlint disable entire file - -- There is currently **No** way to disable rules inline of the file(s) - ---- - -## Lua -- [luarocks](https://github.com/luarocks/luacheck) - -### luacheck standard Config file -- `.github/linters/.luacheckrc` +- `.github/linters/.yaml-lint.yml` - You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.luacheckrc` -- See [luacheck](https://luacheck.readthedocs.io/en/stable/config.html) docs for additional - behaviors +- File should be located at: `.github/linters/.yaml-lint.yml` -### luacheck disable single line -```lua --- luacheck: globals g1 g2, ignore foo -local foo = g1(g2) -- No warnings emitted. +### Yamllint disable single line + +```yml +This line is waaaaaaaaaay too long # yamllint disable-line ``` -### luacheck disable code block -```lua --- The following unused function is not reported. -local function f() -- luacheck: ignore - -- luacheck: globals g3 - g3() -- No warning. -end +### Yamllint disable code block + +```yml +# yamllint disable rule:colons +- Key: value + dolor: sit, + foo: bar +# yamllint enable ``` -### luacheck include/exclude files (via .luacheckrc) -```lua -include_files = {"src", "spec/*.lua", "scripts/*.lua", "*.rockspec", "*.luacheckrc"} -exclude_files = {"src/luacheck/vendor"} +### Yamllint disable entire file + +If you need to ignore an entire file, you can update the `.github/linters/.yaml-lint.yml` to ignore certain files and locations + +```yml +# For all rules +ignore: | + *.dont-lint-me.yaml + /bin/ + !/bin/*.lint-me-anyway.yaml + +rules: + key-duplicates: + ignore: | + generated + *.template.yaml + trailing-spaces: + ignore: | + *.ignore-trailing-spaces.yaml + /ascii-art/* ``` - -### luacheck push/pop -```lua --- luacheck: push ignore foo -foo() -- No warning. --- luacheck: pop -foo() -- Warning is emitted. -``` ---- - -## Dart - -- [dartanalyzer](https://dart.dev/tools/dartanalyzer) - -### dartanalyzer standard Config file - -- `.github/linters/.dart-lint.yml` -- You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/anaylsis_options.yaml` - -### dartanalyzer disable single line - -```dart -int x = ''; // ignore: invalid_assignment -``` - -### dartanalyzer disable code block - -- You can make [rule exceptions](https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis) for the entire file. - -```dart -// ignore_for_file: unused_import, unused_local_variable -``` - -### dartanalyzer disable entire file - -- You can disable entire files with the `analyzer.exclude` property in `anaylsis_options.yaml` - -```dart -analyzer: - exclude: - - file -``` - ---- - -## OpenAPI - -- [spectral](https://github.com/stoplightio/spectral) - -### OpenAPI Config file - -- `.github/linters/.openapirc.yml` -- You can add, extend, and disable rules -- Documentation at [Spectral Custom Rulesets](https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/guides/4-custom-rulesets.md) -- File should be located at: `.github/linters/.openapirc.yml` - -### OpenAPI disable single line - -- There is currently **No** way to disable rules inline of the file(s) - -### OpenAPI disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### OpenAPI disable entire file - -- There is currently **No** way to disable rules inline of the file(s) -- However, you can make [rule exceptions](https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/guides/6-exceptions.md?srn=gh/stoplightio/spectral/docs/guides/6-exceptions.md) in the config for individual file(s). - ---- - -## Protocol Buffers - -- [protolint](https://github.com/yoheimuta/protolint) - -### protolint Config file - -- `.github/linters/.protolintrc.yml` -- You can add, extend, and disable rules -- Documentation at [Rules](https://github.com/yoheimuta/protolint#rules) and [Configuring](https://github.com/yoheimuta/protolint#configuring) - -### protolint disable single line - -```protobuf -enum Foo { - // protolint:disable:next ENUM_FIELD_NAMES_UPPER_SNAKE_CASE - firstValue = 0; - second_value = 1; // protolint:disable:this ENUM_FIELD_NAMES_UPPER_SNAKE_CASE - THIRD_VALUE = 2; -} -``` - -### protolint disable code block - -```protobuf -// protolint:disable ENUM_FIELD_NAMES_UPPER_SNAKE_CASE -enum Foo { - firstValue = 0; - second_value = 1; - THIRD_VALUE = 2; -} -// protolint:enable ENUM_FIELD_NAMES_UPPER_SNAKE_CASE -``` - -### protolint disable entire file - -- You can disable entire files with the `lint.files.exclude` property in `.protolintrc.yml` - -```yaml -# Lint directives. -lint: - # Linter files to walk. - files: - # The specific files to exclude. - exclude: - - path/to/file -``` - -## Clojure - -- [clj-kondo](https://github.com/borkdude/clj-kondo) -- Since clj-kondo approaches static analysis in a very Clojure way, it is advised to read the [configuration docs](https://github.com/borkdude/clj-kondo/blob/master/doc/config.md) - -### clj-kondo standard Config file - -- `.github/linters/.clj-kondo/config.edn` - -### clj-kondo disable single line - -- There is currently **No** way to disable rules in a single line - -### clj-kondo disable code block - -- There is currently **No** way to disable rules in a code block - -### clj-kondo disable entire file - -```clojure -{:output {:exclude-files ["path/to/file"]}} -``` - -## EDITORCONFIG-CHECKER -- [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) - -### editorconfig-checker Config file -- `.github/linters/.ecrc` -- This linter will also use the [`.editorconfig`](https://editorconfig.org/) of your project - -### editorconfig-checker disable single line -- -```js - // editorconfig-checker-disable-line -``` - -### editorconfig-checker disable code block - -- There is currently **No** way to disable rules inline of the file(s) - -### editorconfig-checker disable entire file - -- - -```js -// editorconfig-checker-disable-file -``` - -- You can disable entire files with the `Exclude` property in `.ecrc` - -```json -{ - "Exclude": ["path/to/file", "^regular\\/expression\\.ext$"] -} -``` - -## HTML - -- [htmlhint](https://htmlhint.com/) - -### htmlhint standard Config file - -- `.github/linters/.htmlhintrc` - -### htmlhint disable single line - -- There is currently **No** way to disable rules in a single line - -### htmlhint disable code block - -- There is currently **No** way to disable rules in a code block - -### htmlhint disable entire file - -- There is currently **No** way to disable rules in an entire file From a593a5c9add8153c1bb490e2dae0b61953db500c Mon Sep 17 00:00:00 2001 From: Gabo Date: Thu, 23 Jul 2020 09:37:58 -0500 Subject: [PATCH 23/52] Fix rebase --- Dockerfile | 1 - lib/validation.sh | 3 --- 2 files changed, 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index a3f331d3..884c1c4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -259,7 +259,6 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ VALIDATE_XML=${VALIDATE_XML} \ VALIDATE_YAML=${VALIDATE_YAML} - ############################# # Copy scripts to container # ############################# diff --git a/lib/validation.sh b/lib/validation.sh index 07387fd5..178ffbae 100755 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -46,7 +46,6 @@ function GetValidationInfo() { ################################ # Convert strings to lowercase # ################################ - # Loop through all languages for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do # build the variable @@ -55,7 +54,6 @@ function GetValidationInfo() { eval "${VALIDATE_LANGUAGE}=${!VALIDATE_LANGUAGE,,}" done - ################################################ # Determine if any linters were explicitly set # ################################################ @@ -71,7 +69,6 @@ function GetValidationInfo() { fi done - ################################################### # Validate if we should check individual lanuages # ################################################### From b2569d37350e0ea38d563925fbcfe82ea0b43dfd Mon Sep 17 00:00:00 2001 From: Gabo Date: Thu, 23 Jul 2020 10:40:29 -0500 Subject: [PATCH 24/52] Add python config file vars in readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d90ac812..98d2c186 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,8 @@ and won't run anything unexpected. | **OUTPUT_FORMAT** | `none` | The report format to be generated, besides the stdout one. Output format of tap is currently using v13 of the specification. Supported formats: tap | | **OUTPUT_FOLDER** | `super-linter.report` | The location where the output reporting will be generated to. Output folder must not previously exist. | | **OUTPUT_DETAILS** | `simpler` | What level of details to be reported. Supported formats: simpler or detailed. | +| **PYTHON_PYLINT_CONFIG_FILE** | `.python-lint` | Filename for [pylint configuration](http://pylint.pycqa.org/en/latest/user_guide/run.html?highlight=rcfile#command-line-options) (ex: `.python-lint`, `.pylintrc`) | +| **PYTHON_FLAKE8_CONFIG_FILE** | `.flake8` | Filename for [flake8 configuration](https://flake8.pycqa.org/en/latest/user/configuration.html) (ex: `.flake8`, `tox.ini`) | | **RUBY_CONFIG_FILE** | `.ruby-lint.yml` | Filename for [rubocop configuration](https://docs.rubocop.org/rubocop/configuration.html) (ex: `.ruby-lint.yml`, `.rubocop.yml`) | | **TYPESCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [eslint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`) | | **VALIDATE_ALL_CODEBASE** | `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. | From 26c05d5e418f0af716d78ac074bbcce89c1904ee Mon Sep 17 00:00:00 2001 From: Gabo Date: Thu, 23 Jul 2020 10:41:17 -0500 Subject: [PATCH 25/52] Fix python var and rules --- lib/linter.sh | 104 +++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 4a10072b..b8eb086c 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -123,55 +123,55 @@ LINTED_LANGUAGES_ARRAY=() # Will be filled at run time with all languages that w ################### # GitHub ENV Vars # ################### -ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory -DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default) -DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors -GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path -GITHUB_REPOSITORY="${GITHUB_REPOSITORY}" # GitHub Org/Repo passed from system -GITHUB_RUN_ID="${GITHUB_RUN_ID}" # GitHub RUn ID to point to logs -GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit -GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub Token passed from environment -GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace -MULTI_STATUS="${MULTI_STATUS:-true}" # Multiple status are created for each check ran -TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases -VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files -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_CLOUDFORMATION="${VALIDATE_CLOUDFORMATION}" # Boolean to validate language -VALIDATE_CLOJURE="${VALIDATE_CLOJURE}" # Boolean to validate language -VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language -VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language -VALIDATE_DART="${VALIDATE_DART}" # Boolean to validate language -VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language -VALIDATE_EDITORCONFIG="${VALIDATE_EDITORCONFIG}" # Boolean to validate files with editorconfig -VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language -VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language -VALIDATE_GROOVY="${VALIDATE_GROOVY}" # Boolean to validate language -VALIDATE_HTML="${VALIDATE_HTML}" # Boolean to validate language -VALIDATE_JAVASCRIPT_ES="${VALIDATE_JAVASCRIPT_ES}" # Boolean to validate language -VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to validate language -VALIDATE_JSON="${VALIDATE_JSON}" # Boolean to validate language -VALIDATE_JSX="${VALIDATE_JSX}" # Boolean to validate language -VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language -VALIDATE_LUA="${VALIDATE_LUA}" # Boolean to validate language -VALIDATE_MARKDOWN="${VALIDATE_MD:-}" # Boolean to validate language -VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language -VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language -VALIDATE_PHP="${VALIDATE_PHP}" # Boolean to validate language -VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language -VALIDATE_PYTHON_PYLINT="${VALIDATE_PYTHON:-}" # Boolean to validate language -VALIDATE_PYTHON_FLAKE8="${VALIDATE_PYTHON_FLAKE8}" # Boolean to validate language -VALIDATE_RAKU="${VALIDATE_RAKU}" # Boolean to validate language -VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language -VALIDATE_STATES="${VALIDATE_STATES}" # Boolean to validate language -VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language -VALIDATE_TERRAFORM_TERRASCAN="${VALIDATE_TERRAFORM_TERRASCAN}" # Boolean to validate language -VALIDATE_TSX="${VALIDATE_TSX}" # Boolean to validate language -VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to validate language -VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to validate language -VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate language -VALIDATE_YAML="${VALIDATE_YAML}" # Boolean to validate language +ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory +DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default) +DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors +GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path +GITHUB_REPOSITORY="${GITHUB_REPOSITORY}" # GitHub Org/Repo passed from system +GITHUB_RUN_ID="${GITHUB_RUN_ID}" # GitHub RUn ID to point to logs +GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit +GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub Token passed from environment +GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace +MULTI_STATUS="${MULTI_STATUS:-true}" # Multiple status are created for each check ran +TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases +VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files +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_CLOUDFORMATION="${VALIDATE_CLOUDFORMATION}" # Boolean to validate language +VALIDATE_CLOJURE="${VALIDATE_CLOJURE}" # Boolean to validate language +VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language +VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language +VALIDATE_DART="${VALIDATE_DART}" # Boolean to validate language +VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language +VALIDATE_EDITORCONFIG="${VALIDATE_EDITORCONFIG}" # Boolean to validate files with editorconfig +VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language +VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language +VALIDATE_GROOVY="${VALIDATE_GROOVY}" # Boolean to validate language +VALIDATE_HTML="${VALIDATE_HTML}" # Boolean to validate language +VALIDATE_JAVASCRIPT_ES="${VALIDATE_JAVASCRIPT_ES}" # Boolean to validate language +VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to validate language +VALIDATE_JSON="${VALIDATE_JSON}" # Boolean to validate language +VALIDATE_JSX="${VALIDATE_JSX}" # Boolean to validate language +VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language +VALIDATE_LUA="${VALIDATE_LUA}" # Boolean to validate language +VALIDATE_MARKDOWN="${VALIDATE_MD:-}" # Boolean to validate language +VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language +VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language +VALIDATE_PHP="${VALIDATE_PHP}" # Boolean to validate language +VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language +VALIDATE_PYTHON_PYLINT="${VALIDATE_PYTHON:-$VALIDATE_PYTHON_PYLINT}" # Boolean to validate language +VALIDATE_PYTHON_FLAKE8="${VALIDATE_PYTHON_FLAKE8}" # Boolean to validate language +VALIDATE_RAKU="${VALIDATE_RAKU}" # Boolean to validate language +VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language +VALIDATE_STATES="${VALIDATE_STATES}" # Boolean to validate language +VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language +VALIDATE_TERRAFORM_TERRASCAN="${VALIDATE_TERRAFORM_TERRASCAN}" # Boolean to validate language +VALIDATE_TSX="${VALIDATE_TSX}" # Boolean to validate language +VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to validate language +VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to validate language +VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate language +VALIDATE_YAML="${VALIDATE_YAML}" # Boolean to validate language ############## # Debug Vars # @@ -1097,8 +1097,10 @@ GetLinterRules "LUA" GetLinterRules "MARKDOWN" # Get PowerShell rules GetLinterRules "POWERSHELL" -# Get Python rules -GetLinterRules "PYTHON" +# Get Python pylint rules +GetLinterRules "PYTHON_PYLINT" +# Get Python flake8 rules +GetLinterRules "PYTHON_FLAKE8" # Get Ruby rules GetLinterRules "RUBY" # Get Terraform rules From 8fd0bd3eb5d6174dd63b7db6689e3ca264856a6d Mon Sep 17 00:00:00 2001 From: Gabo Date: Thu, 23 Jul 2020 10:55:15 -0500 Subject: [PATCH 26/52] Fix python file type --- lib/linter.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index b8eb086c..464b8a53 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1522,7 +1522,7 @@ if [ "${VALIDATE_PYTHON_PYLINT}" == "true" ]; then # Lint the python files # ######################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PYTHON" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_PYLINT[@]}" + LintCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_PYLINT[@]}" fi ################## @@ -1533,7 +1533,7 @@ if [ "${VALIDATE_PYTHON_FLAKE8}" == "true" ]; then # Lint the python files # ######################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PYTHON" "flake8" "flake8 --config=${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_FLAKE8[@]}" + LintCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config=${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_FLAKE8[@]}" fi ################ From 5f3ae40c9b7ef87813985a75d21fb1eff9b260ac Mon Sep 17 00:00:00 2001 From: Gabo Date: Thu, 23 Jul 2020 13:18:23 -0500 Subject: [PATCH 27/52] Add VALIDATE_PYTHON back to the readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 98d2c186..a453dc1e 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,7 @@ and won't run anything unexpected. | **VALIDATE_PERL** | `true` | Flag to enable or disable the linting process of the Perl language. | | **VALIDATE_PHP** | `true` | Flag to enable or disable the linting process of the PHP language. | | **VALIDATE_PROTOBUF** | `true` | Flag to enable or disable the linting process of the Protobuf language. | +| **VALIDATE_PYTHON** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: pylint) (keep for backward compatibility) | | **VALIDATE_PYTHON_PYLINT** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: pylint) | | **VALIDATE_PYTHON_FLAKE8** | `true` | Flag to enable or disable the linting process of the Python language. (Utilizing: flake8) | | **VALIDATE_POWERSHELL** | `true` | Flag to enable or disable the linting process of the Powershell language. | From 87b825e2a9bb20c04d4d1ac970d764d778c558b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2020 05:24:15 +0000 Subject: [PATCH 28/52] Bump eslint-plugin-jest from 23.18.2 to 23.19.0 in /dependencies Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 23.18.2 to 23.19.0. - [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases) - [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/master/CHANGELOG.md) - [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v23.18.2...v23.19.0) Signed-off-by: dependabot[bot] --- dependencies/package-lock.json | 6 +++--- dependencies/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dependencies/package-lock.json b/dependencies/package-lock.json index 31315d49..0d3fe13e 100644 --- a/dependencies/package-lock.json +++ b/dependencies/package-lock.json @@ -1883,9 +1883,9 @@ } }, "eslint-plugin-jest": { - "version": "23.18.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.18.2.tgz", - "integrity": "sha512-afVOE47F0PENnRlnePUHgrDbv1tsDlTAVrjL051oUETB2ImzBwa5GfmUAUhDjAEuxH+xkE6DsmEpZ8obXzUMqQ==", + "version": "23.19.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.19.0.tgz", + "integrity": "sha512-l5PLflALqnODl8Yy0H5hDs18aKJS1KTf66VZGXRpIhmbLbPLaTuMB2P+65fBpkdseSpnTVcIlBYvTvJSBi/itg==", "requires": { "@typescript-eslint/experimental-utils": "^2.5.0" }, diff --git a/dependencies/package.json b/dependencies/package.json index b493cb56..288e37e5 100644 --- a/dependencies/package.json +++ b/dependencies/package.json @@ -9,7 +9,7 @@ "dockerfilelint": "^1.5.0", "eslint": "^7.5.0", "eslint-config-prettier": "^6.11.0", - "eslint-plugin-jest": "^23.18.2", + "eslint-plugin-jest": "^23.19.0", "htmlhint": "^0.14.1", "jsonlint": "^1.6.3", "markdownlint-cli": "^0.23.2", From 3c50eee482a48d3b5d84beff12eff23ed9bdd5e8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2020 05:25:24 +0000 Subject: [PATCH 29/52] Bump @typescript-eslint/parser from 3.7.0 to 3.7.1 in /dependencies Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 3.7.0 to 3.7.1. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v3.7.1/packages/parser) Signed-off-by: dependabot[bot] --- dependencies/package-lock.json | 54 ++++++++++++++++++++++++++++++---- dependencies/package.json | 2 +- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/dependencies/package-lock.json b/dependencies/package-lock.json index 31315d49..f079920d 100644 --- a/dependencies/package-lock.json +++ b/dependencies/package-lock.json @@ -538,15 +538,57 @@ } }, "@typescript-eslint/parser": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-3.7.0.tgz", - "integrity": "sha512-2LZauVUt7jAWkcIW7djUc3kyW+fSarNEuM3RF2JdLHR9BfX/nDEnyA4/uWz0wseoWVZbDXDF7iF9Jc342flNqQ==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-3.7.1.tgz", + "integrity": "sha512-W4QV/gXvfIsccN8225784LNOorcm7ch68Fi3V4Wg7gmkWSQRKevO4RrRqWo6N/Z/myK1QAiGgeaXN57m+R/8iQ==", "requires": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "3.7.0", - "@typescript-eslint/types": "3.7.0", - "@typescript-eslint/typescript-estree": "3.7.0", + "@typescript-eslint/experimental-utils": "3.7.1", + "@typescript-eslint/types": "3.7.1", + "@typescript-eslint/typescript-estree": "3.7.1", "eslint-visitor-keys": "^1.1.0" + }, + "dependencies": { + "@typescript-eslint/experimental-utils": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-3.7.1.tgz", + "integrity": "sha512-TqE97pv7HrqWcGJbLbZt1v59tcqsSVpWTOf1AqrWK7n8nok2sGgVtYRuGXeNeLw3wXlLEbY1MKP3saB2HsO/Ng==", + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/types": "3.7.1", + "@typescript-eslint/typescript-estree": "3.7.1", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0" + } + }, + "@typescript-eslint/types": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-3.7.1.tgz", + "integrity": "sha512-PZe8twm5Z4b61jt7GAQDor6KiMhgPgf4XmUb9zdrwTbgtC/Sj29gXP1dws9yEn4+aJeyXrjsD9XN7AWFhmnUfg==" + }, + "@typescript-eslint/typescript-estree": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.7.1.tgz", + "integrity": "sha512-m97vNZkI08dunYOr2lVZOHoyfpqRs0KDpd6qkGaIcLGhQ2WPtgHOd/eVbsJZ0VYCQvupKrObAGTOvk3tfpybYA==", + "requires": { + "@typescript-eslint/types": "3.7.1", + "@typescript-eslint/visitor-keys": "3.7.1", + "debug": "^4.1.1", + "glob": "^7.1.6", + "is-glob": "^4.0.1", + "lodash": "^4.17.15", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + } + }, + "@typescript-eslint/visitor-keys": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-3.7.1.tgz", + "integrity": "sha512-xn22sQbEya+Utj2IqJHGLA3i1jDzR43RzWupxojbSWnj3nnPLavaQmWe5utw03CwYao3r00qzXfgJMGNkrzrAA==", + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + } } }, "@typescript-eslint/types": { diff --git a/dependencies/package.json b/dependencies/package.json index b493cb56..86736d45 100644 --- a/dependencies/package.json +++ b/dependencies/package.json @@ -4,7 +4,7 @@ "@coffeelint/cli": "^3.2.10", "@stoplight/spectral": "^5.4.0", "@typescript-eslint/eslint-plugin": "^3.7.0", - "@typescript-eslint/parser": "^3.7.0", + "@typescript-eslint/parser": "^3.7.1", "babel-eslint": "^10.1.0", "dockerfilelint": "^1.5.0", "eslint": "^7.5.0", From 1619d58331e688a0e356d8b345cdf490c1b463d2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2020 12:54:31 +0000 Subject: [PATCH 30/52] Bump @typescript-eslint/eslint-plugin in /dependencies Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 3.7.0 to 3.7.1. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v3.7.1/packages/eslint-plugin) Signed-off-by: dependabot[bot] --- dependencies/package-lock.json | 40 +++++++++++++++++----------------- dependencies/package.json | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/dependencies/package-lock.json b/dependencies/package-lock.json index a740d54e..8bf1fc2f 100644 --- a/dependencies/package-lock.json +++ b/dependencies/package-lock.json @@ -513,11 +513,11 @@ "integrity": "sha512-/tiJyrc0GPcsReHzgC0SXwOmoPjLqYe01W7dLYB0yasQXMbcRee+ZIk+g8MIQhoBS8fPoBQO3Y93+aeBrI93Ug==" }, "@typescript-eslint/eslint-plugin": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.7.0.tgz", - "integrity": "sha512-4OEcPON3QIx0ntsuiuFP/TkldmBGXf0uKxPQlGtS/W2F3ndYm8Vgdpj/woPJkzUc65gd3iR+qi3K8SDQP/obFg==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.7.1.tgz", + "integrity": "sha512-3DB9JDYkMrc8Au00rGFiJLK2Ja9CoMP6Ut0sHsXp3ZtSugjNxvSSHTnKLfo4o+QmjYBJqEznDqsG1zj4F2xnsg==", "requires": { - "@typescript-eslint/experimental-utils": "3.7.0", + "@typescript-eslint/experimental-utils": "3.7.1", "debug": "^4.1.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", @@ -526,13 +526,13 @@ } }, "@typescript-eslint/experimental-utils": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-3.7.0.tgz", - "integrity": "sha512-xpfXXAfZqhhqs5RPQBfAFrWDHoNxD5+sVB5A46TF58Bq1hRfVROrWHcQHHUM9aCBdy9+cwATcvCbRg8aIRbaHQ==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-3.7.1.tgz", + "integrity": "sha512-TqE97pv7HrqWcGJbLbZt1v59tcqsSVpWTOf1AqrWK7n8nok2sGgVtYRuGXeNeLw3wXlLEbY1MKP3saB2HsO/Ng==", "requires": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/types": "3.7.0", - "@typescript-eslint/typescript-estree": "3.7.0", + "@typescript-eslint/types": "3.7.1", + "@typescript-eslint/typescript-estree": "3.7.1", "eslint-scope": "^5.0.0", "eslint-utils": "^2.0.0" } @@ -592,17 +592,17 @@ } }, "@typescript-eslint/types": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-3.7.0.tgz", - "integrity": "sha512-reCaK+hyKkKF+itoylAnLzFeNYAEktB0XVfSQvf0gcVgpz1l49Lt6Vo9x4MVCCxiDydA0iLAjTF/ODH0pbfnpg==" + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-3.7.1.tgz", + "integrity": "sha512-PZe8twm5Z4b61jt7GAQDor6KiMhgPgf4XmUb9zdrwTbgtC/Sj29gXP1dws9yEn4+aJeyXrjsD9XN7AWFhmnUfg==" }, "@typescript-eslint/typescript-estree": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.7.0.tgz", - "integrity": "sha512-xr5oobkYRebejlACGr1TJ0Z/r0a2/HUf0SXqPvlgUMwiMqOCu/J+/Dr9U3T0IxpE5oLFSkqMx1FE/dKaZ8KsOQ==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.7.1.tgz", + "integrity": "sha512-m97vNZkI08dunYOr2lVZOHoyfpqRs0KDpd6qkGaIcLGhQ2WPtgHOd/eVbsJZ0VYCQvupKrObAGTOvk3tfpybYA==", "requires": { - "@typescript-eslint/types": "3.7.0", - "@typescript-eslint/visitor-keys": "3.7.0", + "@typescript-eslint/types": "3.7.1", + "@typescript-eslint/visitor-keys": "3.7.1", "debug": "^4.1.1", "glob": "^7.1.6", "is-glob": "^4.0.1", @@ -612,9 +612,9 @@ } }, "@typescript-eslint/visitor-keys": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-3.7.0.tgz", - "integrity": "sha512-k5PiZdB4vklUpUX4NBncn5RBKty8G3ihTY+hqJsCdMuD0v4jofI5xuqwnVcWxfv6iTm2P/dfEa2wMUnsUY8ODw==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-3.7.1.tgz", + "integrity": "sha512-xn22sQbEya+Utj2IqJHGLA3i1jDzR43RzWupxojbSWnj3nnPLavaQmWe5utw03CwYao3r00qzXfgJMGNkrzrAA==", "requires": { "eslint-visitor-keys": "^1.1.0" } diff --git a/dependencies/package.json b/dependencies/package.json index 6b7e9c46..3cec01fc 100644 --- a/dependencies/package.json +++ b/dependencies/package.json @@ -3,7 +3,7 @@ "dependencies": { "@coffeelint/cli": "^3.2.10", "@stoplight/spectral": "^5.4.0", - "@typescript-eslint/eslint-plugin": "^3.7.0", + "@typescript-eslint/eslint-plugin": "^3.7.1", "@typescript-eslint/parser": "^3.7.1", "babel-eslint": "^10.1.0", "dockerfilelint": "^1.5.0", From 76775d29b3851482ada4ef34955c2aaaa54f4afc Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Fri, 24 Jul 2020 20:54:11 +0200 Subject: [PATCH 31/52] Add basic PHPStan support --- .automation/test/php/php_bad_2.php | 4 ++++ .automation/test/php/reports/expected-PHP.tap | 8 +++++-- .../test/php/reports/expected-PHP_PHPSTAN.tap | 11 +++++++++ Dockerfile | 22 +++++++++++++++++- README.md | 1 + TEMPLATES/phpstan.neon | 2 ++ lib/buildFileList.sh | 1 + lib/linter.sh | 23 ++++++++++++++++++- lib/worker.sh | 1 + 9 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 .automation/test/php/php_bad_2.php create mode 100644 .automation/test/php/reports/expected-PHP_PHPSTAN.tap create mode 100644 TEMPLATES/phpstan.neon diff --git a/.automation/test/php/php_bad_2.php b/.automation/test/php/php_bad_2.php new file mode 100644 index 00000000..71559d02 --- /dev/null +++ b/.automation/test/php/php_bad_2.php @@ -0,0 +1,4 @@ + Date: Wed, 29 Jul 2020 08:24:47 -0500 Subject: [PATCH 32/52] Fixed logic --- Dockerfile | 13 +++---------- lib/linter.sh | 9 ++++----- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 34084333..944e5924 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,21 +59,14 @@ RUN apk add --update --no-cache \ go \ icu-libs \ jq \ - libc-dev \ - libxml2-utils \ + libc-dev libxml2-utils \ make \ musl-dev \ npm nodejs-current \ openjdk8-jre \ perl \ - php7 \ - php7-phar \ - php7-json \ - php7-mbstring \ - php7-tokenizer \ - php7-ctype \ - php7-curl \ - php7-dom \ + php7 php7-phar php7-json php7-mbstring \ + php7-tokenizer php7-ctype php7-curl php7-dom \ py3-setuptools \ readline-dev \ ruby ruby-dev ruby-bundler ruby-rdoc \ diff --git a/lib/linter.sh b/lib/linter.sh index 183b5c8b..09647ad9 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -75,7 +75,7 @@ OPENAPI_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${OPENAPI_FILE_NAME}" PHPSTAN_FILE_NAME='phpstan.neon' # Name of the file PHPSTAN_LINTER_RULES="${GITHUB_WORKSPACE}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules in the repository if [ ! -f "$PHPSTAN_LINTER_RULES" ]; then - PHPSTAN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules + PHPSTAN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules fi # Powershell Vars POWERSHELL_FILE_NAME='.powershell-psscriptanalyzer.psd1' # Name of the file @@ -125,7 +125,6 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' ############################################ LINTED_LANGUAGES_ARRAY=() # Will be filled at run time with all languages that were linted - ################### # GitHub ENV Vars # ################### @@ -990,7 +989,7 @@ Footer() { ################## # Print if not 0 # ################## - if [ "${!ERROR_COUNTER}" -ne 0 ]; then + if [[ "${!ERROR_COUNTER}" -ne 0 ]]; then # We found errors in the language ################### # Print the goods # @@ -1004,7 +1003,7 @@ Footer() { ###################################### # Check if we validated the langauge # ###################################### - elif [ "${!ERROR_COUNTER}" -eq 0 ] && [[ "${UNIQUE_LINTED_ARRAY[*]}" =~ ${LANGUAGE} ]]; then + elif [[ "${!ERROR_COUNTER}" -eq 0 ]] && [[ "${UNIQUE_LINTED_ARRAY[*]}" =~ ${LANGUAGE} ]]; then # No errors found when linting the language CallStatusAPI "${LANGUAGE}" "success" fi @@ -1026,7 +1025,7 @@ Footer() { # build the variable ERRORS_FOUND_LANGUAGE="ERRORS_FOUND_${LANGUAGE}" # Check if error was found - if [ "${!ERRORS_FOUND_LANGUAGE}" -ne 0 ]; then + if [[ "${!ERRORS_FOUND_LANGUAGE}" -ne 0 ]]; then # Failed exit echo -e "${NC}${F[R]}Exiting with errors found!${NC}" exit 1 From c9de3b17834693f9b239dfca89d497b1a185e1d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2020 05:32:52 +0000 Subject: [PATCH 33/52] Bump borkdude/clj-kondo from 2020.07.26 to 2020.07.29 Bumps borkdude/clj-kondo from 2020.07.26 to 2020.07.29. Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 944e5924..e50a42bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ ######################################### # Get dependency images as build stages # ######################################### -FROM borkdude/clj-kondo:2020.07.26 as clj-kondo +FROM borkdude/clj-kondo:2020.07.29 as clj-kondo FROM dotenvlinter/dotenv-linter:2.1.0 as dotenv-linter FROM mstruebing/editorconfig-checker:2.1.0 as editorconfig-checker FROM golangci/golangci-lint:v1.29.0 as golangci-lint From 8161414bef3d774d2081bd66922710b892a5dede Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 14:15:42 -0500 Subject: [PATCH 34/52] Use log functions for all output --- .automation/cleanup-docker.sh | 68 ++++---- .../templates/ghe-config-apply.sh | 20 +-- .automation/upload-docker.sh | 112 ++++++------- Dockerfile | 2 + lib/buildFileList.sh | 42 +++-- lib/linter.sh | 147 +++++++++--------- lib/log.sh | 6 +- lib/validation.sh | 42 +++-- lib/worker.sh | 94 +++++------ 9 files changed, 258 insertions(+), 275 deletions(-) diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index 028a8aa6..12d29c4b 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -29,11 +29,11 @@ DOCKERFILE_PATH="${DOCKERFILE_PATH}" # Path to the Dockerfile to be uploaded ################################################################################ #### Function Header ########################################################### Header() { - echo "" - echo "-------------------------------------------------------" - echo "----- GitHub Actions remove image from DockerHub ------" - echo "-------------------------------------------------------" - echo "" + echo + info "-------------------------------------------------------" + info "----- GitHub Actions remove image from DockerHub ------" + info "-------------------------------------------------------" + echo } ################################################################################ #### Function ValidateInput #################################################### @@ -42,11 +42,11 @@ ValidateInput() { ################ # Print header # ################ - echo "" - echo "----------------------------------------------" - echo "Gathering variables..." - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "Gathering variables..." + info "----------------------------------------------" + echo ############################ # Validate GITHUB_WORKSPACE # @@ -55,7 +55,7 @@ ValidateInput() { error "Failed to get [GITHUB_WORKSPACE]!" fatal "[${GITHUB_WORKSPACE}]" else - echo "Successfully found:[GITHUB_WORKSPACE], value:[${GITHUB_WORKSPACE}]" + info "Successfully found:[GITHUB_WORKSPACE], value:[${GITHUB_WORKSPACE}]" fi ####################### @@ -67,10 +67,10 @@ ValidateInput() { fatal "[${IMAGE_REPO}]" elif [[ ${IMAGE_REPO} == "github/super-linter" ]]; then # Found our main repo - echo "Successfully found:[IMAGE_REPO], value:[${IMAGE_REPO}]" + info "Successfully found:[IMAGE_REPO], value:[${IMAGE_REPO}]" else # This is a fork and we cant pull vars or any info - warn "No image to cleanup as this is a forked branch, and not being built with current automation!${NC}" + warn "No image to cleanup as this is a forked branch, and not being built with current automation!" exit 0 fi @@ -81,7 +81,7 @@ ValidateInput() { error "Failed to get [IMAGE_VERSION]!" fatal "[${IMAGE_VERSION}]" else - echo "Successfully found:[IMAGE_VERSION], value:[${IMAGE_VERSION}]" + info "Successfully found:[IMAGE_VERSION], value:[${IMAGE_VERSION}]" fi ############################ @@ -91,7 +91,7 @@ ValidateInput() { error "Failed to get [DOCKER_USERNAME]!" fatal "[${DOCKER_USERNAME}]" else - echo "Successfully found:[DOCKER_USERNAME], value:[${DOCKER_USERNAME}]" + info "Successfully found:[DOCKER_USERNAME], value:[${DOCKER_USERNAME}]" fi ############################ @@ -101,7 +101,7 @@ ValidateInput() { error "Failed to get [DOCKER_PASSWORD]!" fatal "[${DOCKER_PASSWORD}]" else - echo "Successfully found:[DOCKER_PASSWORD], value:[********]" + info "Successfully found:[DOCKER_PASSWORD], value:[********]" fi ################################################## @@ -127,11 +127,11 @@ LoginToDocker() { ################ # Print header # ################ - echo "" - echo "----------------------------------------------" - echo "Login to DockerHub..." - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "Login to DockerHub..." + info "----------------------------------------------" + echo ###################### # Login to DockerHub # @@ -152,7 +152,7 @@ LoginToDocker() { fatal "[${LOGIN_CMD}]" else # SUCCESS - echo "Successfully authenticated to DockerHub!" + info "Successfully authenticated to DockerHub!" fi } ################################################################################ @@ -161,11 +161,11 @@ RemoveImage() { ################ # Print header # ################ - echo "" - echo "----------------------------------------------" - echo "Removing the DockerFile image:[${IMAGE_REPO}:${IMAGE_VERSION}]" - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "Removing the DockerFile image:[${IMAGE_REPO}:${IMAGE_VERSION}]" + info "----------------------------------------------" + echo ##################################### # Create Token to auth to DockerHub # @@ -190,7 +190,7 @@ RemoveImage() { fatal "[${TOKEN}]" else # SUCCESS - echo "Successfully gained auth token from DockerHub!" + info "Successfully gained auth token from DockerHub!" fi ################################# @@ -214,17 +214,17 @@ RemoveImage() { fatal "[${REMOVE_CMD}]" else # SUCCESS - echo "Successfully [removed] Docker image tag:[${IMAGE_VERSION}] from DockerHub!" + info "Successfully [removed] Docker image tag:[${IMAGE_VERSION}] from DockerHub!" fi } ################################################################################ #### Function Footer ########################################################### Footer() { - echo "" - echo "-------------------------------------------------------" - echo "The step has completed" - echo "-------------------------------------------------------" - echo "" + echo + info "-------------------------------------------------------" + info "The step has completed" + info "-------------------------------------------------------" + echo } ################################################################################ ################################## MAIN ######################################## diff --git a/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh b/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh index 9258978b..c7370032 100644 --- a/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh +++ b/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh @@ -28,17 +28,17 @@ CheckGHEPid() ################################## if [ ${PID_CHECK} -gt ${PID_CHECK_LIMIT} ]; then # Over the limit, move on - echo "We have checked the pid ${PID_CHECK} times, moving on..." + info "We have checked the pid ${PID_CHECK} times, moving on..." else ################################################ # Check to see if the PID is alive and running # ################################################ if [ ! -f "${GHE_CONFIG_PID}" ]; then # File not found - echo "We're good to move forward, no .pid file found at:[${GHE_CONFIG_PID}]" + info "We're good to move forward, no .pid file found at:[${GHE_CONFIG_PID}]" else # Found the pid running, need to sleep - echo "Current PID found, sleeping ${SLEEP_SECONDS} seconds before next check..." + info "Current PID found, sleeping ${SLEEP_SECONDS} seconds before next check..." ################ # Sleep it off # ################ @@ -55,7 +55,7 @@ CheckGHEPid() if [ ${ERROR_CODE} -ne 0 ]; then error "Failed to sleep!" error "[${SLEEP_CMD}]" - echo "Will try to call apply as last effort..." + info "Will try to call apply as last effort..." #################################### # Call config apply as last effort # #################################### @@ -82,7 +82,7 @@ CheckGHEProcess() ################################## if [ ${PROCESS_CHECK} -gt ${PROCESS_CHECK_LIMIT} ]; then # Over the limit, move on - echo "We have checked the process ${PROCESS_CHECK} times, moving on..." + info "We have checked the process ${PROCESS_CHECK} times, moving on..." else #################################################### # Check to see if the process is alive and running # @@ -99,10 +99,10 @@ CheckGHEProcess() ############################## if [ ${ERROR_CODE} -ne 0 ]; then # No process running on the system - echo "Were good to move forward, no process like:[${GHE_APPLY_COMMAND}] running currently on the system" + info "Were good to move forward, no process like:[${GHE_APPLY_COMMAND}] running currently on the system" else # Found the process running, need to sleep - echo "Current process alive:[${CHECK_PROCESS_CMD}], sleeping ${SLEEP_SECONDS} seconds before next check..." + info "Current process alive:[${CHECK_PROCESS_CMD}], sleeping ${SLEEP_SECONDS} seconds before next check..." ################ # Sleep it off # ################ @@ -119,7 +119,7 @@ CheckGHEProcess() if [ ${ERROR_CODE} -ne 0 ]; then error "Failed to sleep!" error "[${SLEEP_CMD}]" - echo "Will try to call apply as last effort..." + info "Will try to call apply as last effort..." #################################### # Call config apply as last effort # #################################### @@ -144,7 +144,7 @@ RunConfigApply() ########## # Header # ########## - echo "Running ${GHE_APPLY_COMMAND} to the server..." + info "Running ${GHE_APPLY_COMMAND} to the server..." ############################################## # Run the command to apply changes to server # @@ -165,7 +165,7 @@ RunConfigApply() fatal "[${APPLY_CMD}]" else # Success - notice "Successfully ran ${F[C]}${GHE_APPLY_COMMAND}${NC}" + info "Successfully ran ${F[C]}${GHE_APPLY_COMMAND}" fi } ################################################################################ diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index bbb1bae7..bac7f3e8 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -35,11 +35,11 @@ UPDATE_MAJOR_TAG=0 # Flag to deploy the major tag version as ################################################################################ #### Function Header ########################################################### Header() { - echo "" - echo "-------------------------------------------------------" - echo "---- GitHub Actions Upload image to [${REGISTRY}] ----" - echo "-------------------------------------------------------" - echo "" + echo + info "-------------------------------------------------------" + info "---- GitHub Actions Upload image to [${REGISTRY}] ----" + info "-------------------------------------------------------" + echo } ################################################################################ #### Function ValidateInput #################################################### @@ -48,11 +48,11 @@ ValidateInput() { ################ # Print header # ################ - echo "" - echo "----------------------------------------------" - echo "Gathering variables..." - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "Gathering variables..." + info "----------------------------------------------" + echo ############################# # Validate GITHUB_WORKSPACE # @@ -61,7 +61,7 @@ ValidateInput() { error "Failed to get [GITHUB_WORKSPACE]!" fatal "[${GITHUB_WORKSPACE}]" else - notice "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}" + info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]" fi ##################### @@ -71,7 +71,7 @@ ValidateInput() { error "Failed to get [REGISTRY]!" fatal "[${REGISTRY}]" else - notice "Successfully found:${F[W]}[REGISTRY]${F[B]}, value:${F[W]}[${REGISTRY}]${NC}" + info "Successfully found:${F[W]}[REGISTRY]${F[B]}, value:${F[W]}[${REGISTRY}]" fi ##################################################### @@ -85,7 +85,7 @@ ValidateInput() { error "Failed to get [GPR_USERNAME]!" fatal "[${GPR_USERNAME}]" else - notice "Successfully found:${F[W]}[GPR_USERNAME]${F[B]}, value:${F[W]}[${GPR_USERNAME}]${NC}" + info "Successfully found:${F[W]}[GPR_USERNAME]${F[B]}, value:${F[W]}[${GPR_USERNAME}]" fi ###################### @@ -95,7 +95,7 @@ ValidateInput() { error "Failed to get [GPR_TOKEN]!" fatal "[${GPR_TOKEN}]" else - notice "Successfully found:${F[W]}[GPR_TOKEN]${F[B]}, value:${F[W]}[********]${NC}" + info "Successfully found:${F[W]}[GPR_TOKEN]${F[B]}, value:${F[W]}[********]" fi ######################################## # See if we need values for Ducker hub # @@ -108,7 +108,7 @@ ValidateInput() { error "Failed to get [DOCKER_USERNAME]!" fatal "[${DOCKER_USERNAME}]" else - notice "Successfully found:${F[W]}[DOCKER_USERNAME]${F[B]}, value:${F[W]}[${DOCKER_USERNAME}]${NC}" + info "Successfully found:${F[W]}[DOCKER_USERNAME]${F[B]}, value:${F[W]}[${DOCKER_USERNAME}]" fi ############################ @@ -118,7 +118,7 @@ ValidateInput() { error "Failed to get [DOCKER_PASSWORD]!" fatal "[${DOCKER_PASSWORD}]" else - notice "Successfully found:${F[W]}[DOCKER_PASSWORD]${F[B]}, value:${F[B]}[********]${NC}" + info "Successfully found:${F[W]}[DOCKER_PASSWORD]${F[B]}, value:${F[B]}[********]" fi ########################################### # We were not passed a registry to update # @@ -135,14 +135,14 @@ ValidateInput() { error "Failed to get [IMAGE_REPO]!" fatal "[${IMAGE_REPO}]" else - notice "Successfully found:${F[W]}[IMAGE_REPO]${F[B]}, value:${F[W]}[${IMAGE_REPO}]${NC}" + info "Successfully found:${F[W]}[IMAGE_REPO]${F[B]}, value:${F[W]}[${IMAGE_REPO}]" ############################################### # Need to see if GPR registry and update name # ############################################### if [[ ${REGISTRY} == "GPR" ]]; then NAME="docker.pkg.github.com/${IMAGE_REPO}/super-linter" IMAGE_REPO="${NAME}" - echo "Updated [IMAGE_REPO] to:[${IMAGE_REPO}] for GPR" + info "Updated [IMAGE_REPO] to:[${IMAGE_REPO}] for GPR" fi fi @@ -150,8 +150,8 @@ ValidateInput() { # Validate IMAGE_VERSION # ########################## if [ -z "${IMAGE_VERSION}" ]; then - warn "Failed to get [IMAGE_VERSION]!${NC}" - echo "Pulling from Branch Name..." + warn "Failed to get [IMAGE_VERSION]!" + info "Pulling from Branch Name..." ############################## # Get the name of the branch # ############################## @@ -179,9 +179,9 @@ ValidateInput() { # Set the IMAGE_VERSION to the BRANCH_NAME # ############################################ IMAGE_VERSION="${BRANCH_NAME}" - echo "Tag:[${IMAGE_VERSION}]" + info "Tag:[${IMAGE_VERSION}]" else - notice "Successfully found:${F[W]}[IMAGE_VERSION]${F[B]}, value:${F[W]}[${IMAGE_VERSION}]${NC}" + info "Successfully found:${F[W]}[IMAGE_VERSION]${F[B]}, value:${F[W]}[${IMAGE_VERSION}]" fi ################################## @@ -205,7 +205,7 @@ ValidateInput() { ################################### UPDATE_MAJOR_TAG=1 - echo "- Also deploying a major tag of:[${MAJOR_TAG}]" + info "- Also deploying a major tag of:[${MAJOR_TAG}]" fi ############################ @@ -215,7 +215,7 @@ ValidateInput() { error "Failed to get [DOCKERFILE_PATH]!" fatal "[${DOCKERFILE_PATH}]" else - notice "Successfully found:${F[W]}[DOCKERFILE_PATH]${F[B]}, value:${F[W]}[${DOCKERFILE_PATH}]${NC}" + info "Successfully found:${F[W]}[DOCKERFILE_PATH]${F[B]}, value:${F[W]}[${DOCKERFILE_PATH}]" fi } ################################################################################ @@ -232,11 +232,11 @@ Authenticate() { ################ # Print header # ################ - echo "" - echo "----------------------------------------------" - echo "Login to ${NAME}..." - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "Login to ${NAME}..." + info "----------------------------------------------" + echo ################### # Auth to service # @@ -257,7 +257,7 @@ Authenticate() { fatal "[${LOGIN_CMD}]" fatal else # SUCCESS - notice "Successfully authenticated to ${F[C]}${NAME}${F[B]}!${NC}" + info "Successfully authenticated to ${F[C]}${NAME}${F[B]}!" fi } ################################################################################ @@ -266,11 +266,11 @@ BuildImage() { ################ # Print header # ################ - echo "" - echo "----------------------------------------------" - echo "Building the DockerFile image..." - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "Building the DockerFile image..." + info "----------------------------------------------" + echo ################################ # Validate the DOCKERFILE_PATH # @@ -300,7 +300,7 @@ BuildImage() { fatal "failed to [build] Dockerfile!" else # SUCCESS - notice "Successfully Built image!${NC}" + info "Successfully Built image!" fi ######################################################## @@ -323,7 +323,7 @@ BuildImage() { fatal "failed to [tag] Dockerfile!" else # SUCCESS - notice "Successfully tagged image!${NC}" + info "Successfully tagged image!" fi fi } @@ -333,11 +333,11 @@ UploadImage() { ################ # Print header # ################ - echo "" - echo "----------------------------------------------" - echo "Uploading the DockerFile image to ${REGISTRY}..." - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "Uploading the DockerFile image to ${REGISTRY}..." + info "----------------------------------------------" + echo ############################################ # Upload the docker image that was created # @@ -357,7 +357,7 @@ UploadImage() { fatal "failed to [upload] Dockerfile!" else # SUCCESS - notice "Successfully Uploaded Docker image:${F[W]}[${IMAGE_VERSION}]${F[B]} to ${F[C]}${REGISTRY}${F[B]}!${NC}" + info "Successfully Uploaded Docker image:${F[W]}[${IMAGE_VERSION}]${F[B]} to ${F[C]}${REGISTRY}${F[B]}!" fi ######################### @@ -390,13 +390,13 @@ UploadImage() { ################### # Print the goods # ################### - echo "----------------------------------------------" - echo "Docker Image Details:" - echo "Repository:[${REPO}]" - echo "Tag:[${TAG}]" - echo "Image_ID:[${IMAGE_ID}]" - echo "Size:[${SIZE}]" - echo "----------------------------------------------" + info "----------------------------------------------" + info "Docker Image Details:" + info "Repository:[${REPO}]" + info "Tag:[${TAG}]" + info "Image_ID:[${IMAGE_ID}]" + info "Size:[${SIZE}]" + info "----------------------------------------------" fi ############################################################### @@ -421,18 +421,18 @@ UploadImage() { fatal "failed to [upload] MAJOR_TAG:[${MAJOR_TAG}] Dockerfile!" else # SUCCESS - notice "Successfully Uploaded TAG:${F[W]}[${MAJOR_TAG}]${F[B]} of Docker image to ${F[C]}${REGISTRY}${F[B]}!${NC}" + info "Successfully Uploaded TAG:${F[W]}[${MAJOR_TAG}]${F[B]} of Docker image to ${F[C]}${REGISTRY}${F[B]}!" fi fi } ################################################################################ #### Function Footer ########################################################### Footer() { - echo "" - echo "-------------------------------------------------------" - echo "The step has completed" - echo "-------------------------------------------------------" - echo "" + echo + info "-------------------------------------------------------" + info "The step has completed" + info "-------------------------------------------------------" + echo } ################################################################################ ################################## MAIN ######################################## diff --git a/Dockerfile b/Dockerfile index e50a42bf..3533b1d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -228,6 +228,8 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ GITHUB_TOKEN=${GITHUB_TOKEN} \ GITHUB_WORKSPACE=${GITHUB_WORKSPACE} \ LINTER_RULES_PATH=${LINTER_RULES_PATH} \ + LOG_FILE=${LOG_FILE} \ + LOG_LEVEL=${LOG_LEVEL} \ OUTPUT_DETAILS=${OUTPUT_DETAILS} \ OUTPUT_FOLDER=${OUTPUT_FOLDER} \ OUTPUT_FORMAT=${OUTPUT_FORMAT} \ diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 4a64eea3..ccd47747 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -16,11 +16,8 @@ function BuildFileList() { ################ # print header # ################ - if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - echo "" - echo "----------------------------------------------" - echo "Pulling in code history and branches..." - fi + debug "----------------------------------------------" + debug "Pulling in code history and branches..." ################################################################################# # Switch codebase back to the default branch to get a list of all files changed # @@ -40,18 +37,15 @@ function BuildFileList() { ############################## if [ ${ERROR_CODE} -ne 0 ]; then # Error - echo "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!" + info "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!" fatal "[${SWITCH_CMD}]" fi ################ # print header # ################ - if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - echo "" - echo "----------------------------------------------" - echo "Generating Diff with:[git diff --name-only '${DEFAULT_BRANCH}..${GITHUB_SHA}' --diff-filter=d]" - fi + debug "----------------------------------------------" + debug "Generating Diff with:[git diff --name-only '${DEFAULT_BRANCH}..${GITHUB_SHA}' --diff-filter=d]" ################################################# # Get the Array of files changed in the commits # @@ -75,9 +69,9 @@ function BuildFileList() { ################################################ # Iterate through the array of all files found # ################################################ - echo "" - echo "----------------------------------------------" - echo "Files that have been modified in the commit(s):" + echo + info "----------------------------------------------" + info "Files that have been modified in the commit(s):" for FILE in "${RAW_FILE_ARRAY[@]}"; do ########################### # Get the files extension # @@ -90,12 +84,12 @@ function BuildFileList() { ############## # Print file # ############## - echo "File:[${FILE}], File_type:[${FILE_TYPE}]" + info "File:[${FILE}], File_type:[${FILE_TYPE}]" ######### # DEBUG # ######### - #echo "FILE_TYPE:[${FILE_TYPE}]" + debug "FILE_TYPE:[${FILE_TYPE}]" ################################ # Get the CLOUDFORMATION files # @@ -472,8 +466,8 @@ function BuildFileList() { ####################### # It is a bash script # ####################### - warn "Found bash script without extension:[.sh]${NC}" - echo "Please update file with proper extensions." + warn "Found bash script without extension:[.sh]" + info "Please update file with proper extensions." ################################ # Append the file to the array # ################################ @@ -486,8 +480,8 @@ function BuildFileList() { ####################### # It is a Ruby script # ####################### - warn "Found ruby script without extension:[.rb]${NC}" - echo "Please update file with proper extensions." + warn "Found ruby script without extension:[.rb]" + info "Please update file with proper extensions." ################################ # Append the file to the array # ################################ @@ -500,7 +494,7 @@ function BuildFileList() { ############################ # Extension was not found! # ############################ - warn "Failed to get filetype for:[${FILE}]!${NC}" + warn "Failed to get filetype for:[${FILE}]!" ########################################################## # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## @@ -533,7 +527,7 @@ function BuildFileList() { ################ # Footer print # ################ - echo "" - echo "----------------------------------------------" - notice "Successfully gathered list of files...${NC}" + echo + info "----------------------------------------------" + info "Successfully gathered list of files..." } diff --git a/lib/linter.sh b/lib/linter.sh index bb9928cc..f94dd7bc 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -137,6 +137,8 @@ GITHUB_RUN_ID="${GITHUB_RUN_ID}" # GitHub GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub Token passed from environment GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace +LOG_FILE="${LOG_FILE:-super-linter.log}" # Default log file name (located in GITHUB_WORKSPACE folder) +LOG_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE) MULTI_STATUS="${MULTI_STATUS:-true}" # Multiple status are created for each check ran TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files @@ -185,6 +187,16 @@ VALIDATE_YAML="${VALIDATE_YAML}" # Boolean RUN_LOCAL="${RUN_LOCAL}" # Boolean to see if we are running locally ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-false}" # Boolean to see even more info (debug) +############ +# Log Vars # +############ +LOG_TRACE=$(if [[ ${LOG_LEVEL} == "TRACE" ]]; then echo "true";fi) # Boolean to see trace logs +export LOG_TRACE +LOG_DEBUG=$(if [[ ${LOG_LEVEL} == "DEBUG" || ${ACTIONS_RUNNER_DEBUG} == true ]]; then echo "true";fi) # Boolean to see debug logs +export LOG_DEBUG +LOG_VERBOSE=$(if [[ ${LOG_LEVEL} == "VERBOSE" ]]; then echo "true";fi) # Boolean to see verbose logs (info function) +export LOG_VERBOSE + ################ # Default Vars # ################ @@ -352,15 +364,15 @@ Header() { ########## # Prints # ########## - echo "" - echo "---------------------------------------------" - echo "--- GitHub Actions Multi Language Linter ----" - echo "---------------------------------------------" - echo "" - echo "---------------------------------------------" - echo "The Super-Linter source code can be found at:" - echo " - https://github.com/github/super-linter" - echo "---------------------------------------------" + echo + info "---------------------------------------------" + info "--- GitHub Actions Multi Language Linter ----" + info "---------------------------------------------" + echo + info "---------------------------------------------" + info "The Super-Linter source code can be found at:" + info " - https://github.com/github/super-linter" + info "---------------------------------------------" } ################################################################################ #### Function GetLinterVersions ################################################ @@ -368,9 +380,8 @@ GetLinterVersions() { ######################### # Print version headers # ######################### - echo "" - echo "---------------------------------------------" - echo "Linter Version Info:" + debug "---------------------------------------------" + debug "Linter Version Info:" ########################################################## # Go through the array of linters and print version info # @@ -399,20 +410,19 @@ GetLinterVersions() { # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then - warn "[${LINTER}]: Failed to get version info for:${NC}" + warn "[${LINTER}]: Failed to get version info for:" else ########################## # Print the version info # ########################## - notice "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}${NC}" + debug "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}" fi done ######################### # Print version footers # ######################### - echo "---------------------------------------------" - echo "" + debug "---------------------------------------------" } ################################################################################ #### Function GetLinterRules ################################################### @@ -434,8 +444,8 @@ GetLinterRules() { # Validate we have the linter rules # ##################################### if [ -f "${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" ]; then - echo "----------------------------------------------" - echo "User provided file:[${!LANGUAGE_FILE_NAME}], setting rules file..." + info "----------------------------------------------" + info "User provided file:[${!LANGUAGE_FILE_NAME}], setting rules file..." ######################################## # Update the path to the file location # @@ -445,9 +455,7 @@ GetLinterRules() { ######################################################## # No user default provided, using the template default # ######################################################## - if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - echo " -> Codebase does NOT have file:[${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]" - fi + debug " -> Codebase does NOT have file:[${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]" fi } ################################################################################ @@ -514,7 +522,7 @@ GetStandardRules() { # Get the env to add to string # ################################ ENV="$(echo "${ENV}" | cut -d'"' -f2)" - # echo "ENV:[${ENV}]" + debug "ENV:[${ENV}]" ENV_STRING+="--env ${ENV} " done @@ -652,8 +660,8 @@ GetGitHubVars() { ########## # Prints # ########## - echo "--------------------------------------------" - echo "Gathering GitHub information..." + info "--------------------------------------------" + info "Gathering GitHub information..." ############################### # Get the Run test cases flag # @@ -692,8 +700,8 @@ GetGitHubVars() { ########################################## # We are running locally for a debug run # ########################################## - echo "NOTE: ENV VAR [RUN_LOCAL] has been set to:[true]" - echo "bypassing GitHub Actions variables..." + info "NOTE: ENV VAR [RUN_LOCAL] has been set to:[true]" + info "bypassing GitHub Actions variables..." ############################ # Set the GITHUB_WORKSPACE # @@ -706,7 +714,7 @@ GetGitHubVars() { fatal "Provided volume is not a directory!" fi - echo "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]" + info "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]" # No need to touch or set the GITHUB_SHA # No need to touch or set the GITHUB_EVENT_PATH @@ -725,7 +733,7 @@ GetGitHubVars() { error "Failed to get [GITHUB_SHA]!" fatal "[${GITHUB_SHA}]" else - notice "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]${NC}" + info "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]" fi ############################ @@ -735,7 +743,7 @@ GetGitHubVars() { error "Failed to get [GITHUB_WORKSPACE]!" fatal "[${GITHUB_WORKSPACE}]" else - notice "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}" + info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]" fi ############################ @@ -745,7 +753,7 @@ GetGitHubVars() { error "Failed to get [GITHUB_EVENT_PATH]!" fatal "[${GITHUB_EVENT_PATH}]" else - notice "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}${NC}" + info "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}" fi ################################################## @@ -764,7 +772,7 @@ GetGitHubVars() { error "Failed to get [GITHUB_ORG]!" fatal "[${GITHUB_ORG}]" else - notice "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]${NC}" + info "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]" fi ####################### @@ -779,7 +787,7 @@ GetGitHubVars() { error "Failed to get [GITHUB_REPO]!" fatal "[${GITHUB_REPO}]" else - notice "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]${NC}" + info "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]" fi fi @@ -796,7 +804,7 @@ GetGitHubVars() { ################################################################################ MULTI_STATUS='false' else - notice "Successfully found:${F[W]}[GITHUB_TOKEN]${NC}" + info "Successfully found:${F[W]}[GITHUB_TOKEN]" fi ############################### @@ -815,7 +823,7 @@ GetGitHubVars() { error "Failed to get [GITHUB_REPOSITORY]!" fatal "[${GITHUB_REPOSITORY}]" else - notice "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]${NC}" + info "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]" fi ############################ @@ -825,7 +833,7 @@ GetGitHubVars() { error "Failed to get [GITHUB_RUN_ID]!" fatal "[${GITHUB_RUN_ID}]" else - notice "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]${NC}" + info "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]" fi fi } @@ -861,10 +869,8 @@ function ValidatePowershellModules() { fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]" else # Success - if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - notice "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system${NC}" - notice "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system${NC}" - fi + debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system" + debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system" fi } ################################################################################ @@ -917,8 +923,8 @@ CallStatusAPI() { ############################## if [ "${ERROR_CODE}" -ne 0 ]; then # ERROR - echo "ERROR! Failed to call GitHub Status API!" - echo "ERROR:[${SEND_STATUS_CMD}]" + info "ERROR! Failed to call GitHub Status API!" + info "ERROR:[${SEND_STATUS_CMD}]" # Not going to fail the script on this yet... fi fi @@ -926,39 +932,39 @@ CallStatusAPI() { ################################################################################ #### Function Reports ########################################################## Reports() { - echo "" - echo "----------------------------------------------" - echo "----------------------------------------------" - echo "Generated reports:" - echo "----------------------------------------------" - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "----------------------------------------------" + info "Generated reports:" + info "----------------------------------------------" + info "----------------------------------------------" + echo ################################### # Prints output report if enabled # ################################### if [ -z "${FORMAT_REPORT}" ] ; then - echo "Reports generated in folder ${REPORT_OUTPUT_FOLDER}" + info "Reports generated in folder ${REPORT_OUTPUT_FOLDER}" fi ################################ # Prints for warnings if found # ################################ for TEST in "${WARNING_ARRAY_TEST[@]}"; do - warn "Expected file to compare with was not found for ${TEST}${NC}" + warn "Expected file to compare with was not found for ${TEST}" done } ################################################################################ #### Function Footer ########################################################### Footer() { - echo "" - echo "----------------------------------------------" - echo "----------------------------------------------" - echo "The script has completed" - echo "----------------------------------------------" - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "----------------------------------------------" + info "The script has completed" + info "----------------------------------------------" + info "----------------------------------------------" + echo #################################################### # Need to clean up the lanuage array of duplicates # @@ -1001,7 +1007,7 @@ Footer() { # Exit with 0 if errors disabled # ################################## if [ "${DISABLE_ERRORS}" == "true" ]; then - warn "Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]${NC}" + warn "Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]" exit 0 fi @@ -1022,10 +1028,10 @@ Footer() { ######################## # Footer prints Exit 0 # ######################## - echo "" - notice "All file(s) linted successfully with no errors detected${NC}" - echo "----------------------------------------------" - echo "" + echo + notice "All file(s) linted successfully with no errors detected" + info "----------------------------------------------" + echo # Successful exit exit 0 } @@ -1036,7 +1042,7 @@ Footer() { cleanup() { local -ri EXIT_CODE=$? - sudo sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/super-linter.log" || true + sudo sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/${LOG_FILE}" || true exit ${EXIT_CODE} trap - 0 1 2 3 6 14 15 @@ -1118,15 +1124,10 @@ GetLinterRules "TYPESCRIPT" # Get YAML rules GetLinterRules "YAML" -################################# -# Check if were in verbose mode # -################################# -if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - ################################## - # Get and print all version info # - ################################## - GetLinterVersions -fi +################################## +# Get and print all version info # +################################## +GetLinterVersions ########################################### # Check to see if this is a test case run # @@ -1562,7 +1563,7 @@ if [ "${VALIDATE_RAKU}" == "true" ]; then ####################### # Lint the raku files # ####################### - echo "${GITHUB_WORKSPACE}/META6.json" + info "${GITHUB_WORKSPACE}/META6.json" if [ -e "${GITHUB_WORKSPACE}/META6.json" ]; then cd "${GITHUB_WORKSPACE}" && zef install --deps-only --/test . fi diff --git a/lib/log.sh b/lib/log.sh index 532a60a5..fce6b072 100644 --- a/lib/log.sh +++ b/lib/log.sh @@ -41,9 +41,9 @@ log() { fi ) } -trace() { log "${TRACE:-}" "${NC}$(date +"%F %T") ${F[B]}[TRACE ]${NC} $*${NC}"; } -debug() { log "${DEBUG:-}" "${NC}$(date +"%F %T") ${F[B]}[DEBUG ]${NC} $*${NC}"; } -info() { log "${VERBOSE:-}" "${NC}$(date +"%F %T") ${F[B]}[INFO ]${NC} $*${NC}"; } +trace() { log "${LOG_TRACE:-}" "${NC}$(date +"%F %T") ${F[B]}[TRACE ]${NC} $*${NC}"; } +debug() { log "${LOG_DEBUG:-}" "${NC}$(date +"%F %T") ${F[B]}[DEBUG ]${NC} $*${NC}"; } +info() { log "${LOG_VERBOSE:-}" "${NC}$(date +"%F %T") ${F[B]}[INFO ]${NC} $*${NC}"; } notice() { log "true" "${NC}$(date +"%F %T") ${F[G]}[NOTICE]${NC} $*${NC}"; } warn() { log "true" "${NC}$(date +"%F %T") ${F[Y]}[WARN ]${NC} $*${NC}"; } error() { log "true" "${NC}$(date +"%F %T") ${F[R]}[ERROR ]${NC} $*${NC}"; } diff --git a/lib/validation.sh b/lib/validation.sh index 178ffbae..1cc7517d 100755 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -13,9 +13,9 @@ function GetValidationInfo() { ############################################ # Print headers for user provided env vars # ############################################ - echo "" - echo "--------------------------------------------" - echo "Gathering user validation information..." + echo + info "--------------------------------------------" + info "Gathering user validation information..." ########################################### # Skip validation if were running locally # @@ -31,10 +31,10 @@ function GetValidationInfo() { if [[ ${VALIDATE_ALL_CODEBASE} != "false" ]]; then # Set to true VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" - echo "- Validating ALL files in code base..." + info "- Validating ALL files in code base..." else # Its false - echo "- Only validating [new], or [edited] files in code base..." + info "- Only validating [new], or [edited] files in code base..." fi fi @@ -167,23 +167,19 @@ function GetValidationInfo() { ACTIONS_RUNNER_DEBUG="true" fi - ################### - # Debug on runner # - ################### - if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - ########################### - # Print the validate info # - ########################### - for LINE in "${PRINT_ARRAY[@]}"; do - echo "${LINE}" - done + ########################### + # Print the validate info # + ########################### + for LINE in "${PRINT_ARRAY[@]}"; do + debug "${LINE}" + done - echo "--- DEBUG INFO ---" - echo "---------------------------------------------" - RUNNER=$(whoami) - echo "Runner:[${RUNNER}]" - echo "ENV:" - printenv - echo "---------------------------------------------" - fi + debug "--- DEBUG INFO ---" + debug "---------------------------------------------" + RUNNER=$(whoami) + debug "Runner:[${RUNNER}]" + PRINTENV=$(printenv) + debug "ENV:" + debug "${PRINTENV}" + debug "---------------------------------------------" } diff --git a/lib/worker.sh b/lib/worker.sh index 39312b35..a2d1c1eb 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -53,9 +53,7 @@ function LintCodebase() { fatal "[${VALIDATE_INSTALL_CMD}]" else # Success - if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - notice "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}" - fi + debug "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" fi ########################## @@ -74,7 +72,7 @@ function LintCodebase() { if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "${VALIDATE_ALL_CODEBASE}" == "false" ]; then # No files found in commit and user has asked to not validate code base SKIP_FLAG=1 - # echo " - No files found in changeset to lint for language:[${FILE_TYPE}]" + debug " - No files found in changeset 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 @@ -120,7 +118,7 @@ function LintCodebase() { ######################### # Print the header info # ######################### - echo "${LINE}" + info "${LINE}" done ######################################## @@ -165,8 +163,8 @@ function LintCodebase() { ############## # File print # ############## - echo "---------------------------" - echo "File:[${FILE}]" + info "---------------------------" + info "File:[${FILE}]" ################################# # Add the language to the array # @@ -242,7 +240,7 @@ function LintCodebase() { ########### # Success # ########### - notice " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" + info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" ####################################################### # Store the linting as a temporary file in TAP format # @@ -278,13 +276,13 @@ function TestCodebase() { ################ # print header # ################ - echo "" - echo "----------------------------------------------" - echo "----------------------------------------------" - echo "Testing Codebase [${FILE_TYPE}] files..." - echo "----------------------------------------------" - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "----------------------------------------------" + info "Testing Codebase [${FILE_TYPE}] files..." + info "----------------------------------------------" + info "----------------------------------------------" + echo ##################################### # Validate we have linter installed # @@ -305,7 +303,7 @@ function TestCodebase() { fatal "[${VALIDATE_INSTALL_CMD}]" else # Success - notice "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}" + info "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" fi ########################## @@ -356,8 +354,8 @@ function TestCodebase() { ############## # File print # ############## - echo "---------------------------" - echo "File:[${FILE}]" + info "---------------------------" + info "File:[${FILE}]" ######################## # Set the lint command # @@ -461,7 +459,7 @@ function TestCodebase() { ########### # Success # ########### - notice " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" + info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" fi ####################################################### # Store the linting as a temporary file in TAP format # @@ -491,7 +489,7 @@ function TestCodebase() { ########### # Success # ########### - notice " - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" + info " - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" fi ####################################################### # Store the linting as a temporary file in TAP format # @@ -521,17 +519,17 @@ function TestCodebase() { ############################################# # We failed to compare the reporting output # ############################################# - error "Failed to assert TAP output:[${LINTER_NAME}]${NC}"! - echo "Please validate the asserts!" + error "Failed to assert TAP output:[${LINTER_NAME}]"! + info "Please validate the asserts!" cat "${TMPFILE}" exit 1 else # Success - notice "Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]${NC}" + info "Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]" fi else - warn "No TAP expected file found at:[${EXPECTED_FILE}]${NC}" - echo "skipping report assertions" + warn "No TAP expected file found at:[${EXPECTED_FILE}]" + info "skipping report assertions" ##################################### # Append the file type to the array # ##################################### @@ -546,7 +544,7 @@ function TestCodebase() { ################################################# # We failed to find files and no tests were ran # ################################################# - error "Failed to find any tests ran for the Linter:[${LINTER_NAME}]${NC}"! + error "Failed to find any tests ran for the Linter:[${LINTER_NAME}]"! fatal "Please validate logic or that tests exist!" fi } @@ -564,11 +562,11 @@ function RunTestCases() { ################# # Header prints # ################# - echo "" - echo "----------------------------------------------" - echo "-------------- TEST CASE RUN -----------------" - echo "----------------------------------------------" - echo "" + echo + info "----------------------------------------------" + info "-------------- TEST CASE RUN -----------------" + info "----------------------------------------------" + echo ####################### # Test case languages # @@ -661,11 +659,8 @@ function LintAnsibleFiles() { fatal "[${VALIDATE_INSTALL_CMD}]" else # Success - if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - # Success - notice "Successfully found binary in system${NC}" - echo "Location:[${VALIDATE_INSTALL_CMD}]" - fi + debug "Successfully found binary in system" + debug "Location:[${VALIDATE_INSTALL_CMD}]" fi ########################## @@ -700,7 +695,7 @@ function LintAnsibleFiles() { ################################### # Send message that were skipping # ################################### - #echo "- Skipping Ansible lint run as file(s) that were modified were read only..." + debug "- Skipping Ansible lint run as file(s) that were modified were read only..." ############################ # Create flag to skip loop # ############################ @@ -715,7 +710,7 @@ function LintAnsibleFiles() { ######################### # Print the header line # ######################### - echo "${LINE}" + info "${LINE}" done fi @@ -755,8 +750,8 @@ function LintAnsibleFiles() { ############## # File print # ############## - echo "---------------------------" - echo "File:[${FILE}]" + info "---------------------------" + info "File:[${FILE}]" ################################ # Lint the file with the rules # @@ -792,7 +787,7 @@ function LintAnsibleFiles() { ########### # Success # ########### - notice " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}" + info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" ####################################################### # Store the linting as a temporary file in TAP format # @@ -810,17 +805,12 @@ function LintAnsibleFiles() { HeaderTap "${INDEX}" "${REPORT_OUTPUT_FILE}" cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" fi - else # No ansible directory found in path - ############################### - # Check to see if debug is on # - ############################### - if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then - ######################## - # No Ansible dir found # - ######################## - warn "No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]${NC}" - echo "skipping ansible lint" - fi + else + ######################## + # No Ansible dir found # + ######################## + warn "No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]" + debug "skipping ansible lint" fi } ################################################################################ From d581a2d43ac0d170a45ee7fa61430b9319e0e971 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 14:19:07 -0500 Subject: [PATCH 35/52] Fix mistake --- .automation/upload-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index bac7f3e8..0510276a 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -255,7 +255,7 @@ Authenticate() { # ERROR error "Failed to authenticate to ${NAME}!" fatal "[${LOGIN_CMD}]" -fatal else + else # SUCCESS info "Successfully authenticated to ${F[C]}${NAME}${F[B]}!" fi From adb504d2330c117488286e4b5f28e71a1caa54ac Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 14:26:10 -0500 Subject: [PATCH 36/52] Use export to Workaround SC2034 --- lib/buildFileList.sh | 2 +- lib/linter.sh | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index ccd47747..2f07defd 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -503,7 +503,7 @@ function BuildFileList() { fi done - echo ${READ_ONLY_CHANGE_FLAG} > /dev/null 2>&1 || true # Workaround SC2034 + export READ_ONLY_CHANGE_FLAG # Workaround SC2034 ######################################### # Need to switch back to branch of code # diff --git a/lib/linter.sh b/lib/linter.sh index f94dd7bc..7bfe9592 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -209,18 +209,18 @@ DEFAULT_IFS="${IFS}" # Get the Default IFS for ############################################################### # Default Vars that are called in Subs and need to be ignored # ############################################################### -DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors -echo "${DEFAULT_DISABLE_ERRORS}" > /dev/null 2>&1 || true # Workaround SC2034 -RAW_FILE_ARRAY=() # Array of all files that were changed -echo "${RAW_FILE_ARRAY[*]}" > /dev/null 2>&1 || true # Workaround SC2034 -READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md -echo "${READ_ONLY_CHANGE_FLAG}" > /dev/null 2>&1 || true # Workaround SC2034 -TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore -echo "${TEST_CASE_FOLDER}" > /dev/null 2>&1 || true # Workaround SC2034 -DEFAULT_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/ansible" # Default Ansible Directory -echo "${DEFAULT_ANSIBLE_DIRECTORY}" > /dev/null 2>&1 || true # Workaround SC2034 -WARNING_ARRAY_TEST=() # Array of warning linters that did not have an expected test result. -echo "${WARNING_ARRAY_TEST[*]}" > /dev/null 2>&1 || true # Workaround SC2034 +DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors +export DEFAULT_DISABLE_ERRORS # Workaround SC2034 +RAW_FILE_ARRAY=() # Array of all files that were changed +export RAW_FILE_ARRAY # Workaround SC2034 +READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md +export READ_ONLY_CHANGE_FLAG # Workaround SC2034 +TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore +export TEST_CASE_FOLDER # Workaround SC2034 +DEFAULT_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/ansible" # Default Ansible Directory +export DEFAULT_ANSIBLE_DIRECTORY # Workaround SC2034 +WARNING_ARRAY_TEST=() # Array of warning linters that did not have an expected test result. +export WARNING_ARRAY_TEST # Workaround SC2034 ############## # Format # From c541a221bb228431fef90cf049c36be3e62a7f1e Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 15:05:16 -0500 Subject: [PATCH 37/52] Ditch empty echos --- .automation/cleanup-docker.sh | 10 ---------- .automation/upload-docker.sh | 12 ------------ lib/buildFileList.sh | 2 -- lib/linter.sh | 8 -------- lib/validation.sh | 1 - lib/worker.sh | 4 ---- 6 files changed, 37 deletions(-) diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index 12d29c4b..d9eb6312 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -29,11 +29,9 @@ DOCKERFILE_PATH="${DOCKERFILE_PATH}" # Path to the Dockerfile to be uploaded ################################################################################ #### Function Header ########################################################### Header() { - echo info "-------------------------------------------------------" info "----- GitHub Actions remove image from DockerHub ------" info "-------------------------------------------------------" - echo } ################################################################################ #### Function ValidateInput #################################################### @@ -42,11 +40,9 @@ ValidateInput() { ################ # Print header # ################ - echo info "----------------------------------------------" info "Gathering variables..." info "----------------------------------------------" - echo ############################ # Validate GITHUB_WORKSPACE # @@ -127,11 +123,9 @@ LoginToDocker() { ################ # Print header # ################ - echo info "----------------------------------------------" info "Login to DockerHub..." info "----------------------------------------------" - echo ###################### # Login to DockerHub # @@ -161,11 +155,9 @@ RemoveImage() { ################ # Print header # ################ - echo info "----------------------------------------------" info "Removing the DockerFile image:[${IMAGE_REPO}:${IMAGE_VERSION}]" info "----------------------------------------------" - echo ##################################### # Create Token to auth to DockerHub # @@ -220,11 +212,9 @@ RemoveImage() { ################################################################################ #### Function Footer ########################################################### Footer() { - echo info "-------------------------------------------------------" info "The step has completed" info "-------------------------------------------------------" - echo } ################################################################################ ################################## MAIN ######################################## diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index 0510276a..f9557959 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -35,11 +35,9 @@ UPDATE_MAJOR_TAG=0 # Flag to deploy the major tag version as ################################################################################ #### Function Header ########################################################### Header() { - echo info "-------------------------------------------------------" info "---- GitHub Actions Upload image to [${REGISTRY}] ----" info "-------------------------------------------------------" - echo } ################################################################################ #### Function ValidateInput #################################################### @@ -48,11 +46,9 @@ ValidateInput() { ################ # Print header # ################ - echo info "----------------------------------------------" info "Gathering variables..." info "----------------------------------------------" - echo ############################# # Validate GITHUB_WORKSPACE # @@ -232,11 +228,9 @@ Authenticate() { ################ # Print header # ################ - echo info "----------------------------------------------" info "Login to ${NAME}..." info "----------------------------------------------" - echo ################### # Auth to service # @@ -266,11 +260,9 @@ BuildImage() { ################ # Print header # ################ - echo info "----------------------------------------------" info "Building the DockerFile image..." info "----------------------------------------------" - echo ################################ # Validate the DOCKERFILE_PATH # @@ -333,11 +325,9 @@ UploadImage() { ################ # Print header # ################ - echo info "----------------------------------------------" info "Uploading the DockerFile image to ${REGISTRY}..." info "----------------------------------------------" - echo ############################################ # Upload the docker image that was created # @@ -428,11 +418,9 @@ UploadImage() { ################################################################################ #### Function Footer ########################################################### Footer() { - echo info "-------------------------------------------------------" info "The step has completed" info "-------------------------------------------------------" - echo } ################################################################################ ################################## MAIN ######################################## diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 2f07defd..6c0ba76b 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -69,7 +69,6 @@ function BuildFileList() { ################################################ # Iterate through the array of all files found # ################################################ - echo info "----------------------------------------------" info "Files that have been modified in the commit(s):" for FILE in "${RAW_FILE_ARRAY[@]}"; do @@ -527,7 +526,6 @@ function BuildFileList() { ################ # Footer print # ################ - echo info "----------------------------------------------" info "Successfully gathered list of files..." } diff --git a/lib/linter.sh b/lib/linter.sh index 7bfe9592..062c2df8 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -364,11 +364,9 @@ Header() { ########## # Prints # ########## - echo info "---------------------------------------------" info "--- GitHub Actions Multi Language Linter ----" info "---------------------------------------------" - echo info "---------------------------------------------" info "The Super-Linter source code can be found at:" info " - https://github.com/github/super-linter" @@ -932,13 +930,11 @@ CallStatusAPI() { ################################################################################ #### Function Reports ########################################################## Reports() { - echo info "----------------------------------------------" info "----------------------------------------------" info "Generated reports:" info "----------------------------------------------" info "----------------------------------------------" - echo ################################### # Prints output report if enabled # @@ -958,13 +954,11 @@ Reports() { ################################################################################ #### Function Footer ########################################################### Footer() { - echo info "----------------------------------------------" info "----------------------------------------------" info "The script has completed" info "----------------------------------------------" info "----------------------------------------------" - echo #################################################### # Need to clean up the lanuage array of duplicates # @@ -1028,10 +1022,8 @@ Footer() { ######################## # Footer prints Exit 0 # ######################## - echo notice "All file(s) linted successfully with no errors detected" info "----------------------------------------------" - echo # Successful exit exit 0 } diff --git a/lib/validation.sh b/lib/validation.sh index 1cc7517d..6e4105b0 100755 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -13,7 +13,6 @@ function GetValidationInfo() { ############################################ # Print headers for user provided env vars # ############################################ - echo info "--------------------------------------------" info "Gathering user validation information..." diff --git a/lib/worker.sh b/lib/worker.sh index a2d1c1eb..b5d5988c 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -276,13 +276,11 @@ function TestCodebase() { ################ # print header # ################ - echo info "----------------------------------------------" info "----------------------------------------------" info "Testing Codebase [${FILE_TYPE}] files..." info "----------------------------------------------" info "----------------------------------------------" - echo ##################################### # Validate we have linter installed # @@ -562,11 +560,9 @@ function RunTestCases() { ################# # Header prints # ################# - echo info "----------------------------------------------" info "-------------- TEST CASE RUN -----------------" info "----------------------------------------------" - echo ####################### # Test case languages # From 2d2fafef1b931da8ee2e8145f98d6ed81ebb1d04 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 15:18:24 -0500 Subject: [PATCH 38/52] Format code --- lib/buildFileList.sh | 1016 ++++++++++---------- lib/linter.sh | 2109 +++++++++++++++++++++--------------------- lib/log.sh | 32 +- lib/termColors.sh | 32 +- lib/validation.sh | 320 +++---- lib/worker.sh | 1612 ++++++++++++++++---------------- 6 files changed, 2562 insertions(+), 2559 deletions(-) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 6c0ba76b..a98e885f 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -10,522 +10,522 @@ ################################################################################ #### Function BuildFileList #################################################### function BuildFileList() { - # Need to build a list of all files changed - # This can be pulled from the GITHUB_EVENT_PATH payload + # Need to build a list of all files changed + # This can be pulled from the GITHUB_EVENT_PATH payload - ################ - # print header # - ################ - debug "----------------------------------------------" - debug "Pulling in code history and branches..." + ################ + # print header # + ################ + debug "----------------------------------------------" + debug "Pulling in code history and branches..." - ################################################################################# - # Switch codebase back to the default branch to get a list of all files changed # - ################################################################################# - SWITCH_CMD=$( - git -C "${GITHUB_WORKSPACE}" pull --quiet - git -C "${GITHUB_WORKSPACE}" checkout "${DEFAULT_BRANCH}" 2>&1 - ) + ################################################################################# + # Switch codebase back to the default branch to get a list of all files changed # + ################################################################################# + SWITCH_CMD=$( + git -C "${GITHUB_WORKSPACE}" pull --quiet + git -C "${GITHUB_WORKSPACE}" checkout "${DEFAULT_BRANCH}" 2>&1 + ) - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Error - info "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!" - fatal "[${SWITCH_CMD}]" - fi - - ################ - # print header # - ################ - debug "----------------------------------------------" - debug "Generating Diff with:[git diff --name-only '${DEFAULT_BRANCH}..${GITHUB_SHA}' --diff-filter=d]" - - ################################################# - # Get the Array of files changed in the commits # - ################################################# - mapfile -t RAW_FILE_ARRAY < <(git -C "${GITHUB_WORKSPACE}" diff --name-only "${DEFAULT_BRANCH}..${GITHUB_SHA}" --diff-filter=d 2>&1) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Error - error "Failed to gain a list of all files changed!" - fatal "[${RAW_FILE_ARRAY[*]}]" - fi - - ################################################ - # Iterate through the array of all files found # - ################################################ - info "----------------------------------------------" - info "Files that have been modified in the commit(s):" - for FILE in "${RAW_FILE_ARRAY[@]}"; do - ########################### - # Get the files extension # - ########################### - # Extract just the file extension - FILE_TYPE=${FILE##*.} - # To lowercase - FILE_TYPE=${FILE_TYPE,,} - - ############## - # Print file # - ############## - info "File:[${FILE}], File_type:[${FILE_TYPE}]" - - ######### - # DEBUG # - ######### - debug "FILE_TYPE:[${FILE_TYPE}]" - - ################################ - # Get the CLOUDFORMATION files # - ################################ - if [ "${FILE_TYPE}" == "yml" ] || [ "${FILE_TYPE}" == "yaml" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_YAML+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - - ##################################### - # Check if the file is CFN template # - ##################################### - if DetectCloudFormationFile "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_CLOUDFORMATION+=("${FILE}") - - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - fi - ###################### - # Get the JSON files # - ###################### - elif [ "${FILE_TYPE}" == "json" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_JSON+=("${FILE}") - ############################ - # Check if file is OpenAPI # - ############################ - if DetectOpenAPIFile "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_OPENAPI+=("${FILE}") - fi - ############################ - # Check if file is ARM # - ############################ - if DetectARMFile "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_ARM+=("${FILE}") - fi - ##################################### - # Check if the file is CFN template # - ##################################### - if DetectCloudFormationFile "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_CLOUDFORMATION+=("${FILE}") - fi - ############################################ - # Check if the file is AWS States Language # - ############################################ - if DetectAWSStatesFIle "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_STATES+=("${FILE}") - fi - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ##################### - # Get the XML files # - ##################### - elif [ "${FILE_TYPE}" == "xml" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_XML+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ########################## - # Get the MARKDOWN files # - ########################## - elif [ "${FILE_TYPE}" == "md" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_MARKDOWN+=("${FILE}") - ###################### - # Get the BASH files # - ###################### - elif [ "${FILE_TYPE}" == "sh" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_BASH+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ###################### - # Get the PERL files # - ###################### - elif [ "${FILE_TYPE}" == "pl" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_PERL+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ###################### - # Get the RAKU files # - ###################### - elif [ "${FILE_TYPE}" == "raku" ] || [ "${FILE_TYPE}" == "rakumod" ] \ - || [ "${FILE_TYPE}" == "rakutest" ] || [ "${FILE_TYPE}" == "pm6" ] \ - || [ "${FILE_TYPE}" == "pl6" ] || [ "${FILE_TYPE}" == "p6" ] ; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_RAKU+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ###################### - # Get the PHP files # - ###################### - elif [ "${FILE_TYPE}" == "php" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_PHP+=("${FILE}") - FILE_ARRAY_PHP_PHPSTAN+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ###################### - # Get the RUBY files # - ###################### - elif [ "${FILE_TYPE}" == "rb" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_RUBY+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ######################## - # Get the PYTHON files # - ######################## - elif [ "${FILE_TYPE}" == "py" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_PYTHON_PYLINT+=("${FILE}") - FILE_ARRAY_PYTHON_FLAKE8+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ######################## - # Get the COFFEE files # - ######################## - elif [ "${FILE_TYPE}" == "coffee" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_COFFEESCRIPT+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ############################ - # Get the JavaScript files # - ############################ - elif [ "${FILE_TYPE}" == "js" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_JAVASCRIPT_ES+=("${FILE}") - FILE_ARRAY_JAVASCRIPT_STANDARD+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ############################ - # Get the JSX files # - ############################ - elif [ "${FILE_TYPE}" == "jsx" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_JSX+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ############################ - # Get the TSX files # - ############################ - elif [ "${FILE_TYPE}" == "tsx" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_TSX+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ######################## - # Get the Golang files # - ######################## - ############################ - # Get the TypeScript files # - ############################ - elif [ "${FILE_TYPE}" == "ts" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_TYPESCRIPT_ES+=("${FILE}") - FILE_ARRAY_TYPESCRIPT_STANDARD+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ######################## - # Get the Golang files # - ######################## - elif [ "${FILE_TYPE}" == "go" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_GO+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ########################### - # Get the Terraform files # - ########################### - elif [ "${FILE_TYPE}" == "tf" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_TERRAFORM+=("${FILE}") - FILE_ARRAY_TERRAFORM_TERRASCAN+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ########################### - # Get the Powershell files # - ########################### - elif [ "${FILE_TYPE}" == "ps1" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_POWERSHELL+=("${FILE}") - elif [ "${FILE_TYPE}" == "css" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_CSS+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "env" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_ENV+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "kt" ] || [ "${FILE_TYPE}" == "kts" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_KOTLIN+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "$FILE_TYPE" == "lua" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_LUA+=("$FILE") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ############################ - # Get the Protocol Buffers files # - ############################ - elif [ "${FILE_TYPE}" == "dart" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_DART+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "proto" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_PROTOBUF+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE}" == "dockerfile" ] || [ "${FILE_TYPE}" == "dockerfile" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_DOCKER+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "clj" ] || [ "${FILE_TYPE}" == "cljs" ] || [ "${FILE_TYPE}" == "cljc" ] || [ "${FILE_TYPE}" == "edn" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_CLOJURE+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "html" ]; then - ################################ - # Append the file to the array # - ##############################p## - FILE_ARRAY_HTML+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ] || [ "$FILE_TYPE" == "gradle" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_GROOVY+=("$FILE") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - else - ############################################## - # Use file to see if we can parse what it is # - ############################################## - GET_FILE_TYPE_CMD=$(file "${FILE}" 2>&1) - - ################# - # Check if bash # - ################# - if [[ ${GET_FILE_TYPE_CMD} == *"Bourne-Again shell script"* ]]; then - ####################### - # It is a bash script # - ####################### - warn "Found bash script without extension:[.sh]" - info "Please update file with proper extensions." - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_BASH+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [[ ${GET_FILE_TYPE_CMD} == *"Ruby script"* ]]; then - ####################### - # It is a Ruby script # - ####################### - warn "Found ruby script without extension:[.rb]" - info "Please update file with proper extensions." - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_RUBY+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - else - ############################ - # Extension was not found! # - ############################ - warn "Failed to get filetype for:[${FILE}]!" - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - fi + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Error + info "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!" + fatal "[${SWITCH_CMD}]" fi - done - export READ_ONLY_CHANGE_FLAG # Workaround SC2034 + ################ + # print header # + ################ + debug "----------------------------------------------" + debug "Generating Diff with:[git diff --name-only '${DEFAULT_BRANCH}..${GITHUB_SHA}' --diff-filter=d]" - ######################################### - # Need to switch back to branch of code # - ######################################### - SWITCH2_CMD=$(git -C "${GITHUB_WORKSPACE}" checkout --progress --force "${GITHUB_SHA}" 2>&1) + ################################################# + # Get the Array of files changed in the commits # + ################################################# + mapfile -t RAW_FILE_ARRAY < <(git -C "${GITHUB_WORKSPACE}" diff --name-only "${DEFAULT_BRANCH}..${GITHUB_SHA}" --diff-filter=d 2>&1) - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Error - error "Failed to switch back to branch!" - fatal "[${SWITCH2_CMD}]" - fi + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Error + error "Failed to gain a list of all files changed!" + fatal "[${RAW_FILE_ARRAY[*]}]" + fi - ################ - # Footer print # - ################ - info "----------------------------------------------" - info "Successfully gathered list of files..." + ################################################ + # Iterate through the array of all files found # + ################################################ + info "----------------------------------------------" + info "Files that have been modified in the commit(s):" + for FILE in "${RAW_FILE_ARRAY[@]}"; do + ########################### + # Get the files extension # + ########################### + # Extract just the file extension + FILE_TYPE=${FILE##*.} + # To lowercase + FILE_TYPE=${FILE_TYPE,,} + + ############## + # Print file # + ############## + info "File:[${FILE}], File_type:[${FILE_TYPE}]" + + ######### + # DEBUG # + ######### + debug "FILE_TYPE:[${FILE_TYPE}]" + + ################################ + # Get the CLOUDFORMATION files # + ################################ + if [ "${FILE_TYPE}" == "yml" ] || [ "${FILE_TYPE}" == "yaml" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_YAML+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + + ##################################### + # Check if the file is CFN template # + ##################################### + if DetectCloudFormationFile "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_CLOUDFORMATION+=("${FILE}") + + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + fi + ###################### + # Get the JSON files # + ###################### + elif [ "${FILE_TYPE}" == "json" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_JSON+=("${FILE}") + ############################ + # Check if file is OpenAPI # + ############################ + if DetectOpenAPIFile "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_OPENAPI+=("${FILE}") + fi + ############################ + # Check if file is ARM # + ############################ + if DetectARMFile "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_ARM+=("${FILE}") + fi + ##################################### + # Check if the file is CFN template # + ##################################### + if DetectCloudFormationFile "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_CLOUDFORMATION+=("${FILE}") + fi + ############################################ + # Check if the file is AWS States Language # + ############################################ + if DetectAWSStatesFIle "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_STATES+=("${FILE}") + fi + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ##################### + # Get the XML files # + ##################### + elif [ "${FILE_TYPE}" == "xml" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_XML+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ########################## + # Get the MARKDOWN files # + ########################## + elif [ "${FILE_TYPE}" == "md" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_MARKDOWN+=("${FILE}") + ###################### + # Get the BASH files # + ###################### + elif [ "${FILE_TYPE}" == "sh" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_BASH+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### + # Get the PERL files # + ###################### + elif [ "${FILE_TYPE}" == "pl" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PERL+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### + # Get the RAKU files # + ###################### + elif [ "${FILE_TYPE}" == "raku" ] || [ "${FILE_TYPE}" == "rakumod" ] || + [ "${FILE_TYPE}" == "rakutest" ] || [ "${FILE_TYPE}" == "pm6" ] || + [ "${FILE_TYPE}" == "pl6" ] || [ "${FILE_TYPE}" == "p6" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_RAKU+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### + # Get the PHP files # + ###################### + elif [ "${FILE_TYPE}" == "php" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PHP+=("${FILE}") + FILE_ARRAY_PHP_PHPSTAN+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### + # Get the RUBY files # + ###################### + elif [ "${FILE_TYPE}" == "rb" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_RUBY+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ######################## + # Get the PYTHON files # + ######################## + elif [ "${FILE_TYPE}" == "py" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PYTHON_PYLINT+=("${FILE}") + FILE_ARRAY_PYTHON_FLAKE8+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ######################## + # Get the COFFEE files # + ######################## + elif [ "${FILE_TYPE}" == "coffee" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_COFFEESCRIPT+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ############################ + # Get the JavaScript files # + ############################ + elif [ "${FILE_TYPE}" == "js" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_JAVASCRIPT_ES+=("${FILE}") + FILE_ARRAY_JAVASCRIPT_STANDARD+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ############################ + # Get the JSX files # + ############################ + elif [ "${FILE_TYPE}" == "jsx" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_JSX+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ############################ + # Get the TSX files # + ############################ + elif [ "${FILE_TYPE}" == "tsx" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_TSX+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ######################## + # Get the Golang files # + ######################## + ############################ + # Get the TypeScript files # + ############################ + elif [ "${FILE_TYPE}" == "ts" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_TYPESCRIPT_ES+=("${FILE}") + FILE_ARRAY_TYPESCRIPT_STANDARD+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ######################## + # Get the Golang files # + ######################## + elif [ "${FILE_TYPE}" == "go" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_GO+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ########################### + # Get the Terraform files # + ########################### + elif [ "${FILE_TYPE}" == "tf" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_TERRAFORM+=("${FILE}") + FILE_ARRAY_TERRAFORM_TERRASCAN+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ########################### + # Get the Powershell files # + ########################### + elif [ "${FILE_TYPE}" == "ps1" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_POWERSHELL+=("${FILE}") + elif [ "${FILE_TYPE}" == "css" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_CSS+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "env" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_ENV+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "kt" ] || [ "${FILE_TYPE}" == "kts" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_KOTLIN+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "$FILE_TYPE" == "lua" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_LUA+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ############################ + # Get the Protocol Buffers files # + ############################ + elif [ "${FILE_TYPE}" == "dart" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_DART+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "proto" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PROTOBUF+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE}" == "dockerfile" ] || [ "${FILE_TYPE}" == "dockerfile" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_DOCKER+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "clj" ] || [ "${FILE_TYPE}" == "cljs" ] || [ "${FILE_TYPE}" == "cljc" ] || [ "${FILE_TYPE}" == "edn" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_CLOJURE+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "html" ]; then + ################################ + # Append the file to the array # + ##############################p## + FILE_ARRAY_HTML+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ] || [ "$FILE_TYPE" == "gradle" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_GROOVY+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + else + ############################################## + # Use file to see if we can parse what it is # + ############################################## + GET_FILE_TYPE_CMD=$(file "${FILE}" 2>&1) + + ################# + # Check if bash # + ################# + if [[ ${GET_FILE_TYPE_CMD} == *"Bourne-Again shell script"* ]]; then + ####################### + # It is a bash script # + ####################### + warn "Found bash script without extension:[.sh]" + info "Please update file with proper extensions." + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_BASH+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [[ ${GET_FILE_TYPE_CMD} == *"Ruby script"* ]]; then + ####################### + # It is a Ruby script # + ####################### + warn "Found ruby script without extension:[.rb]" + info "Please update file with proper extensions." + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_RUBY+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + else + ############################ + # Extension was not found! # + ############################ + warn "Failed to get filetype for:[${FILE}]!" + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + fi + fi + done + + export READ_ONLY_CHANGE_FLAG # Workaround SC2034 + + ######################################### + # Need to switch back to branch of code # + ######################################### + SWITCH2_CMD=$(git -C "${GITHUB_WORKSPACE}" 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 + error "Failed to switch back to branch!" + fatal "[${SWITCH2_CMD}]" + fi + + ################ + # Footer print # + ################ + info "----------------------------------------------" + info "Successfully gathered list of files..." } diff --git a/lib/linter.sh b/lib/linter.sh index 062c2df8..e106dd0e 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -22,103 +22,103 @@ source /action/lib/worker.sh # Source the function script(s) # GLOBALS # ########### # Default Vars -DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location +DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location # Ansible Vars -ANSIBLE_FILE_NAME='.ansible-lint.yml' # Name of the file -ANSIBLE_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${ANSIBLE_FILE_NAME}" # Path to the Ansible lint rules +ANSIBLE_FILE_NAME='.ansible-lint.yml' # Name of the file +ANSIBLE_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${ANSIBLE_FILE_NAME}" # Path to the Ansible lint rules # Azure Resource Manager Vars -ARM_FILE_NAME='.arm-ttk.psd1' # Name of the file -ARM_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${ARM_FILE_NAME}" # Path to the ARM lint rules +ARM_FILE_NAME='.arm-ttk.psd1' # Name of the file +ARM_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${ARM_FILE_NAME}" # Path to the ARM lint rules # Cloudformation Vars -CLOUDFORMATION_FILE_NAME='.cfnlintrc.yml' # Name of the file -CLOUDFORMATION_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${CLOUDFORMATION_FILE_NAME}" # Path to the cloudformation lint rules +CLOUDFORMATION_FILE_NAME='.cfnlintrc.yml' # Name of the file +CLOUDFORMATION_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${CLOUDFORMATION_FILE_NAME}" # Path to the cloudformation lint rules # Clojure Vars -CLOJURE_FILE_NAME='.clj-kondo/config.edn' # Name of the file -CLOJURE_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${CLOJURE_FILE_NAME}" # Path to the Clojure lint rules +CLOJURE_FILE_NAME='.clj-kondo/config.edn' # Name of the file +CLOJURE_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${CLOJURE_FILE_NAME}" # Path to the Clojure lint rules # Coffee Vars -COFFEE_FILE_NAME='.coffee-lint.json' # Name of the file -COFFEESCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${COFFEE_FILE_NAME}" # Path to the coffeescript lint rules +COFFEE_FILE_NAME='.coffee-lint.json' # Name of the file +COFFEESCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${COFFEE_FILE_NAME}" # Path to the coffeescript lint rules # CSS Vars -CSS_FILE_NAME='.stylelintrc.json' # Name of the file -CSS_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${CSS_FILE_NAME}" # Path to the CSS lint rules +CSS_FILE_NAME='.stylelintrc.json' # Name of the file +CSS_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${CSS_FILE_NAME}" # Path to the CSS lint rules # Dart Vars -DART_FILE_NAME='analysis_options.yaml' # Name of the file -DART_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${DART_FILE_NAME}" # Path to the DART lint rules +DART_FILE_NAME='analysis_options.yaml' # Name of the file +DART_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${DART_FILE_NAME}" # Path to the DART lint rules # Docker Vars -DOCKER_FILE_NAME='.dockerfilelintrc' # Name of the file -DOCKER_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${DOCKER_FILE_NAME}" # Path to the Docker lint rules +DOCKER_FILE_NAME='.dockerfilelintrc' # Name of the file +DOCKER_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${DOCKER_FILE_NAME}" # Path to the Docker lint rules # Golang Vars -GO_FILE_NAME='.golangci.yml' # Name of the file -GO_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${GO_FILE_NAME}" # Path to the Go lint rules +GO_FILE_NAME='.golangci.yml' # Name of the file +GO_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${GO_FILE_NAME}" # Path to the Go lint rules # Groovy Vars -GROOVY_FILE_NAME='.groovylintrc.json' # Name of the file -GROOVY_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${GROOVY_FILE_NAME}" # Path to the Groovy lint rules +GROOVY_FILE_NAME='.groovylintrc.json' # Name of the file +GROOVY_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${GROOVY_FILE_NAME}" # Path to the Groovy lint rules # HTML Vars -HTML_FILE_NAME='.htmlhintrc' # Name of the file -HTML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${HTML_FILE_NAME}" # Path to the CSS lint rules +HTML_FILE_NAME='.htmlhintrc' # Name of the file +HTML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${HTML_FILE_NAME}" # Path to the CSS lint rules # Javascript Vars -JAVASCRIPT_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # Name of the file -JAVASCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${JAVASCRIPT_FILE_NAME}" # Path to the Javascript lint rules -JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard +JAVASCRIPT_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # Name of the file +JAVASCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${JAVASCRIPT_FILE_NAME}" # Path to the Javascript lint rules +JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard # Default linter path -LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory +LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory # Lua Vars -LUA_FILE_NAME='.luacheckrc' # Name of the file -LUA_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${LUA_FILE_NAME}" # Path to the Lua lint rules +LUA_FILE_NAME='.luacheckrc' # Name of the file +LUA_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${LUA_FILE_NAME}" # Path to the Lua lint rules # MD Vars -MARKDOWN_FILE_NAME='.markdown-lint.yml' # Name of the file -MARKDOWN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${MARKDOWN_FILE_NAME}" # Path to the markdown lint rules +MARKDOWN_FILE_NAME='.markdown-lint.yml' # Name of the file +MARKDOWN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${MARKDOWN_FILE_NAME}" # Path to the markdown lint rules # OpenAPI Vars -OPENAPI_FILE_NAME='.openapirc.yml' # Name of the file -OPENAPI_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${OPENAPI_FILE_NAME}" # Path to the OpenAPI lint rules +OPENAPI_FILE_NAME='.openapirc.yml' # Name of the file +OPENAPI_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${OPENAPI_FILE_NAME}" # Path to the OpenAPI lint rules # PHP Vars -PHPSTAN_FILE_NAME='phpstan.neon' # Name of the file -PHPSTAN_LINTER_RULES="${GITHUB_WORKSPACE}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules in the repository +PHPSTAN_FILE_NAME='phpstan.neon' # Name of the file +PHPSTAN_LINTER_RULES="${GITHUB_WORKSPACE}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules in the repository if [ ! -f "$PHPSTAN_LINTER_RULES" ]; then - PHPSTAN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules + PHPSTAN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules fi # Powershell Vars -POWERSHELL_FILE_NAME='.powershell-psscriptanalyzer.psd1' # Name of the file -POWERSHELL_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${POWERSHELL_FILE_NAME}" # Path to the Powershell lint rules +POWERSHELL_FILE_NAME='.powershell-psscriptanalyzer.psd1' # Name of the file +POWERSHELL_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${POWERSHELL_FILE_NAME}" # Path to the Powershell lint rules # Protocol Buffers Vars -PROTOBUF_FILE_NAME='.protolintrc.yml' # Name of the file -PROTOBUF_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PROTOBUF_FILE_NAME}" # Path to the Protocol Buffers lint rules +PROTOBUF_FILE_NAME='.protolintrc.yml' # Name of the file +PROTOBUF_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PROTOBUF_FILE_NAME}" # Path to the Protocol Buffers lint rules # Python Vars -PYTHON_PYLINT_FILE_NAME="${PYTHON_PYLINT_CONFIG_FILE:-.python-lint}" # Name of the file -PYTHON_PYLINT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_PYLINT_FILE_NAME}" # Path to the python lint rules -PYTHON_FLAKE8_FILE_NAME="${PYTHON_FLAKE8_CONFIG_FILE:-.flake8}" # Name of the file -PYTHON_FLAKE8_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_FLAKE8_FILE_NAME}" # Path to the python lint rules +PYTHON_PYLINT_FILE_NAME="${PYTHON_PYLINT_CONFIG_FILE:-.python-lint}" # Name of the file +PYTHON_PYLINT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_PYLINT_FILE_NAME}" # Path to the python lint rules +PYTHON_FLAKE8_FILE_NAME="${PYTHON_FLAKE8_CONFIG_FILE:-.flake8}" # Name of the file +PYTHON_FLAKE8_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_FLAKE8_FILE_NAME}" # Path to the python lint rules # Ruby Vars -RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}" # Name of the file -RUBY_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${RUBY_FILE_NAME}" # Path to the ruby lint rules +RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}" # Name of the file +RUBY_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${RUBY_FILE_NAME}" # Path to the ruby lint rules # Terraform Vars -TERRAFORM_FILE_NAME='.tflint.hcl' # Name of the file -TERRAFORM_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${TERRAFORM_FILE_NAME}" # Path to the Terraform lint rules +TERRAFORM_FILE_NAME='.tflint.hcl' # Name of the file +TERRAFORM_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${TERRAFORM_FILE_NAME}" # Path to the Terraform lint rules # Typescript Vars -TYPESCRIPT_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # Name of the file -TYPESCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${TYPESCRIPT_FILE_NAME}" # Path to the Typescript lint rules -TYPESCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard +TYPESCRIPT_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # Name of the file +TYPESCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${TYPESCRIPT_FILE_NAME}" # Path to the Typescript lint rules +TYPESCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard # YAML Vars -YAML_FILE_NAME="${YAML_CONFIG_FILE:-.yaml-lint.yml}" # Name of the file -YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" # Path to the yaml lint rules +YAML_FILE_NAME="${YAML_CONFIG_FILE:-.yaml-lint.yml}" # Name of the file +YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" # Path to the yaml lint rules ####################################### # Linter array for information prints # ####################################### LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo' 'coffeelint' - 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'flake8' 'golangci-lint' 'htmlhint' - 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' - 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'terrascan' - 'tflint' 'xmllint' 'yamllint') + 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'flake8' 'golangci-lint' 'htmlhint' + 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' + 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'terrascan' + 'tflint' 'xmllint' 'yamllint') ############################# # Language array for prints # ############################# LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' - 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' - 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP' 'PHP_PHPSTAN' 'POWERSHELL' - 'PROTOBUF' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' - 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YML') + 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' + 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP' 'PHP_PHPSTAN' 'POWERSHELL' + 'PROTOBUF' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' + 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YML') ############################################ # Array for all languages that were linted # @@ -128,58 +128,58 @@ LINTED_LANGUAGES_ARRAY=() # Will be filled at run time with all languages that w ################### # GitHub ENV Vars # ################### -ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory -DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default) -DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors -GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path -GITHUB_REPOSITORY="${GITHUB_REPOSITORY}" # GitHub Org/Repo passed from system -GITHUB_RUN_ID="${GITHUB_RUN_ID}" # GitHub RUn ID to point to logs -GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit -GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub Token passed from environment -GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace -LOG_FILE="${LOG_FILE:-super-linter.log}" # Default log file name (located in GITHUB_WORKSPACE folder) -LOG_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE) -MULTI_STATUS="${MULTI_STATUS:-true}" # Multiple status are created for each check ran -TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases -VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files -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_CLOUDFORMATION="${VALIDATE_CLOUDFORMATION}" # Boolean to validate language -VALIDATE_CLOJURE="${VALIDATE_CLOJURE}" # Boolean to validate language -VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language -VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language -VALIDATE_DART="${VALIDATE_DART}" # Boolean to validate language -VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language -VALIDATE_EDITORCONFIG="${VALIDATE_EDITORCONFIG}" # Boolean to validate files with editorconfig -VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language -VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language -VALIDATE_GROOVY="${VALIDATE_GROOVY}" # Boolean to validate language -VALIDATE_HTML="${VALIDATE_HTML}" # Boolean to validate language -VALIDATE_JAVASCRIPT_ES="${VALIDATE_JAVASCRIPT_ES}" # Boolean to validate language -VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to validate language -VALIDATE_JSON="${VALIDATE_JSON}" # Boolean to validate language -VALIDATE_JSX="${VALIDATE_JSX}" # Boolean to validate language -VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language -VALIDATE_LUA="${VALIDATE_LUA}" # Boolean to validate language -VALIDATE_MARKDOWN="${VALIDATE_MD:-}" # Boolean to validate language -VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language -VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language -VALIDATE_PHP="${VALIDATE_PHP}" # Boolean to validate language -VALIDATE_PHP_PHPSTAN="${VALIDATE_PHP_PHPSTAN}" # Boolean to validate language -VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language -VALIDATE_PYTHON_PYLINT="${VALIDATE_PYTHON:-$VALIDATE_PYTHON_PYLINT}" # Boolean to validate language -VALIDATE_PYTHON_FLAKE8="${VALIDATE_PYTHON_FLAKE8}" # Boolean to validate language -VALIDATE_RAKU="${VALIDATE_RAKU}" # Boolean to validate language -VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language -VALIDATE_STATES="${VALIDATE_STATES}" # Boolean to validate language -VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language -VALIDATE_TERRAFORM_TERRASCAN="${VALIDATE_TERRAFORM_TERRASCAN}" # Boolean to validate language -VALIDATE_TSX="${VALIDATE_TSX}" # Boolean to validate language -VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to validate language -VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to validate language -VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate language -VALIDATE_YAML="${VALIDATE_YAML}" # Boolean to validate language +ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory +DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default) +DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors +GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path +GITHUB_REPOSITORY="${GITHUB_REPOSITORY}" # GitHub Org/Repo passed from system +GITHUB_RUN_ID="${GITHUB_RUN_ID}" # GitHub RUn ID to point to logs +GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit +GITHUB_TOKEN="${GITHUB_TOKEN}" # GitHub Token passed from environment +GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace +LOG_FILE="${LOG_FILE:-super-linter.log}" # Default log file name (located in GITHUB_WORKSPACE folder) +LOG_LEVEL="${LOG_LEVEL:-VERBOSE}" # Default log level (VERBOSE, DEBUG, TRACE) +MULTI_STATUS="${MULTI_STATUS:-true}" # Multiple status are created for each check ran +TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases +VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files +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_CLOUDFORMATION="${VALIDATE_CLOUDFORMATION}" # Boolean to validate language +VALIDATE_CLOJURE="${VALIDATE_CLOJURE}" # Boolean to validate language +VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language +VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language +VALIDATE_DART="${VALIDATE_DART}" # Boolean to validate language +VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language +VALIDATE_EDITORCONFIG="${VALIDATE_EDITORCONFIG}" # Boolean to validate files with editorconfig +VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language +VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language +VALIDATE_GROOVY="${VALIDATE_GROOVY}" # Boolean to validate language +VALIDATE_HTML="${VALIDATE_HTML}" # Boolean to validate language +VALIDATE_JAVASCRIPT_ES="${VALIDATE_JAVASCRIPT_ES}" # Boolean to validate language +VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to validate language +VALIDATE_JSON="${VALIDATE_JSON}" # Boolean to validate language +VALIDATE_JSX="${VALIDATE_JSX}" # Boolean to validate language +VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language +VALIDATE_LUA="${VALIDATE_LUA}" # Boolean to validate language +VALIDATE_MARKDOWN="${VALIDATE_MD:-}" # Boolean to validate language +VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language +VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language +VALIDATE_PHP="${VALIDATE_PHP}" # Boolean to validate language +VALIDATE_PHP_PHPSTAN="${VALIDATE_PHP_PHPSTAN}" # Boolean to validate language +VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language +VALIDATE_PYTHON_PYLINT="${VALIDATE_PYTHON:-$VALIDATE_PYTHON_PYLINT}" # Boolean to validate language +VALIDATE_PYTHON_FLAKE8="${VALIDATE_PYTHON_FLAKE8}" # Boolean to validate language +VALIDATE_RAKU="${VALIDATE_RAKU}" # Boolean to validate language +VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language +VALIDATE_STATES="${VALIDATE_STATES}" # Boolean to validate language +VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language +VALIDATE_TERRAFORM_TERRASCAN="${VALIDATE_TERRAFORM_TERRASCAN}" # Boolean to validate language +VALIDATE_TSX="${VALIDATE_TSX}" # Boolean to validate language +VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to validate language +VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to validate language +VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate language +VALIDATE_YAML="${VALIDATE_YAML}" # Boolean to validate language ############## # Debug Vars # @@ -190,37 +190,41 @@ ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-false}" # Boolean to see even more ############ # Log Vars # ############ -LOG_TRACE=$(if [[ ${LOG_LEVEL} == "TRACE" ]]; then echo "true";fi) # Boolean to see trace logs +if [[ ${ACTIONS_RUNNER_DEBUG} == true ]]; then LOG_LEVEL="DEBUG"; fi +# Boolean to see trace logs +LOG_TRACE=$(if [[ ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi) export LOG_TRACE -LOG_DEBUG=$(if [[ ${LOG_LEVEL} == "DEBUG" || ${ACTIONS_RUNNER_DEBUG} == true ]]; then echo "true";fi) # Boolean to see debug logs +# Boolean to see debug logs +LOG_DEBUG=$(if [[ ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi) export LOG_DEBUG -LOG_VERBOSE=$(if [[ ${LOG_LEVEL} == "VERBOSE" ]]; then echo "true";fi) # Boolean to see verbose logs (info function) +# Boolean to see verbose logs (info function) +LOG_VERBOSE=$(if [[ ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi) export LOG_VERBOSE ################ # Default Vars # ################ -DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files -DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-/tmp/lint}" # Default workspace if running locally -DEFAULT_RUN_LOCAL='false' # Default value for debugging locally -DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases -DEFAULT_IFS="${IFS}" # Get the Default IFS for updating +DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files +DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-/tmp/lint}" # Default workspace if running locally +DEFAULT_RUN_LOCAL='false' # Default value for debugging locally +DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases +DEFAULT_IFS="${IFS}" # Get the Default IFS for updating ############################################################### # Default Vars that are called in Subs and need to be ignored # ############################################################### -DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors -export DEFAULT_DISABLE_ERRORS # Workaround SC2034 -RAW_FILE_ARRAY=() # Array of all files that were changed -export RAW_FILE_ARRAY # Workaround SC2034 -READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md -export READ_ONLY_CHANGE_FLAG # Workaround SC2034 -TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore -export TEST_CASE_FOLDER # Workaround SC2034 -DEFAULT_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/ansible" # Default Ansible Directory -export DEFAULT_ANSIBLE_DIRECTORY # Workaround SC2034 -WARNING_ARRAY_TEST=() # Array of warning linters that did not have an expected test result. -export WARNING_ARRAY_TEST # Workaround SC2034 +DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors +export DEFAULT_DISABLE_ERRORS # Workaround SC2034 +RAW_FILE_ARRAY=() # Array of all files that were changed +export RAW_FILE_ARRAY # Workaround SC2034 +READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md +export READ_ONLY_CHANGE_FLAG # Workaround SC2034 +TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore +export TEST_CASE_FOLDER # Workaround SC2034 +DEFAULT_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/ansible" # Default Ansible Directory +export DEFAULT_ANSIBLE_DIRECTORY # Workaround SC2034 +WARNING_ARRAY_TEST=() # Array of warning linters that did not have an expected test result. +export WARNING_ARRAY_TEST # Workaround SC2034 ############## # Format # @@ -356,561 +360,133 @@ export ERRORS_FOUND_YAML # Workaround SC2034 ################################################################################ #### Function Header ########################################################### Header() { - ############################### - # Give them the possum action # - ############################### - /bin/bash /action/lib/possum.sh + ############################### + # Give them the possum action # + ############################### + /bin/bash /action/lib/possum.sh - ########## - # Prints # - ########## - info "---------------------------------------------" - info "--- GitHub Actions Multi Language Linter ----" - info "---------------------------------------------" - info "---------------------------------------------" - info "The Super-Linter source code can be found at:" - info " - https://github.com/github/super-linter" - info "---------------------------------------------" + ########## + # Prints # + ########## + info "---------------------------------------------" + info "--- GitHub Actions Multi Language Linter ----" + info "---------------------------------------------" + info "---------------------------------------------" + info "The Super-Linter source code can be found at:" + info " - https://github.com/github/super-linter" + info "---------------------------------------------" } ################################################################################ #### Function GetLinterVersions ################################################ GetLinterVersions() { - ######################### - # Print version headers # - ######################### - debug "---------------------------------------------" - debug "Linter Version Info:" + ######################### + # Print version headers # + ######################### + debug "---------------------------------------------" + debug "Linter Version Info:" - ########################################################## - # Go through the array of linters and print version info # - ########################################################## - for LINTER in "${LINTER_ARRAY[@]}"; do - #################### - # Get the versions # - #################### - if [[ "${LINTER}" == "arm-ttk" ]]; then - # Need specific command for ARM - mapfile -t GET_VERSION_CMD < <(grep -iE 'version' "${ARM_TTK_PSD1}" | xargs 2>&1) - elif [[ "${LINTER}" == "protolint" ]]; then - # Need specific command for Protolint - mapfile -t GET_VERSION_CMD < <(echo "--version not supported") - else - # Standard version command - mapfile -t GET_VERSION_CMD < <("${LINTER}" --version 2>&1) - fi + ########################################################## + # Go through the array of linters and print version info # + ########################################################## + for LINTER in "${LINTER_ARRAY[@]}"; do + #################### + # Get the versions # + #################### + if [[ ${LINTER} == "arm-ttk" ]]; then + # Need specific command for ARM + mapfile -t GET_VERSION_CMD < <(grep -iE 'version' "${ARM_TTK_PSD1}" | xargs 2>&1) + elif [[ ${LINTER} == "protolint" ]]; then + # Need specific command for Protolint + mapfile -t GET_VERSION_CMD < <(echo "--version not supported") + else + # Standard version command + mapfile -t GET_VERSION_CMD < <("${LINTER}" --version 2>&1) + fi - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then - warn "[${LINTER}]: Failed to get version info for:" - else - ########################## - # Print the version info # - ########################## - debug "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}" - fi - done + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then + warn "[${LINTER}]: Failed to get version info for:" + else + ########################## + # Print the version info # + ########################## + debug "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}" + fi + done - ######################### - # Print version footers # - ######################### - debug "---------------------------------------------" + ######################### + # Print version footers # + ######################### + debug "---------------------------------------------" } ################################################################################ #### Function GetLinterRules ################################################### GetLinterRules() { - # Need to validate the rules files exist + # Need to validate the rules files exist - ################ - # Pull in vars # - ################ - LANGUAGE_NAME="${1}" # Name of the language were looking for + ################ + # Pull in vars # + ################ + LANGUAGE_NAME="${1}" # Name of the language were looking for - ####################################################### - # Need to create the variables for the real variables # - ####################################################### - LANGUAGE_FILE_NAME="${LANGUAGE_NAME}_FILE_NAME" - LANGUAGE_LINTER_RULES="${LANGUAGE_NAME}_LINTER_RULES" + ####################################################### + # Need to create the variables for the real variables # + ####################################################### + LANGUAGE_FILE_NAME="${LANGUAGE_NAME}_FILE_NAME" + LANGUAGE_LINTER_RULES="${LANGUAGE_NAME}_LINTER_RULES" - ##################################### - # Validate we have the linter rules # - ##################################### - if [ -f "${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" ]; then - info "----------------------------------------------" - info "User provided file:[${!LANGUAGE_FILE_NAME}], setting rules file..." + ##################################### + # Validate we have the linter rules # + ##################################### + if [ -f "${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" ]; then + info "----------------------------------------------" + info "User provided file:[${!LANGUAGE_FILE_NAME}], setting rules file..." - ######################################## - # Update the path to the file location # - ######################################## - eval "${LANGUAGE_LINTER_RULES}=${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" - else - ######################################################## - # No user default provided, using the template default # - ######################################################## - debug " -> Codebase does NOT have file:[${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]" - fi + ######################################## + # Update the path to the file location # + ######################################## + eval "${LANGUAGE_LINTER_RULES}=${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" + else + ######################################################## + # No user default provided, using the template default # + ######################################################## + debug " -> Codebase does NOT have file:[${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]" + fi } ################################################################################ #### Function GetStandardRules ################################################# GetStandardRules() { - ################ - # Pull In Vars # - ################ - LINTER="${1}" # Type: javascript | typescript + ################ + # Pull In Vars # + ################ + LINTER="${1}" # Type: javascript | typescript - ######################################################################### - # Need to get the ENV vars from the linter rules to run in command line # - ######################################################################### - # Copy orig IFS to var - ORIG_IFS="${IFS}" - # Set the IFS to newline - IFS=$'\n' + ######################################################################### + # Need to get the ENV vars from the linter rules to run in command line # + ######################################################################### + # Copy orig IFS to var + ORIG_IFS="${IFS}" + # Set the IFS to newline + IFS=$'\n' - ######################################### - # Get list of all environment variables # - ######################################### - # Only env vars that are marked as true - GET_ENV_ARRAY=() - if [[ ${LINTER} == "javascript" ]]; then - mapfile -t GET_ENV_ARRAY < <(yq .env "${JAVASCRIPT_LINTER_RULES}" | grep true) - elif [[ ${LINTER} == "typescript" ]]; then - mapfile -t GET_ENV_ARRAY < <(yq .env "${TYPESCRIPT_LINTER_RULES}" | grep true) - fi - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # ERROR - error "Failed to gain list of ENV vars to load!" - fatal "[${GET_ENV_ARRAY[*]}]" - fi - - ########################## - # Set IFS back to normal # - ########################## - # Set IFS back to Orig - IFS="${ORIG_IFS}" - - ###################### - # Set the env string # - ###################### - ENV_STRING='' - - ############################# - # Pull out the envs to load # - ############################# - for ENV in "${GET_ENV_ARRAY[@]}"; do - ############################# - # remove spaces from return # - ############################# - ENV="$(echo -e "${ENV}" | tr -d '[:space:]')" - ################################ - # Get the env to add to string # - ################################ - ENV="$(echo "${ENV}" | cut -d'"' -f2)" - debug "ENV:[${ENV}]" - ENV_STRING+="--env ${ENV} " - done - - ######################################### - # Remove trailing and ending whitespace # - ######################################### - if [[ ${LINTER} == "javascript" ]]; then - JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" - elif [[ ${LINTER} == "typescript" ]]; then - TYPESCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" - fi -} -################################################################################ -#### Function DetectOpenAPIFile ################################################ -DetectOpenAPIFile() { - ################ - # Pull in vars # - ################ - FILE="${1}" - - ############################### - # Check the file for keywords # - ############################### - grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "${FILE}" > /dev/null - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -eq 0 ]; then - ######################## - # Found string in file # - ######################## - return 0 - else - ################### - # No string match # - ################### - return 1 - fi -} -################################################################################ -#### Function DetectARMFile #################################################### -DetectARMFile() { - ################ - # Pull in vars # - ################ - FILE="${1}" # Name of the file/path we are validating - - ############################### - # Check the file for keywords # - ############################### - grep -E 'schema.management.azure.com' "${FILE}" > /dev/null - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -eq 0 ]; then - ######################## - # Found string in file # - ######################## - return 0 - else - ################### - # No string match # - ################### - return 1 - fi -} -################################################################################ -#### Function DetectCloudFormationFile ######################################### -DetectCloudFormationFile() { - ################ - # Pull in Vars # - ################ - FILE="${1}" # File that we need to validate - - # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-formats.html - # AWSTemplateFormatVersion is optional - ####################################### - # Check if file has AWS Template info # - ####################################### - if grep -q 'AWSTemplateFormatVersion' "${FILE}" > /dev/null; then - # Found it - return 0 - fi - - ##################################### - # See if it contains AWS References # - ##################################### - if grep -q -E '(AWS|Alexa|Custom)::' "${FILE}" > /dev/null; then - # Found it - return 0 - fi - - ##################################################### - # No identifiers of a CLOUDFORMATION template found # - ##################################################### - return 1 -} -################################################################################ -#### Function DetectAWSStatesFIle ############################################## -DetectAWSStatesFIle() { - ################ - # Pull in Vars # - ################ - FILE="${1}" # File that we need to validate - - # https://states-language.net/spec.html#example - ############################### - # check if file has resources # - ############################### - if grep '"Resource": *"arn"*' "${FILE}"; then - # Found it - return 0 - fi - - ################################################# - # No identifiers of a AWS States Language found # - ################################################# - return 1 -} -################################################################################ -#### Function GetGitHubVars #################################################### -GetGitHubVars() { - ########## - # Prints # - ########## - info "--------------------------------------------" - info "Gathering GitHub information..." - - ############################### - # Get the Run test cases flag # - ############################### - if [ -z "${TEST_CASE_RUN}" ]; then - ################################## - # No flag passed, set to default # - ################################## - TEST_CASE_RUN="${DEFAULT_TEST_CASE_RUN}" - fi - - ############################### - # Convert string to lowercase # - ############################### - TEST_CASE_RUN="${TEST_CASE_RUN,,}" - - ########################## - # Get the run local flag # - ########################## - if [ -z "${RUN_LOCAL}" ]; then - ################################## - # No flag passed, set to default # - ################################## - RUN_LOCAL="${DEFAULT_RUN_LOCAL}" - fi - - ############################### - # Convert string to lowercase # - ############################### - RUN_LOCAL="${RUN_LOCAL,,}" - - ################################# - # Check if were running locally # - ################################# - if [[ ${RUN_LOCAL} != "false" ]]; then - ########################################## - # We are running locally for a debug run # - ########################################## - info "NOTE: ENV VAR [RUN_LOCAL] has been set to:[true]" - info "bypassing GitHub Actions variables..." - - ############################ - # Set the GITHUB_WORKSPACE # - ############################ - if [ -z "${GITHUB_WORKSPACE}" ]; then - GITHUB_WORKSPACE="${DEFAULT_WORKSPACE}" + ######################################### + # Get list of all environment variables # + ######################################### + # Only env vars that are marked as true + GET_ENV_ARRAY=() + if [[ ${LINTER} == "javascript" ]]; then + mapfile -t GET_ENV_ARRAY < <(yq .env "${JAVASCRIPT_LINTER_RULES}" | grep true) + elif [[ ${LINTER} == "typescript" ]]; then + mapfile -t GET_ENV_ARRAY < <(yq .env "${TYPESCRIPT_LINTER_RULES}" | grep true) fi - if [ ! -d "${GITHUB_WORKSPACE}" ]; then - fatal "Provided volume is not a directory!" - fi - - info "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]" - - # No need to touch or set the GITHUB_SHA - # No need to touch or set the GITHUB_EVENT_PATH - # No need to touch or set the GITHUB_ORG - # No need to touch or set the GITHUB_REPO - - ################################# - # Set the VALIDATE_ALL_CODEBASE # - ################################# - VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" - else - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_SHA}" ]; then - error "Failed to get [GITHUB_SHA]!" - fatal "[${GITHUB_SHA}]" - else - info "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]" - fi - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_WORKSPACE}" ]; then - error "Failed to get [GITHUB_WORKSPACE]!" - fatal "[${GITHUB_WORKSPACE}]" - else - info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]" - fi - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_EVENT_PATH}" ]; then - error "Failed to get [GITHUB_EVENT_PATH]!" - fatal "[${GITHUB_EVENT_PATH}]" - else - info "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}" - fi - - ################################################## - # Need to pull the GitHub Vars from the env file # - ################################################## - - ###################### - # Get the GitHub Org # - ###################### - GITHUB_ORG=$(jq -r '.repository.owner.login' < "${GITHUB_EVENT_PATH}") - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_ORG}" ]; then - error "Failed to get [GITHUB_ORG]!" - fatal "[${GITHUB_ORG}]" - else - info "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]" - fi - - ####################### - # Get the GitHub Repo # - ####################### - GITHUB_REPO=$(jq -r '.repository.name' < "${GITHUB_EVENT_PATH}") - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_REPO}" ]; then - error "Failed to get [GITHUB_REPO]!" - fatal "[${GITHUB_REPO}]" - else - info "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]" - fi - fi - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then - error "Failed to get [GITHUB_TOKEN]!" - error "[${GITHUB_TOKEN}]" - error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!" - - ################################################################################ - # Need to set MULTI_STATUS to false as we cant hit API endpoints without token # - ################################################################################ - MULTI_STATUS='false' - else - info "Successfully found:${F[W]}[GITHUB_TOKEN]" - fi - - ############################### - # Convert string to lowercase # - ############################### - MULTI_STATUS="${MULTI_STATUS,,}" - - ####################################################################### - # Check to see if the multi status is set, and we have a token to use # - ####################################################################### - if [ "${MULTI_STATUS}" == "true" ] && [ -n "${GITHUB_TOKEN}" ]; then - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_REPOSITORY}" ]; then - error "Failed to get [GITHUB_REPOSITORY]!" - fatal "[${GITHUB_REPOSITORY}]" - else - info "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]" - fi - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_RUN_ID}" ]; then - error "Failed to get [GITHUB_RUN_ID]!" - fatal "[${GITHUB_RUN_ID}]" - else - info "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]" - fi - fi -} -################################################################################ -#### Function ValidatePowershellModules ######################################## -function ValidatePowershellModules() { - VALIDATE_PSSA_MODULE=$(pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>&1) - # If module found, ensure Invoke-ScriptAnalyzer command is available - if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]]; then - VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1) - else - fatal "Failed to find module." - fi - - ######################################### - # validate we found the script analyzer # - ######################################### - if [[ ${VALIDATE_PSSA_CMD} != "Invoke-ScriptAnalyzer" ]]; then - fatal "Failed to find module." - fi - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Failed - error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!" - fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]" - else - # Success - debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system" - debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system" - fi -} -################################################################################ -#### Function CallStatusAPI #################################################### -CallStatusAPI() { - #################### - # Pull in the vars # - #################### - LANGUAGE="${1}" # langauge that was validated - STATUS="${2}" # success | error - SUCCESS_MSG='No errors were found in the linting process' - FAIL_MSG='Errors were detected, please view logs' - MESSAGE='' # Message to send to status API - - ###################################### - # Check the status to create message # - ###################################### - if [ "${STATUS}" == "success" ]; then - # Success - MESSAGE="${SUCCESS_MSG}" - else - # Failure - MESSAGE="${FAIL_MSG}" - fi - - ########################################################## - # Check to see if were enabled for multi Status mesaages # - ########################################################## - if [ "${MULTI_STATUS}" == "true" ]; then - ############################################## - # Call the status API to create status check # - ############################################## - SEND_STATUS_CMD=$(curl -f -s -X POST \ - --url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}" \ - -H 'accept: application/vnd.github.v3+json' \ - -H "authorization: Bearer ${GITHUB_TOKEN}" \ - -H 'content-type: application/json' \ - -d "{ \"state\": \"${STATUS}\", - \"target_url\": \"https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\", - \"description\": \"${MESSAGE}\", \"context\": \"--> Linted: ${LANGUAGE}\" - }" 2>&1) - ####################### # Load the error code # ####################### @@ -919,116 +495,543 @@ CallStatusAPI() { ############################## # Check the shell for errors # ############################## - if [ "${ERROR_CODE}" -ne 0 ]; then - # ERROR - info "ERROR! Failed to call GitHub Status API!" - info "ERROR:[${SEND_STATUS_CMD}]" - # Not going to fail the script on this yet... + if [ ${ERROR_CODE} -ne 0 ]; then + # ERROR + error "Failed to gain list of ENV vars to load!" + fatal "[${GET_ENV_ARRAY[*]}]" + fi + + ########################## + # Set IFS back to normal # + ########################## + # Set IFS back to Orig + IFS="${ORIG_IFS}" + + ###################### + # Set the env string # + ###################### + ENV_STRING='' + + ############################# + # Pull out the envs to load # + ############################# + for ENV in "${GET_ENV_ARRAY[@]}"; do + ############################# + # remove spaces from return # + ############################# + ENV="$(echo -e "${ENV}" | tr -d '[:space:]')" + ################################ + # Get the env to add to string # + ################################ + ENV="$(echo "${ENV}" | cut -d'"' -f2)" + debug "ENV:[${ENV}]" + ENV_STRING+="--env ${ENV} " + done + + ######################################### + # Remove trailing and ending whitespace # + ######################################### + if [[ ${LINTER} == "javascript" ]]; then + JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + elif [[ ${LINTER} == "typescript" ]]; then + TYPESCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + fi +} +################################################################################ +#### Function DetectOpenAPIFile ################################################ +DetectOpenAPIFile() { + ################ + # Pull in vars # + ################ + FILE="${1}" + + ############################### + # Check the file for keywords # + ############################### + grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "${FILE}" > /dev/null + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -eq 0 ]; then + ######################## + # Found string in file # + ######################## + return 0 + else + ################### + # No string match # + ################### + return 1 + fi +} +################################################################################ +#### Function DetectARMFile #################################################### +DetectARMFile() { + ################ + # Pull in vars # + ################ + FILE="${1}" # Name of the file/path we are validating + + ############################### + # Check the file for keywords # + ############################### + grep -E 'schema.management.azure.com' "${FILE}" > /dev/null + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -eq 0 ]; then + ######################## + # Found string in file # + ######################## + return 0 + else + ################### + # No string match # + ################### + return 1 + fi +} +################################################################################ +#### Function DetectCloudFormationFile ######################################### +DetectCloudFormationFile() { + ################ + # Pull in Vars # + ################ + FILE="${1}" # File that we need to validate + + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-formats.html + # AWSTemplateFormatVersion is optional + ####################################### + # Check if file has AWS Template info # + ####################################### + if grep -q 'AWSTemplateFormatVersion' "${FILE}" > /dev/null; then + # Found it + return 0 + fi + + ##################################### + # See if it contains AWS References # + ##################################### + if grep -q -E '(AWS|Alexa|Custom)::' "${FILE}" > /dev/null; then + # Found it + return 0 + fi + + ##################################################### + # No identifiers of a CLOUDFORMATION template found # + ##################################################### + return 1 +} +################################################################################ +#### Function DetectAWSStatesFIle ############################################## +DetectAWSStatesFIle() { + ################ + # Pull in Vars # + ################ + FILE="${1}" # File that we need to validate + + # https://states-language.net/spec.html#example + ############################### + # check if file has resources # + ############################### + if grep '"Resource": *"arn"*' "${FILE}"; then + # Found it + return 0 + fi + + ################################################# + # No identifiers of a AWS States Language found # + ################################################# + return 1 +} +################################################################################ +#### Function GetGitHubVars #################################################### +GetGitHubVars() { + ########## + # Prints # + ########## + info "--------------------------------------------" + info "Gathering GitHub information..." + + ############################### + # Get the Run test cases flag # + ############################### + if [ -z "${TEST_CASE_RUN}" ]; then + ################################## + # No flag passed, set to default # + ################################## + TEST_CASE_RUN="${DEFAULT_TEST_CASE_RUN}" + fi + + ############################### + # Convert string to lowercase # + ############################### + TEST_CASE_RUN="${TEST_CASE_RUN,,}" + + ########################## + # Get the run local flag # + ########################## + if [ -z "${RUN_LOCAL}" ]; then + ################################## + # No flag passed, set to default # + ################################## + RUN_LOCAL="${DEFAULT_RUN_LOCAL}" + fi + + ############################### + # Convert string to lowercase # + ############################### + RUN_LOCAL="${RUN_LOCAL,,}" + + ################################# + # Check if were running locally # + ################################# + if [[ ${RUN_LOCAL} != "false" ]]; then + ########################################## + # We are running locally for a debug run # + ########################################## + info "NOTE: ENV VAR [RUN_LOCAL] has been set to:[true]" + info "bypassing GitHub Actions variables..." + + ############################ + # Set the GITHUB_WORKSPACE # + ############################ + if [ -z "${GITHUB_WORKSPACE}" ]; then + GITHUB_WORKSPACE="${DEFAULT_WORKSPACE}" + fi + + if [ ! -d "${GITHUB_WORKSPACE}" ]; then + fatal "Provided volume is not a directory!" + fi + + info "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]" + + # No need to touch or set the GITHUB_SHA + # No need to touch or set the GITHUB_EVENT_PATH + # No need to touch or set the GITHUB_ORG + # No need to touch or set the GITHUB_REPO + + ################################# + # Set the VALIDATE_ALL_CODEBASE # + ################################# + VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" + else + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_SHA}" ]; then + error "Failed to get [GITHUB_SHA]!" + fatal "[${GITHUB_SHA}]" + else + info "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]" + fi + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_WORKSPACE}" ]; then + error "Failed to get [GITHUB_WORKSPACE]!" + fatal "[${GITHUB_WORKSPACE}]" + else + info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]" + fi + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_EVENT_PATH}" ]; then + error "Failed to get [GITHUB_EVENT_PATH]!" + fatal "[${GITHUB_EVENT_PATH}]" + else + info "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}" + fi + + ################################################## + # Need to pull the GitHub Vars from the env file # + ################################################## + + ###################### + # Get the GitHub Org # + ###################### + GITHUB_ORG=$(jq -r '.repository.owner.login' < "${GITHUB_EVENT_PATH}") + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_ORG}" ]; then + error "Failed to get [GITHUB_ORG]!" + fatal "[${GITHUB_ORG}]" + else + info "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]" + fi + + ####################### + # Get the GitHub Repo # + ####################### + GITHUB_REPO=$(jq -r '.repository.name' < "${GITHUB_EVENT_PATH}") + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_REPO}" ]; then + error "Failed to get [GITHUB_REPO]!" + fatal "[${GITHUB_REPO}]" + else + info "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]" + fi + fi + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then + error "Failed to get [GITHUB_TOKEN]!" + error "[${GITHUB_TOKEN}]" + error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!" + + ################################################################################ + # Need to set MULTI_STATUS to false as we cant hit API endpoints without token # + ################################################################################ + MULTI_STATUS='false' + else + info "Successfully found:${F[W]}[GITHUB_TOKEN]" + fi + + ############################### + # Convert string to lowercase # + ############################### + MULTI_STATUS="${MULTI_STATUS,,}" + + ####################################################################### + # Check to see if the multi status is set, and we have a token to use # + ####################################################################### + if [ "${MULTI_STATUS}" == "true" ] && [ -n "${GITHUB_TOKEN}" ]; then + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_REPOSITORY}" ]; then + error "Failed to get [GITHUB_REPOSITORY]!" + fatal "[${GITHUB_REPOSITORY}]" + else + info "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]" + fi + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_RUN_ID}" ]; then + error "Failed to get [GITHUB_RUN_ID]!" + fatal "[${GITHUB_RUN_ID}]" + else + info "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]" + fi + fi +} +################################################################################ +#### Function ValidatePowershellModules ######################################## +function ValidatePowershellModules() { + VALIDATE_PSSA_MODULE=$(pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>&1) + # If module found, ensure Invoke-ScriptAnalyzer command is available + if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]]; then + VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1) + else + fatal "Failed to find module." + fi + + ######################################### + # validate we found the script analyzer # + ######################################### + if [[ ${VALIDATE_PSSA_CMD} != "Invoke-ScriptAnalyzer" ]]; then + fatal "Failed to find module." + fi + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Failed + error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!" + fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]" + else + # Success + debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system" + debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system" + fi +} +################################################################################ +#### Function CallStatusAPI #################################################### +CallStatusAPI() { + #################### + # Pull in the vars # + #################### + LANGUAGE="${1}" # langauge that was validated + STATUS="${2}" # success | error + SUCCESS_MSG='No errors were found in the linting process' + FAIL_MSG='Errors were detected, please view logs' + MESSAGE='' # Message to send to status API + + ###################################### + # Check the status to create message # + ###################################### + if [ "${STATUS}" == "success" ]; then + # Success + MESSAGE="${SUCCESS_MSG}" + else + # Failure + MESSAGE="${FAIL_MSG}" + fi + + ########################################################## + # Check to see if were enabled for multi Status mesaages # + ########################################################## + if [ "${MULTI_STATUS}" == "true" ]; then + ############################################## + # Call the status API to create status check # + ############################################## + SEND_STATUS_CMD=$(curl -f -s -X POST \ + --url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}" \ + -H 'accept: application/vnd.github.v3+json' \ + -H "authorization: Bearer ${GITHUB_TOKEN}" \ + -H 'content-type: application/json' \ + -d "{ \"state\": \"${STATUS}\", + \"target_url\": \"https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\", + \"description\": \"${MESSAGE}\", \"context\": \"--> Linted: ${LANGUAGE}\" + }" 2>&1) + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ "${ERROR_CODE}" -ne 0 ]; then + # ERROR + info "ERROR! Failed to call GitHub Status API!" + info "ERROR:[${SEND_STATUS_CMD}]" + # Not going to fail the script on this yet... + fi fi - fi } ################################################################################ #### Function Reports ########################################################## Reports() { - info "----------------------------------------------" - info "----------------------------------------------" - info "Generated reports:" - info "----------------------------------------------" - info "----------------------------------------------" + info "----------------------------------------------" + info "----------------------------------------------" + info "Generated reports:" + info "----------------------------------------------" + info "----------------------------------------------" - ################################### - # Prints output report if enabled # - ################################### - if [ -z "${FORMAT_REPORT}" ] ; then - info "Reports generated in folder ${REPORT_OUTPUT_FOLDER}" - fi + ################################### + # Prints output report if enabled # + ################################### + if [ -z "${FORMAT_REPORT}" ]; then + info "Reports generated in folder ${REPORT_OUTPUT_FOLDER}" + fi - ################################ - # Prints for warnings if found # - ################################ - for TEST in "${WARNING_ARRAY_TEST[@]}"; do - warn "Expected file to compare with was not found for ${TEST}" - done + ################################ + # Prints for warnings if found # + ################################ + for TEST in "${WARNING_ARRAY_TEST[@]}"; do + warn "Expected file to compare with was not found for ${TEST}" + done } ################################################################################ #### Function Footer ########################################################### Footer() { - info "----------------------------------------------" - info "----------------------------------------------" - info "The script has completed" - info "----------------------------------------------" - info "----------------------------------------------" + info "----------------------------------------------" + info "----------------------------------------------" + info "The script has completed" + info "----------------------------------------------" + info "----------------------------------------------" - #################################################### - # Need to clean up the lanuage array of duplicates # - #################################################### - mapfile -t UNIQUE_LINTED_ARRAY < <(echo "${LINTED_LANGUAGES_ARRAY[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ') + #################################################### + # Need to clean up the lanuage array of duplicates # + #################################################### + mapfile -t UNIQUE_LINTED_ARRAY < <(echo "${LINTED_LANGUAGES_ARRAY[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ') - ############################## - # Prints for errors if found # - ############################## - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - ########################### - # Build the error counter # - ########################### - ERROR_COUNTER="ERRORS_FOUND_${LANGUAGE}" + ############################## + # 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 - # We found errors in the language - ################### - # Print the goods # - ################### - error "ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]" + ################## + # Print if not 0 # + ################## + if [[ ${!ERROR_COUNTER} -ne 0 ]]; then + # We found errors in the language + ################### + # Print the goods # + ################### + error "ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]" - ######################################### - # Create status API for Failed language # - ######################################### - CallStatusAPI "${LANGUAGE}" "error" - ###################################### - # Check if we validated the langauge # - ###################################### - elif [[ "${!ERROR_COUNTER}" -eq 0 ]] && [[ "${UNIQUE_LINTED_ARRAY[*]}" =~ ${LANGUAGE} ]]; then - # No errors found when linting the language - CallStatusAPI "${LANGUAGE}" "success" + ######################################### + # Create status API for Failed language # + ######################################### + CallStatusAPI "${LANGUAGE}" "error" + ###################################### + # Check if we validated the langauge # + ###################################### + elif [[ ${!ERROR_COUNTER} -eq 0 ]] && [[ ${UNIQUE_LINTED_ARRAY[*]} =~ ${LANGUAGE} ]]; then + # No errors found when linting the language + CallStatusAPI "${LANGUAGE}" "success" + fi + done + + ################################## + # Exit with 0 if errors disabled # + ################################## + if [ "${DISABLE_ERRORS}" == "true" ]; then + warn "Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]" + exit 0 fi - done - ################################## - # Exit with 0 if errors disabled # - ################################## - if [ "${DISABLE_ERRORS}" == "true" ]; then - warn "Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]" + ############################### + # Exit with 1 if errors found # + ############################### + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + ERRORS_FOUND_LANGUAGE="ERRORS_FOUND_${LANGUAGE}" + # Check if error was found + if [[ ${!ERRORS_FOUND_LANGUAGE} -ne 0 ]]; then + # Failed exit + fatal "Exiting with errors found!" + fi + done + + ######################## + # Footer prints Exit 0 # + ######################## + notice "All file(s) linted successfully with no errors detected" + info "----------------------------------------------" + # Successful exit exit 0 - fi - - ############################### - # Exit with 1 if errors found # - ############################### - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - ERRORS_FOUND_LANGUAGE="ERRORS_FOUND_${LANGUAGE}" - # Check if error was found - if [[ "${!ERRORS_FOUND_LANGUAGE}" -ne 0 ]]; then - # Failed exit - fatal "Exiting with errors found!" - fi - done - - ######################## - # Footer prints Exit 0 # - ######################## - notice "All file(s) linted successfully with no errors detected" - info "----------------------------------------------" - # Successful exit - exit 0 } - ################################################################################ #### Function Cleanup ########################################################## cleanup() { @@ -1054,10 +1057,10 @@ Header # check flag for validating the report folder does not exist # ############################################################## if [ -n "${OUTPUT_FORMAT}" ]; then - if [ -d "${REPORT_OUTPUT_FOLDER}" ] ; then - error "ERROR! Found ${REPORT_OUTPUT_FOLDER}" - fatal "Please remove the folder and try again." - fi + if [ -d "${REPORT_OUTPUT_FOLDER}" ]; then + error "ERROR! Found ${REPORT_OUTPUT_FOLDER}" + fatal "Please remove the folder and try again." + fi fi ####################### @@ -1126,560 +1129,560 @@ GetLinterVersions ########################################### if [[ ${TEST_CASE_RUN} != "false" ]]; then - ############################################# - # Set the multi status to off for test runs # - ############################################# - MULTI_STATUS='false' + ############################################# + # Set the multi status to off for test runs # + ############################################# + MULTI_STATUS='false' - ########################### - # Run only the test cases # - ########################### - # Code will exit from inside this loop - RunTestCases + ########################### + # Run only the test cases # + ########################### + # Code will exit from inside this loop + RunTestCases fi ############################################# # check flag for validation of all codebase # ############################################# if [ "${VALIDATE_ALL_CODEBASE}" == "false" ]; then - ######################################## - # Get list of files changed if env set # - ######################################## - BuildFileList + ######################################## + # Get list of files changed if env set # + ######################################## + BuildFileList fi ################### # ANSIBLE LINTING # ################### if [ "${VALIDATE_ANSIBLE}" == "true" ]; then - ########################## - # Lint the Ansible files # - ########################## - # Due to the nature of how we want to validate Ansible, we cannot use the - # standard loop, since it looks for an ansible folder, excludes certain - # files, and looks for additional changes, it should be an outlier - LintAnsibleFiles "${ANSIBLE_LINTER_RULES}" # Passing rules but not needed, dont want to exclude unused var + ########################## + # Lint the Ansible files # + ########################## + # Due to the nature of how we want to validate Ansible, we cannot use the + # standard loop, since it looks for an ansible folder, excludes certain + # files, and looks for additional changes, it should be an outlier + LintAnsibleFiles "${ANSIBLE_LINTER_RULES}" # Passing rules but not needed, dont want to exclude unused var fi ######################## # ARM Template LINTING # ######################## if [ "${VALIDATE_ARM}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every json file is an ARM file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' + # If we are validating all codebase we need to build file list because not every json file is an ARM file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectARMFile "${FILE}"; then - FILE_ARRAY_ARM+=("${FILE}") - fi - done + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectARMFile "${FILE}"; then + FILE_ARRAY_ARM+=("${FILE}") + fi + done - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi - ############################### - # Lint the ARM Template files # - ############################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" "disabledfileext" "${FILE_ARRAY_ARM[@]}" + ############################### + # Lint the ARM Template files # + ############################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" "disabledfileext" "${FILE_ARRAY_ARM[@]}" fi ################ # BASH LINTING # ################ if [ "${VALIDATE_BASH}" == "true" ]; then - ####################### - # Lint the bash files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "BASH" "shellcheck" "shellcheck --color" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" + ####################### + # Lint the bash files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "BASH" "shellcheck" "shellcheck --color" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" fi ########################## # CLOUDFORMATION LINTING # ########################## if [ "${VALIDATE_CLOUDFORMATION}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every yml/json file is an CLOUDFORMATION file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' + # If we are validating all codebase we need to build file list because not every yml/json file is an CLOUDFORMATION file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectCloudFormationFile "${FILE}"; then - FILE_ARRAY_CLOUDFORMATION+=("${FILE}") - fi - done + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectCloudFormationFile "${FILE}"; then + FILE_ARRAY_CLOUDFORMATION+=("${FILE}") + fi + done - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi - ################################# - # Lint the CloudFormation files # - ################################# - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "CLOUDFORMATION" "cfn-lint" "cfn-lint --config-file ${CLOUDFORMATION_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_CLOUDFORMATION[@]}" + ################################# + # Lint the CloudFormation files # + ################################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "CLOUDFORMATION" "cfn-lint" "cfn-lint --config-file ${CLOUDFORMATION_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_CLOUDFORMATION[@]}" fi ################### # CLOJURE LINTING # ################### if [ "${VALIDATE_CLOJURE}" == "true" ]; then - ################################# - # Get Clojure standard rules # - ################################# - GetStandardRules "clj-kondo" - ######################### - # Lint the Clojure files # - ######################### - LintCodebase "CLOJURE" "clj-kondo" "clj-kondo --config ${CLOJURE_LINTER_RULES} --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$" "${FILE_ARRAY_CLOJURE[@]}" + ################################# + # Get Clojure standard rules # + ################################# + GetStandardRules "clj-kondo" + ######################### + # Lint the Clojure files # + ######################### + LintCodebase "CLOJURE" "clj-kondo" "clj-kondo --config ${CLOJURE_LINTER_RULES} --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$" "${FILE_ARRAY_CLOJURE[@]}" fi ######################## # COFFEESCRIPT LINTING # ######################## if [ "${VALIDATE_COFFEE}" == "true" ]; then - ######################### - # Lint the coffee files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f ${COFFEESCRIPT_LINTER_RULES}" ".*\.\(coffee\)\$" "${FILE_ARRAY_COFFEESCRIPT[@]}" + ######################### + # Lint the coffee files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f ${COFFEESCRIPT_LINTER_RULES}" ".*\.\(coffee\)\$" "${FILE_ARRAY_COFFEESCRIPT[@]}" fi ############### # CSS LINTING # ############### if [ "${VALIDATE_CSS}" == "true" ]; then - ################################# - # Get CSS standard rules # - ################################# - GetStandardRules "stylelint" - ############################# - # Lint the CSS files # - ############################# - LintCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}" + ################################# + # Get CSS standard rules # + ################################# + GetStandardRules "stylelint" + ############################# + # Lint the CSS files # + ############################# + LintCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}" fi ################ # DART LINTING # ################ if [ "${VALIDATE_DART}" == "true" ]; then - ####################### - # Lint the Dart files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "${FILE_ARRAY_DART[@]}" + ####################### + # Lint the Dart files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "${FILE_ARRAY_DART[@]}" fi ################## # DOCKER LINTING # ################## if [ "${VALIDATE_DOCKER}" == "true" ]; then - ######################### - # Lint the docker files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - # NOTE: dockerfilelint's "-c" option expects the folder *containing* the DOCKER_LINTER_RULES file - LintCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c $(dirname ${DOCKER_LINTER_RULES})" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}" + ######################### + # Lint the docker files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + # NOTE: dockerfilelint's "-c" option expects the folder *containing* the DOCKER_LINTER_RULES file + LintCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c $(dirname ${DOCKER_LINTER_RULES})" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}" fi ######################## # EDITORCONFIG LINTING # ######################## if [ "${VALIDATE_EDITORCONFIG}" == "true" ]; then - #################################### - # Lint the files with editorconfig # - #################################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" "^.*$" "${FILE_ARRAY_ENV[@]}" + #################################### + # Lint the files with editorconfig # + #################################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" "^.*$" "${FILE_ARRAY_ENV[@]}" fi ############### # ENV LINTING # ############### if [ "${VALIDATE_ENV}" == "true" ]; then - ####################### - # Lint the env files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$" "${FILE_ARRAY_ENV[@]}" + ####################### + # Lint the env files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$" "${FILE_ARRAY_ENV[@]}" fi ################## # GOLANG LINTING # ################## if [ "${VALIDATE_GO}" == "true" ]; then - ######################### - # Lint the golang files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "${FILE_ARRAY_GO[@]}" + ######################### + # Lint the golang files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "${FILE_ARRAY_GO[@]}" fi ################## # GROOVY LINTING # ################## if [ "$VALIDATE_GROOVY" == "true" ]; then - ######################### - # Lint the groovy files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}" + ######################### + # Lint the groovy files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}" fi ################ # HTML LINTING # ################ if [ "${VALIDATE_HTML}" == "true" ]; then - ########################### - # Get HTML standard rules # - ########################### - GetStandardRules "htmlhint" - ####################### - # Lint the HTML files # - ####################### - LintCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "${FILE_ARRAY_HTML[@]}" + ########################### + # Get HTML standard rules # + ########################### + GetStandardRules "htmlhint" + ####################### + # Lint the HTML files # + ####################### + LintCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "${FILE_ARRAY_HTML[@]}" fi ###################### # JAVASCRIPT LINTING # ###################### if [ "${VALIDATE_JAVASCRIPT_ES}" == "true" ]; then - ############################# - # Lint the Javascript files # - ############################# - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_ES[@]}" + ############################# + # Lint the Javascript files # + ############################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_ES[@]}" fi ###################### # JAVASCRIPT LINTING # ###################### if [ "${VALIDATE_JAVASCRIPT_STANDARD}" == "true" ]; then - ################################# - # Get Javascript standard rules # - ################################# - GetStandardRules "javascript" - ############################# - # Lint the Javascript files # - ############################# - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_STANDARD[@]}" + ################################# + # Get Javascript standard rules # + ################################# + GetStandardRules "javascript" + ############################# + # Lint the Javascript files # + ############################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_STANDARD[@]}" fi ################ # JSON LINTING # ################ if [ "${VALIDATE_JSON}" == "true" ]; then - ####################### - # Lint the json files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "${FILE_ARRAY_JSON[@]}" + ####################### + # Lint the json files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "${FILE_ARRAY_JSON[@]}" fi ############### # JSX LINTING # ############### if [ "${VALIDATE_JSX}" == "true" ]; then - ###################### - # Lint the JSX files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "JSX" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(jsx\)\$" "${FILE_ARRAY_JSX[@]}" + ###################### + # Lint the JSX files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JSX" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(jsx\)\$" "${FILE_ARRAY_JSX[@]}" fi ################## # KOTLIN LINTING # ################## if [ "${VALIDATE_KOTLIN}" == "true" ]; then - ####################### - # Lint the Kotlin files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}" + ####################### + # Lint the Kotlin files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}" fi ############### # LUA LINTING # ############### if [ "${VALIDATE_LUA}" == "true" ]; then - ###################### - # Lint the Lua files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "LUA" "lua" "luacheck --config ${LUA_LINTER_RULES}" ".*\.\(lua\)\$" "${FILE_ARRAY_LUA[@]}" + ###################### + # Lint the Lua files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "LUA" "lua" "luacheck --config ${LUA_LINTER_RULES}" ".*\.\(lua\)\$" "${FILE_ARRAY_LUA[@]}" fi #################### # MARKDOWN LINTING # #################### if [ "${VALIDATE_MARKDOWN}" == "true" ]; then - ########################### - # Lint the Markdown Files # - ########################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "${FILE_ARRAY_MARKDOWN[@]}" + ########################### + # Lint the Markdown Files # + ########################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "${FILE_ARRAY_MARKDOWN[@]}" fi ################### # OPENAPI LINTING # ################### if [ "${VALIDATE_OPENAPI}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' + # If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectOpenAPIFile "${FILE}"; then - FILE_ARRAY_OPENAPI+=("${FILE}") - fi - done + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectOpenAPIFile "${FILE}"; then + FILE_ARRAY_OPENAPI+=("${FILE}") + fi + done - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi - ########################## - # Lint the OpenAPI files # - ########################## - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_OPENAPI[@]}" + ########################## + # Lint the OpenAPI files # + ########################## + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_OPENAPI[@]}" fi ################ # PERL LINTING # ################ if [ "${VALIDATE_PERL}" == "true" ]; then - ####################### - # Lint the perl files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}" + ####################### + # Lint the perl files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}" fi ################ # PHP LINTING # ################ if [ "${VALIDATE_PHP}" == "true" ]; then - ####################### - # Lint the PHP files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "${FILE_ARRAY_PHP[@]}" + ####################### + # Lint the PHP files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "${FILE_ARRAY_PHP[@]}" fi ################### # PHPStan LINTING # ################### if [ "${VALIDATE_PHP_PHPSTAN}" == "true" ]; then - ####################### - # Lint the PHP files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PHP_PHPSTAN" "phpstan" "phpstan analyse --no-progress --no-ansi -c ${PHPSTAN_LINTER_RULES}" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PHPSTAN[@]}" + ####################### + # Lint the PHP files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PHP_PHPSTAN" "phpstan" "phpstan analyse --no-progress --no-ansi -c ${PHPSTAN_LINTER_RULES}" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PHPSTAN[@]}" fi ###################### # POWERSHELL LINTING # ###################### if [ "${VALIDATE_POWERSHELL}" == "true" ]; then - ############################################################### - # For POWERSHELL, ensure PSScriptAnalyzer module is available # - ############################################################### - ValidatePowershellModules + ############################################################### + # For POWERSHELL, ensure PSScriptAnalyzer module is available # + ############################################################### + ValidatePowershellModules - ############################# - # Lint the powershell files # - ############################# - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" + ############################# + # Lint the powershell files # + ############################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi #################### # PROTOBUF LINTING # #################### if [ "${VALIDATE_PROTOBUF}" == "true" ]; then - ####################### - # Lint the Protocol Buffers files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "${FILE_ARRAY_PROTOBUF[@]}" + ####################### + # Lint the Protocol Buffers files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "${FILE_ARRAY_PROTOBUF[@]}" fi ################## # PYTHON LINTING # ################## if [ "${VALIDATE_PYTHON_PYLINT}" == "true" ]; then - ######################### - # Lint the python files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_PYLINT[@]}" + ######################### + # Lint the python files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_PYLINT[@]}" fi ################## # PYTHON LINTING # ################## if [ "${VALIDATE_PYTHON_FLAKE8}" == "true" ]; then - ######################### - # Lint the python files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config=${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_FLAKE8[@]}" + ######################### + # Lint the python files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config=${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_FLAKE8[@]}" fi ################ # RAKU LINTING # ################ if [ "${VALIDATE_RAKU}" == "true" ]; then - ####################### - # Lint the raku files # - ####################### + ####################### + # Lint the raku files # + ####################### info "${GITHUB_WORKSPACE}/META6.json" if [ -e "${GITHUB_WORKSPACE}/META6.json" ]; then - cd "${GITHUB_WORKSPACE}" && zef install --deps-only --/test . + cd "${GITHUB_WORKSPACE}" && zef install --deps-only --/test . fi - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "RAKU" "raku" "raku -I ${GITHUB_WORKSPACE}/lib -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "${FILE_ARRAY_RAKU[@]}" + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "RAKU" "raku" "raku -I ${GITHUB_WORKSPACE}/lib -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "${FILE_ARRAY_RAKU[@]}" fi ################ # RUBY LINTING # ################ if [ "${VALIDATE_RUBY}" == "true" ]; then - ####################### - # Lint the ruby files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES} --force-exclusion" ".*\.\(rb\)\$" "${FILE_ARRAY_RUBY[@]}" + ####################### + # Lint the ruby files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES} --force-exclusion" ".*\.\(rb\)\$" "${FILE_ARRAY_RUBY[@]}" fi ###################### # AWS STATES LINTING # ###################### if [ "${VALIDATE_STATES}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every json file is an aws states file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' + # If we are validating all codebase we need to build file list because not every json file is an aws states file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectAWSStatesFIle "${FILE}"; then - FILE_ARRAY_STATES+=("${FILE}") - fi - done + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectAWSStatesFIle "${FILE}"; then + FILE_ARRAY_STATES+=("${FILE}") + fi + done - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi - ######################### - # Lint the STATES files # - ######################### - LintCodebase "STATES" "asl-validator" "asl-validator --json-path" "disabledfileext" "${FILE_ARRAY_STATES[@]}" + ######################### + # Lint the STATES files # + ######################### + LintCodebase "STATES" "asl-validator" "asl-validator --json-path" "disabledfileext" "${FILE_ARRAY_STATES[@]}" fi ##################### # TERRAFORM LINTING # ##################### if [ "${VALIDATE_TERRAFORM}" == "true" ]; then - ############################ - # Lint the Terraform files # - ############################ - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM[@]}" + ############################ + # Lint the Terraform files # + ############################ + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM[@]}" fi ############################### # TERRAFORM TERRASCAN LINTING # ############################### if [ "${VALIDATE_TERRAFORM_TERRASCAN}" == "true" ]; then - ############################ - # Lint the Terraform files # - ############################ - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM_TERRASCAN[@]}" + ############################ + # Lint the Terraform files # + ############################ + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM_TERRASCAN[@]}" fi ############### # TSX LINTING # ############### if [ "${VALIDATE_TSX}" == "true" ]; then - ###################### - # Lint the TSX files # - ###################### - LintCodebase "TSX" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(tsx\)\$" "${FILE_ARRAY_TSX[@]}" + ###################### + # Lint the TSX files # + ###################### + LintCodebase "TSX" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(tsx\)\$" "${FILE_ARRAY_TSX[@]}" fi ###################### # TYPESCRIPT LINTING # ###################### if [ "${VALIDATE_TYPESCRIPT_ES}" == "true" ]; then - ############################# - # Lint the Typescript files # - ############################# - LintCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_ES[@]}" + ############################# + # Lint the Typescript files # + ############################# + LintCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_ES[@]}" fi ###################### # TYPESCRIPT LINTING # ###################### if [ "${VALIDATE_TYPESCRIPT_STANDARD}" == "true" ]; then - ################################# - # Get Typescript standard rules # - ################################# - GetStandardRules "typescript" - ############################# - # Lint the Typescript files # - ############################# - LintCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_STANDARD[@]}" + ################################# + # Get Typescript standard rules # + ################################# + GetStandardRules "typescript" + ############################# + # Lint the Typescript files # + ############################# + LintCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_STANDARD[@]}" fi ############### # XML LINTING # ############### if [ "${VALIDATE_XML}" == "true" ]; then - ###################### - # Lint the XML Files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "${FILE_ARRAY_XML[@]}" + ###################### + # Lint the XML Files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "${FILE_ARRAY_XML[@]}" fi ############### # YAML LINTING # ############### if [ "${VALIDATE_YAML}" == "true" ]; then - ###################### - # Lint the Yml Files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "${FILE_ARRAY_YAML[@]}" + ###################### + # Lint the Yml Files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "${FILE_ARRAY_YAML[@]}" fi ########### diff --git a/lib/log.sh b/lib/log.sh index fce6b072..f6bd73a2 100644 --- a/lib/log.sh +++ b/lib/log.sh @@ -1,24 +1,24 @@ #!/usr/bin/env bash declare -Agr B=( - [B]=$(echo -e "\e[44m") - [C]=$(echo -e "\e[46m") - [G]=$(echo -e "\e[42m") - [K]=$(echo -e "\e[40m") - [M]=$(echo -e "\e[45m") - [R]=$(echo -e "\e[41m") - [W]=$(echo -e "\e[47m") - [Y]=$(echo -e "\e[43m") + [B]=$(echo -e "\e[44m") + [C]=$(echo -e "\e[46m") + [G]=$(echo -e "\e[42m") + [K]=$(echo -e "\e[40m") + [M]=$(echo -e "\e[45m") + [R]=$(echo -e "\e[41m") + [W]=$(echo -e "\e[47m") + [Y]=$(echo -e "\e[43m") ) declare -Agr F=( - [B]=$(echo -e "\e[0;34m") - [C]=$(echo -e "\e[0;36m") - [G]=$(echo -e "\e[0;32m") - [K]=$(echo -e "\e[0;30m") - [M]=$(echo -e "\e[0;35m") - [R]=$(echo -e "\e[0;31m") - [W]=$(echo -e "\e[0;37m") - [Y]=$(echo -e "\e[0;33m") + [B]=$(echo -e "\e[0;34m") + [C]=$(echo -e "\e[0;36m") + [G]=$(echo -e "\e[0;32m") + [K]=$(echo -e "\e[0;30m") + [M]=$(echo -e "\e[0;35m") + [R]=$(echo -e "\e[0;31m") + [W]=$(echo -e "\e[0;37m") + [Y]=$(echo -e "\e[0;33m") ) readonly NC=$(echo -e "\e[0m") diff --git a/lib/termColors.sh b/lib/termColors.sh index 8f22a26c..ce3e0e66 100755 --- a/lib/termColors.sh +++ b/lib/termColors.sh @@ -1,24 +1,24 @@ #!/usr/bin/env bash declare -Agr B=( - [B]=$(echo -e "\e[44m") - [C]=$(echo -e "\e[46m") - [G]=$(echo -e "\e[42m") - [K]=$(echo -e "\e[40m") - [M]=$(echo -e "\e[45m") - [R]=$(echo -e "\e[41m") - [W]=$(echo -e "\e[47m") - [Y]=$(echo -e "\e[43m") + [B]=$(echo -e "\e[44m") + [C]=$(echo -e "\e[46m") + [G]=$(echo -e "\e[42m") + [K]=$(echo -e "\e[40m") + [M]=$(echo -e "\e[45m") + [R]=$(echo -e "\e[41m") + [W]=$(echo -e "\e[47m") + [Y]=$(echo -e "\e[43m") ) declare -Agr F=( - [B]=$(echo -e "\e[0;34m") - [C]=$(echo -e "\e[0;36m") - [G]=$(echo -e "\e[0;32m") - [K]=$(echo -e "\e[0;30m") - [M]=$(echo -e "\e[0;35m") - [R]=$(echo -e "\e[0;31m") - [W]=$(echo -e "\e[0;37m") - [Y]=$(echo -e "\e[0;33m") + [B]=$(echo -e "\e[0;34m") + [C]=$(echo -e "\e[0;36m") + [G]=$(echo -e "\e[0;32m") + [K]=$(echo -e "\e[0;30m") + [M]=$(echo -e "\e[0;35m") + [R]=$(echo -e "\e[0;31m") + [W]=$(echo -e "\e[0;37m") + [Y]=$(echo -e "\e[0;33m") ) readonly NC=$(echo -e "\e[0m") diff --git a/lib/validation.sh b/lib/validation.sh index 6e4105b0..fcbcd4ac 100755 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -10,175 +10,175 @@ ################################################################################ #### Function GetValidationInfo ################################################ function GetValidationInfo() { - ############################################ - # Print headers for user provided env vars # - ############################################ - info "--------------------------------------------" - info "Gathering user validation information..." + ############################################ + # Print headers for user provided env vars # + ############################################ + info "--------------------------------------------" + info "Gathering user validation information..." + + ########################################### + # Skip validation if were running locally # + ########################################### + if [[ ${RUN_LOCAL} != "true" ]]; then + ############################### + # Convert string to lowercase # + ############################### + VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE,,}" + ###################################### + # Validate we should check all files # + ###################################### + if [[ ${VALIDATE_ALL_CODEBASE} != "false" ]]; then + # Set to true + VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" + info "- Validating ALL files in code base..." + else + # Its false + info "- Only validating [new], or [edited] files in code base..." + fi + fi + + ###################### + # Create Print Array # + ###################### + PRINT_ARRAY=() + + ################################ + # Convert strings to lowercase # + ################################ + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" + # Set the value of the var to lowercase + eval "${VALIDATE_LANGUAGE}=${!VALIDATE_LANGUAGE,,}" + done + + ################################################ + # Determine if any linters were explicitly set # + ################################################ + ANY_SET="false" + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" + # Check to see if the variable was set + if [ -n "${!VALIDATE_LANGUAGE}" ]; then + # It was set, need to set flag + ANY_SET="true" + fi + done + + ################################################### + # Validate if we should check individual lanuages # + ################################################### + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" + # Check if ANY_SET was set + if [[ ${ANY_SET} == "true" ]]; then + # Check to see if the variable was set + if [ -z "${!VALIDATE_LANGUAGE}" ]; then + # Flag was not set, default to false + eval "${VALIDATE_LANGUAGE}='false'" + fi + else + # No linter flags were set - default all to true + eval "${VALIDATE_LANGUAGE}='true'" + fi + done + + ####################################### + # Print which linters we are enabling # + ####################################### + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" + if [[ ${!VALIDATE_LANGUAGE} == "true" ]]; then + # We need to validate + PRINT_ARRAY+=("- Validating [$LANGUAGE] files in code base...") + else + # We are skipping the language + PRINT_ARRAY+=("- Excluding [$LANGUAGE] files in code base...") + fi + done + + ############################## + # Validate Ansible Directory # + ############################## + if [ -z "${ANSIBLE_DIRECTORY}" ]; then + # No Value, need to default + ANSIBLE_DIRECTORY="${DEFAULT_ANSIBLE_DIRECTORY}" + else + # Check if first char is '/' + if [[ ${ANSIBLE_DIRECTORY:0:1} == "/" ]]; then + # Remove first char + ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY:1}" + fi + # Need to give it full path + TEMP_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/${ANSIBLE_DIRECTORY}" + # Set the value + ANSIBLE_DIRECTORY="${TEMP_ANSIBLE_DIRECTORY}" + fi + + ############################### + # Get the disable errors flag # + ############################### + if [ -z "${DISABLE_ERRORS}" ]; then + ################################## + # No flag passed, set to default # + ################################## + DISABLE_ERRORS="${DEFAULT_DISABLE_ERRORS}" + fi - ########################################### - # Skip validation if were running locally # - ########################################### - if [[ ${RUN_LOCAL} != "true" ]]; then ############################### # Convert string to lowercase # ############################### - VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE,,}" - ###################################### - # Validate we should check all files # - ###################################### - if [[ ${VALIDATE_ALL_CODEBASE} != "false" ]]; then - # Set to true - VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" - info "- Validating ALL files in code base..." - else - # Its false - info "- Only validating [new], or [edited] files in code base..." + DISABLE_ERRORS="${DISABLE_ERRORS,,}" + + ############################ + # Set to false if not true # + ############################ + if [ "${DISABLE_ERRORS}" != "true" ]; then + DISABLE_ERRORS="false" fi - fi - ###################### - # Create Print Array # - ###################### - PRINT_ARRAY=() - - ################################ - # Convert strings to lowercase # - ################################ - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" - # Set the value of the var to lowercase - eval "${VALIDATE_LANGUAGE}=${!VALIDATE_LANGUAGE,,}" - done - - ################################################ - # Determine if any linters were explicitly set # - ################################################ - ANY_SET="false" - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" - # Check to see if the variable was set - if [ -n "${!VALIDATE_LANGUAGE}" ]; then - # It was set, need to set flag - ANY_SET="true" + ############################ + # Get the run verbose flag # + ############################ + if [ -z "${ACTIONS_RUNNER_DEBUG}" ]; then + ################################## + # No flag passed, set to default # + ################################## + ACTIONS_RUNNER_DEBUG="${DEFAULT_ACTIONS_RUNNER_DEBUG}" fi - done - ################################################### - # Validate if we should check individual lanuages # - ################################################### - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" - # Check if ANY_SET was set - if [[ ${ANY_SET} == "true" ]]; then - # Check to see if the variable was set - if [ -z "${!VALIDATE_LANGUAGE}" ]; then - # Flag was not set, default to false - eval "${VALIDATE_LANGUAGE}='false'" - fi - else - # No linter flags were set - default all to true - eval "${VALIDATE_LANGUAGE}='true'" + ############################### + # Convert string to lowercase # + ############################### + ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG,,}" + + ############################ + # Set to true if not false # + ############################ + if [ "${ACTIONS_RUNNER_DEBUG}" != "false" ]; then + ACTIONS_RUNNER_DEBUG="true" fi - done - ####################################### - # Print which linters we are enabling # - ####################################### - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" - if [[ ${!VALIDATE_LANGUAGE} == "true" ]]; then - # We need to validate - PRINT_ARRAY+=("- Validating [$LANGUAGE] files in code base...") - else - # We are skipping the language - PRINT_ARRAY+=("- Excluding [$LANGUAGE] files in code base...") - fi - done + ########################### + # Print the validate info # + ########################### + for LINE in "${PRINT_ARRAY[@]}"; do + debug "${LINE}" + done - ############################## - # Validate Ansible Directory # - ############################## - if [ -z "${ANSIBLE_DIRECTORY}" ]; then - # No Value, need to default - ANSIBLE_DIRECTORY="${DEFAULT_ANSIBLE_DIRECTORY}" - else - # Check if first char is '/' - if [[ ${ANSIBLE_DIRECTORY:0:1} == "/" ]]; then - # Remove first char - ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY:1}" - fi - # Need to give it full path - TEMP_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/${ANSIBLE_DIRECTORY}" - # Set the value - ANSIBLE_DIRECTORY="${TEMP_ANSIBLE_DIRECTORY}" - fi - - ############################### - # Get the disable errors flag # - ############################### - if [ -z "${DISABLE_ERRORS}" ]; then - ################################## - # No flag passed, set to default # - ################################## - DISABLE_ERRORS="${DEFAULT_DISABLE_ERRORS}" - fi - - ############################### - # Convert string to lowercase # - ############################### - DISABLE_ERRORS="${DISABLE_ERRORS,,}" - - ############################ - # Set to false if not true # - ############################ - if [ "${DISABLE_ERRORS}" != "true" ]; then - DISABLE_ERRORS="false" - fi - - ############################ - # Get the run verbose flag # - ############################ - if [ -z "${ACTIONS_RUNNER_DEBUG}" ]; then - ################################## - # No flag passed, set to default # - ################################## - ACTIONS_RUNNER_DEBUG="${DEFAULT_ACTIONS_RUNNER_DEBUG}" - fi - - ############################### - # Convert string to lowercase # - ############################### - ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG,,}" - - ############################ - # Set to true if not false # - ############################ - if [ "${ACTIONS_RUNNER_DEBUG}" != "false" ]; then - ACTIONS_RUNNER_DEBUG="true" - fi - - ########################### - # Print the validate info # - ########################### - for LINE in "${PRINT_ARRAY[@]}"; do - debug "${LINE}" - done - - debug "--- DEBUG INFO ---" - debug "---------------------------------------------" - RUNNER=$(whoami) - debug "Runner:[${RUNNER}]" - PRINTENV=$(printenv) - debug "ENV:" - debug "${PRINTENV}" - debug "---------------------------------------------" + debug "--- DEBUG INFO ---" + debug "---------------------------------------------" + RUNNER=$(whoami) + debug "Runner:[${RUNNER}]" + PRINTENV=$(printenv) + debug "ENV:" + debug "${PRINTENV}" + debug "---------------------------------------------" } diff --git a/lib/worker.sh b/lib/worker.sh index b5d5988c..929b3ff9 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -10,883 +10,883 @@ ################################################################################ #### Function LintCodebase ##################################################### function LintCodebase() { - #################### - # Pull in the vars # - #################### - FILE_TYPE="${1}" && shift # Pull the variable and remove from array path (Example: JSON) - LINTER_NAME="${1}" && shift # Pull the variable and remove from array path (Example: jsonlint) - LINTER_COMMAND="${1}" && shift # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) - 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}) + #################### + # Pull in the vars # + #################### + FILE_TYPE="${1}" && shift # Pull the variable and remove from array path (Example: JSON) + LINTER_NAME="${1}" && shift # Pull the variable and remove from array path (Example: jsonlint) + LINTER_COMMAND="${1}" && shift # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) + 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 # - ################ - PRINT_ARRAY+=("") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("Linting [${FILE_TYPE}] files...") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("----------------------------------------------") - - ##################################### - # Validate we have linter installed # - ##################################### - 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 - error "Failed to find [${LINTER_NAME}] in system!" - fatal "[${VALIDATE_INSTALL_CMD}]" - else - # Success - debug "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" - fi - - ########################## - # Initialize empty Array # - ########################## - 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 - SKIP_FLAG=1 - debug " - No files found in changeset 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 - else - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' - - ################################# - # Get list of all files to lint # - ################################# - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex "${FILE_EXTENSIONS}" 2>&1) - - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - - ############################################################ - # 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 # + # Create Print Array # ###################### - for LINE in "${PRINT_ARRAY[@]}"; do - ######################### - # Print the header info # - ######################### - info "${LINE}" - done + PRINT_ARRAY=() - ######################################## - # Prepare context if TAP format output # - ######################################## - if IsTAP ; then - TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") - INDEX=0 - mkdir -p "${REPORT_OUTPUT_FOLDER}" - REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" - fi + ################ + # print header # + ################ + PRINT_ARRAY+=("") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("Linting [${FILE_TYPE}] files...") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") - ################## - # Lint the files # - ################## - for FILE in "${LIST_FILES[@]}"; do - ################################### - # Get the file name and directory # - ################################### - FILE_NAME=$(basename "${FILE}" 2>&1) - DIR_NAME=$(dirname "${FILE}" 2>&1) - - ##################################################### - # 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 - elif [[ ${FILE} == *".git"* ]]; then - # This is likely the .git folder and shouldnt be parsed - continue - fi - - ################################## - # Increase the linted file index # - ################################## - (("INDEX++")) - - ############## - # File print # - ############## - info "---------------------------" - info "File:[${FILE}]" - - ################################# - # Add the language to the array # - ################################# - LINTED_LANGUAGES_ARRAY+=("${FILE_TYPE}") - - #################### - # Set the base Var # - #################### - LINT_CMD='' - - #################################### - # Corner case for pwsh subshell # - # - PowerShell (PSScriptAnalyzer) # - # - ARM (arm-ttk) # - #################################### - if [[ ${FILE_TYPE} == "POWERSHELL" ]] || [[ ${FILE_TYPE} == "ARM" ]]; then - ################################ - # Lint the file with the rules # - ################################ - # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}" || exit - pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" - exit $? 2>&1 - ) - ############################################################################### - # Corner case for groovy as we have to pass it as path and file in ant format # - ############################################################################### - elif [[ ${FILE_TYPE} == "GROOVY" ]]; then - ####################################### - # Lint the file with the updated path # - ####################################### - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}" || exit - ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 - ) - else - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}" || exit - ${LINTER_COMMAND} "${FILE}" 2>&1 - ) - fi - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # 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}++")) - - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP ; then - NotOkTap "${INDEX}" "${FILE}" "${TMPFILE}" - AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" - fi - else - ########### - # Success # - ########### - info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" - - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP ; then - OkTap "${INDEX}" "${FILE}" "${TMPFILE}" - fi - fi - done - - ################################# - # Generate report in TAP format # - ################################# - if IsTAP && [ ${INDEX} -gt 0 ] ; then - HeaderTap "${INDEX}" "${REPORT_OUTPUT_FILE}" - cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" - fi - fi -} -################################################################################ -#### Function TestCodebase ##################################################### -function TestCodebase() { - #################### - # Pull in the vars # - #################### - FILE_TYPE="${1}" # Pull the variable and remove from array path (Example: JSON) - LINTER_NAME="${2}" # Pull the variable and remove from array path (Example: jsonlint) - LINTER_COMMAND="${3}" # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) - FILE_EXTENSIONS="${4}" # Pull the variable and remove from array path (Example: *.json) - INDVIDUAL_TEST_FOLDER="${5}" # Folder for specific tests - TESTS_RAN=0 # Incremented when tests are ran, this will help find failed finds - - ################ - # print header # - ################ - info "----------------------------------------------" - info "----------------------------------------------" - info "Testing Codebase [${FILE_TYPE}] files..." - info "----------------------------------------------" - info "----------------------------------------------" - - ##################################### - # Validate we have linter installed # - ##################################### - 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 - error "Failed to find [${LINTER_NAME}] in system!" - fatal "[${VALIDATE_INSTALL_CMD}]" - else - # Success - info "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" - fi - - ########################## - # Initialize empty Array # - ########################## - LIST_FILES=() - - ################################# - # Get list of all files to lint # - ################################# - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" -type f -regex "${FILE_EXTENSIONS}" ! -path "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/ansible/ghe-initialize/*" | sort 2>&1) - - ######################################## - # Prepare context if TAP output format # - ######################################## - if IsTAP ; then - TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") - mkdir -p "${REPORT_OUTPUT_FOLDER}" - REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" - fi - - ################## - # Lint the files # - ################## - for FILE in "${LIST_FILES[@]}"; do - ##################### - # Get the file name # - ##################### - FILE_NAME=$(basename "${FILE}" 2>&1) - DIR_NAME=$(dirname "${FILE}" 2>&1) - - ############################ - # Get the file pass status # - ############################ - # Example: markdown_good_1.md -> good - FILE_STATUS=$(echo "${FILE_NAME}" | cut -f2 -d'_') - - ######################################################### - # If not found, assume it should be linted successfully # - ######################################################### - if [ -z "${FILE_STATUS}" ] || [[ ${FILE} == *"README"* ]]; then - ################################## - # Set to good for proper linting # - ################################## - FILE_STATUS="good" - fi - - ############## - # File print # - ############## - info "---------------------------" - info "File:[${FILE}]" - - ######################## - # Set the lint command # - ######################## - LINT_CMD='' - - ####################################### - # Check if docker and get folder name # - ####################################### - if [[ ${FILE_TYPE} == "DOCKER" ]]; then - if [[ ${FILE} == *"good"* ]]; then - ############# - # Good file # - ############# - FILE_STATUS='good' - else - ############ - # Bad file # - ############ - FILE_STATUS='bad' - fi - fi - - ##################### - # Check for ansible # - ##################### - if [[ ${FILE_TYPE} == "ANSIBLE" ]]; then - ######################################## - # Make sure we dont lint certain files # - ######################################## - if [[ ${FILE} == *"vault.yml"* ]] || [[ ${FILE} == *"galaxy.yml"* ]]; then - # This is a file we dont look at - continue - fi - - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" || exit - ${LINTER_COMMAND} "${FILE}" 2>&1 - ) - elif [[ ${FILE_TYPE} == "POWERSHELL" ]] || [[ ${FILE_TYPE} == "ARM" ]]; then - ################################ - # Lint the file with the rules # - ################################ - # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}" || exit - pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" - exit $? 2>&1 - ) - ############################################################################### - # Corner case for groovy as we have to pass it as path and file in ant format # - ############################################################################### - elif [[ ${FILE_TYPE} == "GROOVY" ]]; then - ####################################### - # Lint the file with the updated path # - ####################################### - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}" || exit - ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 - ) - else - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}" || exit - ${LINTER_COMMAND} "${FILE}" 2>&1 - ) - fi + ##################################### + # Validate we have linter installed # + ##################################### + VALIDATE_INSTALL_CMD=$(command -v "${LINTER_NAME}" 2>&1) ####################### # Load the error code # ####################### ERROR_CODE=$? - ######################################## - # Increment counter that check was ran # - ######################################## - (("TESTS_RAN++")) - - ######################################## - # Check for if it was supposed to pass # - ######################################## - if [[ ${FILE_STATUS} == "good" ]]; then - ############################## - # 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}++")) - else - ########### - # Success # - ########### - info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" - fi - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP ; then - OkTap "${TESTS_RAN}" "${FILE_NAME}" "${TMPFILE}" - fi + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Failed + error "Failed to find [${LINTER_NAME}] in system!" + fatal "[${VALIDATE_INSTALL_CMD}]" else - ####################################### - # File status = bad, this should fail # - ####################################### - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -eq 0 ]; then - ######### - # Error # - ######### - error "Found errors in [${LINTER_NAME}] linter!" - error "This file should have failed test case!" - error "Command run:${NC}[\$${LINT_CMD}]" - error "[${LINT_CMD}]" - error "Linter CMD:[${LINTER_COMMAND} ${FILE}]" - # Increment the error count - (("ERRORS_FOUND_${FILE_TYPE}++")) - else - ########### - # Success # - ########### - info " - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" - fi - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP ; then - NotOkTap "${TESTS_RAN}" "${FILE_NAME}" "${TMPFILE}" - AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" - fi - fi - done - - ########################################################################### - # Generate report in TAP format and validate with the expected TAP output # - ########################################################################### - if IsTAP && [ ${TESTS_RAN} -gt 0 ] ; then - HeaderTap "${TESTS_RAN}" "${REPORT_OUTPUT_FILE}" - cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" - - ######################################################################## - # If expected TAP report exists then compare with the generated report # - ######################################################################## - EXPECTED_FILE="${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}/reports/expected-${FILE_TYPE}.tap" - if [ -e "${EXPECTED_FILE}" ] ; then - TMPFILE=$(mktemp -q "/tmp/diff-${FILE_TYPE}.XXXXXX") - ## Ignore white spaces, case sensitive - if ! diff -a -w -i "${EXPECTED_FILE}" "${REPORT_OUTPUT_FILE}" > "${TMPFILE}" 2>&1; then - ############################################# - # We failed to compare the reporting output # - ############################################# - error "Failed to assert TAP output:[${LINTER_NAME}]"! - info "Please validate the asserts!" - cat "${TMPFILE}" - exit 1 - else # Success - info "Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]" - fi - else - warn "No TAP expected file found at:[${EXPECTED_FILE}]" - info "skipping report assertions" - ##################################### - # Append the file type to the array # - ##################################### - WARNING_ARRAY_TEST+=("${FILE_TYPE}") + debug "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" fi - fi - ############################## - # Validate we ran some tests # - ############################## - if [ "${TESTS_RAN}" -eq 0 ]; then - ################################################# - # We failed to find files and no tests were ran # - ################################################# - error "Failed to find any tests ran for the Linter:[${LINTER_NAME}]"! - fatal "Please validate logic or that tests exist!" - fi + ########################## + # Initialize empty Array # + ########################## + 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 + SKIP_FLAG=1 + debug " - No files found in changeset 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 + else + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' + + ################################# + # Get list of all files to lint # + ################################# + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex "${FILE_EXTENSIONS}" 2>&1) + + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + + ############################################################ + # 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 # + ###################### + for LINE in "${PRINT_ARRAY[@]}"; do + ######################### + # Print the header info # + ######################### + info "${LINE}" + done + + ######################################## + # Prepare context if TAP format output # + ######################################## + if IsTAP; then + TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") + INDEX=0 + mkdir -p "${REPORT_OUTPUT_FOLDER}" + REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" + fi + + ################## + # Lint the files # + ################## + for FILE in "${LIST_FILES[@]}"; do + ################################### + # Get the file name and directory # + ################################### + FILE_NAME=$(basename "${FILE}" 2>&1) + DIR_NAME=$(dirname "${FILE}" 2>&1) + + ##################################################### + # 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 + elif [[ ${FILE} == *".git"* ]]; then + # This is likely the .git folder and shouldnt be parsed + continue + fi + + ################################## + # Increase the linted file index # + ################################## + (("INDEX++")) + + ############## + # File print # + ############## + info "---------------------------" + info "File:[${FILE}]" + + ################################# + # Add the language to the array # + ################################# + LINTED_LANGUAGES_ARRAY+=("${FILE_TYPE}") + + #################### + # Set the base Var # + #################### + LINT_CMD='' + + #################################### + # Corner case for pwsh subshell # + # - PowerShell (PSScriptAnalyzer) # + # - ARM (arm-ttk) # + #################################### + if [[ ${FILE_TYPE} == "POWERSHELL" ]] || [[ ${FILE_TYPE} == "ARM" ]]; then + ################################ + # Lint the file with the rules # + ################################ + # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" + exit $? 2>&1 + ) + ############################################################################### + # Corner case for groovy as we have to pass it as path and file in ant format # + ############################################################################### + elif [[ ${FILE_TYPE} == "GROOVY" ]]; then + ####################################### + # Lint the file with the updated path # + ####################################### + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 + ) + else + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + ${LINTER_COMMAND} "${FILE}" 2>&1 + ) + fi + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # 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}++")) + + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + NotOkTap "${INDEX}" "${FILE}" "${TMPFILE}" + AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" + fi + else + ########### + # Success # + ########### + info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" + + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + OkTap "${INDEX}" "${FILE}" "${TMPFILE}" + fi + fi + done + + ################################# + # Generate report in TAP format # + ################################# + if IsTAP && [ ${INDEX} -gt 0 ]; then + HeaderTap "${INDEX}" "${REPORT_OUTPUT_FILE}" + cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" + fi + fi } ################################################################################ -#### Function RunTestCases ##################################################### -function RunTestCases() { - # This loop will run the test cases and exclude user code - # This is called from the automation process to validate new code - # When a PR is opened, the new code is validated with the default branch - # version of linter.sh, and a new container is built with the latest codebase - # for testing. That container is spun up, and ran, - # with the flag: TEST_CASE_RUN=true - # So that the new code can be validated against the test cases +#### Function TestCodebase ##################################################### +function TestCodebase() { + #################### + # Pull in the vars # + #################### + FILE_TYPE="${1}" # Pull the variable and remove from array path (Example: JSON) + LINTER_NAME="${2}" # Pull the variable and remove from array path (Example: jsonlint) + LINTER_COMMAND="${3}" # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) + FILE_EXTENSIONS="${4}" # Pull the variable and remove from array path (Example: *.json) + INDVIDUAL_TEST_FOLDER="${5}" # Folder for specific tests + TESTS_RAN=0 # Incremented when tests are ran, this will help find failed finds - ################# - # Header prints # - ################# - info "----------------------------------------------" - info "-------------- TEST CASE RUN -----------------" - info "----------------------------------------------" + ################ + # print header # + ################ + info "----------------------------------------------" + info "----------------------------------------------" + info "Testing Codebase [${FILE_TYPE}] files..." + info "----------------------------------------------" + info "----------------------------------------------" - ####################### - # Test case languages # - ####################### - # TestCodebase "Language" "Linter" "Linter-command" "Regex to find files" "Test Folder" - 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" ".*\.\(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" - TestCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "css" - TestCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "dart" - TestCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c ${DOCKER_LINTER_RULES}" ".*\(Dockerfile\)\$" "docker" - TestCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" ".*\.ext$" "editorconfig-checker" - TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "env" - TestCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "golang" - TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" - TestCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "html" - TestCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "javascript" - TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript" - TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json" - TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin" - TestCodebase "LUA" "lua" "luacheck" ".*\.\(lua\)\$" "lua" - TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown" - TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl" - TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php" - TestCodebase "PHP_PHPSTAN" "phpstan" "phpstan analyse --no-progress --no-ansi -c ${PHPSTAN_LINTER_RULES}" ".*\.\(php\)\$" "php" - TestCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi" - TestCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "powershell" - TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "protobuf" - TestCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "python" - TestCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config ${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "python" - TestCodebase "RAKU" "raku" "raku -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "raku" - TestCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES}" ".*\.\(rb\)\$" "ruby" - TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states" - TestCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "terraform" - TestCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "terraform_terrascan" - TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" - TestCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" - TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "xml" - TestCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "yml" + ##################################### + # Validate we have linter installed # + ##################################### + VALIDATE_INSTALL_CMD=$(command -v "${LINTER_NAME}" 2>&1) - ################# - # Footer prints # - ################# - # Call the footer to display run information - # and exit with error code - Footer -} -################################################################################ -#### Function LintAnsibleFiles ################################################# -function LintAnsibleFiles() { - ###################### - # Create Print Array # - ###################### - PRINT_ARRAY=() + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ################ - # print header # - ################ - PRINT_ARRAY+=("") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("Linting [Ansible] files...") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("----------------------------------------------") + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Failed + error "Failed to find [${LINTER_NAME}] in system!" + fatal "[${VALIDATE_INSTALL_CMD}]" + else + # Success + info "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" + fi - ###################### - # Name of the linter # - ###################### - LINTER_NAME="ansible-lint" - - ########################################### - # Validate we have ansible-lint installed # - ########################################### - 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 - error "Failed to find ${LINTER_NAME} in system!" - fatal "[${VALIDATE_INSTALL_CMD}]" - else - # Success - debug "Successfully found binary in system" - debug "Location:[${VALIDATE_INSTALL_CMD}]" - fi - - ########################## - # Initialize empty Array # - ########################## - LIST_FILES=() - - ####################### - # Create flag to skip # - ####################### - SKIP_FLAG=0 - - ###################################################### - # Only go into ansible linter if we have base folder # - ###################################################### - if [ -d "${ANSIBLE_DIRECTORY}" ]; then + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() ################################# # Get list of all files to lint # ################################# - mapfile -t LIST_FILES < <(ls "${ANSIBLE_DIRECTORY}"/*.{yaml,yml} 2>&1) - - ############################################################### - # Set the list to empty if only MD and TXT files were changed # - ############################################################### - # No need to run the full ansible checks on read only file changes - if [ "${READ_ONLY_CHANGE_FLAG}" -eq 0 ]; then - ########################## - # Set the array to empty # - ########################## - LIST_FILES=() - ################################### - # Send message that were skipping # - ################################### - debug "- 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 # - ######################### - info "${LINE}" - done - fi + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" -type f -regex "${FILE_EXTENSIONS}" ! -path "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/ansible/ghe-initialize/*" | sort 2>&1) ######################################## # Prepare context if TAP output format # ######################################## - if IsTAP ; then - TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") - INDEX=0 - mkdir -p "${REPORT_OUTPUT_FOLDER}" - REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" + if IsTAP; then + TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") + mkdir -p "${REPORT_OUTPUT_FOLDER}" + REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" fi ################## # Lint the files # ################## for FILE in "${LIST_FILES[@]}"; do + ##################### + # Get the file name # + ##################### + FILE_NAME=$(basename "${FILE}" 2>&1) + DIR_NAME=$(dirname "${FILE}" 2>&1) - ######################################## - # Make sure we dont lint certain files # - ######################################## - if [[ ${FILE} == *"vault.yml"* ]] || [[ ${FILE} == *"galaxy.yml"* ]]; then - # This is a file we dont look at - continue - fi + ############################ + # Get the file pass status # + ############################ + # Example: markdown_good_1.md -> good + FILE_STATUS=$(echo "${FILE_NAME}" | cut -f2 -d'_') - ################################## - # Increase the linted file index # - ################################## - (("INDEX++")) - - #################### - # Get the filename # - #################### - FILE_NAME=$(basename "${ANSIBLE_DIRECTORY}/${FILE}" 2>&1) - - ############## - # File print # - ############## - info "---------------------------" - info "File:[${FILE}]" - - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$("${LINTER_NAME}" -v -c "${ANSIBLE_LINTER_RULES}" "${ANSIBLE_DIRECTORY}/${FILE}" 2>&1) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - ######### - # Error # - ######### - error "Found errors in [${LINTER_NAME}] linter!" - error "[${LINT_CMD}]" - # Increment error count - ((ERRORS_FOUND_ANSIBLE++)) - - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP ; then - NotOkTap "${INDEX}" "${FILE}" "${TMPFILE}" - AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" + ######################################################### + # If not found, assume it should be linted successfully # + ######################################################### + if [ -z "${FILE_STATUS}" ] || [[ ${FILE} == *"README"* ]]; then + ################################## + # Set to good for proper linting # + ################################## + FILE_STATUS="good" fi - else - ########### - # Success # - ########### - info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" + ############## + # File print # + ############## + info "---------------------------" + info "File:[${FILE}]" - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP ; then - OkTap "${INDEX}" "${FILE}" "${TMPFILE}" + ######################## + # Set the lint command # + ######################## + LINT_CMD='' + + ####################################### + # Check if docker and get folder name # + ####################################### + if [[ ${FILE_TYPE} == "DOCKER" ]]; then + if [[ ${FILE} == *"good"* ]]; then + ############# + # Good file # + ############# + FILE_STATUS='good' + else + ############ + # Bad file # + ############ + FILE_STATUS='bad' + fi + fi + + ##################### + # Check for ansible # + ##################### + if [[ ${FILE_TYPE} == "ANSIBLE" ]]; then + ######################################## + # Make sure we dont lint certain files # + ######################################## + if [[ ${FILE} == *"vault.yml"* ]] || [[ ${FILE} == *"galaxy.yml"* ]]; then + # This is a file we dont look at + continue + fi + + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" || exit + ${LINTER_COMMAND} "${FILE}" 2>&1 + ) + elif [[ ${FILE_TYPE} == "POWERSHELL" ]] || [[ ${FILE_TYPE} == "ARM" ]]; then + ################################ + # Lint the file with the rules # + ################################ + # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}" || exit + pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" + exit $? 2>&1 + ) + ############################################################################### + # Corner case for groovy as we have to pass it as path and file in ant format # + ############################################################################### + elif [[ ${FILE_TYPE} == "GROOVY" ]]; then + ####################################### + # Lint the file with the updated path # + ####################################### + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 + ) + else + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}" || exit + ${LINTER_COMMAND} "${FILE}" 2>&1 + ) + fi + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ######################################## + # Increment counter that check was ran # + ######################################## + (("TESTS_RAN++")) + + ######################################## + # Check for if it was supposed to pass # + ######################################## + if [[ ${FILE_STATUS} == "good" ]]; then + ############################## + # 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}++")) + else + ########### + # Success # + ########### + info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" + fi + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + OkTap "${TESTS_RAN}" "${FILE_NAME}" "${TMPFILE}" + fi + else + ####################################### + # File status = bad, this should fail # + ####################################### + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -eq 0 ]; then + ######### + # Error # + ######### + error "Found errors in [${LINTER_NAME}] linter!" + error "This file should have failed test case!" + error "Command run:${NC}[\$${LINT_CMD}]" + error "[${LINT_CMD}]" + error "Linter CMD:[${LINTER_COMMAND} ${FILE}]" + # Increment the error count + (("ERRORS_FOUND_${FILE_TYPE}++")) + else + ########### + # Success # + ########### + info " - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" + fi + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + NotOkTap "${TESTS_RAN}" "${FILE_NAME}" "${TMPFILE}" + AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" + fi fi - fi done - ################################# - # Generate report in TAP format # - ################################# - if IsTAP && [ ${INDEX} -gt 0 ] ; then - HeaderTap "${INDEX}" "${REPORT_OUTPUT_FILE}" - cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" + ########################################################################### + # Generate report in TAP format and validate with the expected TAP output # + ########################################################################### + if IsTAP && [ ${TESTS_RAN} -gt 0 ]; then + HeaderTap "${TESTS_RAN}" "${REPORT_OUTPUT_FILE}" + cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" + + ######################################################################## + # If expected TAP report exists then compare with the generated report # + ######################################################################## + EXPECTED_FILE="${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}/reports/expected-${FILE_TYPE}.tap" + if [ -e "${EXPECTED_FILE}" ]; then + TMPFILE=$(mktemp -q "/tmp/diff-${FILE_TYPE}.XXXXXX") + ## Ignore white spaces, case sensitive + if ! diff -a -w -i "${EXPECTED_FILE}" "${REPORT_OUTPUT_FILE}" > "${TMPFILE}" 2>&1; then + ############################################# + # We failed to compare the reporting output # + ############################################# + error "Failed to assert TAP output:[${LINTER_NAME}]"! + info "Please validate the asserts!" + cat "${TMPFILE}" + exit 1 + else + # Success + info "Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]" + fi + else + warn "No TAP expected file found at:[${EXPECTED_FILE}]" + info "skipping report assertions" + ##################################### + # Append the file type to the array # + ##################################### + WARNING_ARRAY_TEST+=("${FILE_TYPE}") + fi + fi + + ############################## + # Validate we ran some tests # + ############################## + if [ "${TESTS_RAN}" -eq 0 ]; then + ################################################# + # We failed to find files and no tests were ran # + ################################################# + error "Failed to find any tests ran for the Linter:[${LINTER_NAME}]"! + fatal "Please validate logic or that tests exist!" + fi +} +################################################################################ +#### Function RunTestCases ##################################################### +function RunTestCases() { + # This loop will run the test cases and exclude user code + # This is called from the automation process to validate new code + # When a PR is opened, the new code is validated with the default branch + # version of linter.sh, and a new container is built with the latest codebase + # for testing. That container is spun up, and ran, + # with the flag: TEST_CASE_RUN=true + # So that the new code can be validated against the test cases + + ################# + # Header prints # + ################# + info "----------------------------------------------" + info "-------------- TEST CASE RUN -----------------" + info "----------------------------------------------" + + ####################### + # Test case languages # + ####################### + # TestCodebase "Language" "Linter" "Linter-command" "Regex to find files" "Test Folder" + 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" ".*\.\(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" + TestCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "css" + TestCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "dart" + TestCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c ${DOCKER_LINTER_RULES}" ".*\(Dockerfile\)\$" "docker" + TestCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" ".*\.ext$" "editorconfig-checker" + TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "env" + TestCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "golang" + TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" + TestCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "html" + TestCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "javascript" + TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript" + TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json" + TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin" + TestCodebase "LUA" "lua" "luacheck" ".*\.\(lua\)\$" "lua" + TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown" + TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl" + TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php" + TestCodebase "PHP_PHPSTAN" "phpstan" "phpstan analyse --no-progress --no-ansi -c ${PHPSTAN_LINTER_RULES}" ".*\.\(php\)\$" "php" + TestCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi" + TestCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "powershell" + TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "protobuf" + TestCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "python" + TestCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config ${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "python" + TestCodebase "RAKU" "raku" "raku -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "raku" + TestCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES}" ".*\.\(rb\)\$" "ruby" + TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states" + TestCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "terraform" + TestCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "terraform_terrascan" + TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" + TestCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" + TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "xml" + TestCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "yml" + + ################# + # Footer prints # + ################# + # Call the footer to display run information + # and exit with error code + Footer +} +################################################################################ +#### Function LintAnsibleFiles ################################################# +function LintAnsibleFiles() { + ###################### + # Create Print Array # + ###################### + PRINT_ARRAY=() + + ################ + # print header # + ################ + PRINT_ARRAY+=("") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("Linting [Ansible] files...") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") + + ###################### + # Name of the linter # + ###################### + LINTER_NAME="ansible-lint" + + ########################################### + # Validate we have ansible-lint installed # + ########################################### + 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 + error "Failed to find ${LINTER_NAME} in system!" + fatal "[${VALIDATE_INSTALL_CMD}]" + else + # Success + debug "Successfully found binary in system" + debug "Location:[${VALIDATE_INSTALL_CMD}]" + fi + + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ####################### + # Create flag to skip # + ####################### + SKIP_FLAG=0 + + ###################################################### + # Only go into ansible linter if we have base folder # + ###################################################### + if [ -d "${ANSIBLE_DIRECTORY}" ]; then + + ################################# + # Get list of all files to lint # + ################################# + mapfile -t LIST_FILES < <(ls "${ANSIBLE_DIRECTORY}"/*.{yaml,yml} 2>&1) + + ############################################################### + # Set the list to empty if only MD and TXT files were changed # + ############################################################### + # No need to run the full ansible checks on read only file changes + if [ "${READ_ONLY_CHANGE_FLAG}" -eq 0 ]; then + ########################## + # Set the array to empty # + ########################## + LIST_FILES=() + ################################### + # Send message that were skipping # + ################################### + debug "- 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 # + ######################### + info "${LINE}" + done + fi + + ######################################## + # Prepare context if TAP output format # + ######################################## + if IsTAP; then + TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") + INDEX=0 + mkdir -p "${REPORT_OUTPUT_FOLDER}" + REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" + fi + + ################## + # Lint the files # + ################## + for FILE in "${LIST_FILES[@]}"; do + + ######################################## + # Make sure we dont lint certain files # + ######################################## + if [[ ${FILE} == *"vault.yml"* ]] || [[ ${FILE} == *"galaxy.yml"* ]]; then + # This is a file we dont look at + continue + fi + + ################################## + # Increase the linted file index # + ################################## + (("INDEX++")) + + #################### + # Get the filename # + #################### + FILE_NAME=$(basename "${ANSIBLE_DIRECTORY}/${FILE}" 2>&1) + + ############## + # File print # + ############## + info "---------------------------" + info "File:[${FILE}]" + + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$("${LINTER_NAME}" -v -c "${ANSIBLE_LINTER_RULES}" "${ANSIBLE_DIRECTORY}/${FILE}" 2>&1) + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + ######### + # Error # + ######### + error "Found errors in [${LINTER_NAME}] linter!" + error "[${LINT_CMD}]" + # Increment error count + ((ERRORS_FOUND_ANSIBLE++)) + + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + NotOkTap "${INDEX}" "${FILE}" "${TMPFILE}" + AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" + fi + + else + ########### + # Success # + ########### + info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" + + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + OkTap "${INDEX}" "${FILE}" "${TMPFILE}" + fi + fi + done + + ################################# + # Generate report in TAP format # + ################################# + if IsTAP && [ ${INDEX} -gt 0 ]; then + HeaderTap "${INDEX}" "${REPORT_OUTPUT_FILE}" + cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" + fi + else + ######################## + # No Ansible dir found # + ######################## + warn "No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]" + debug "skipping ansible lint" fi - else - ######################## - # No Ansible dir found # - ######################## - warn "No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]" - debug "skipping ansible lint" - fi } ################################################################################ #### Function IsTap ############################################################ function IsTAP() { - if [ "${OUTPUT_FORMAT}" == "tap" ] ; then - return 0 - else - return 1 - fi + if [ "${OUTPUT_FORMAT}" == "tap" ]; then + return 0 + else + return 1 + fi } ################################################################################ #### Function TransformTAPDetails ############################################## function TransformTAPDetails() { - DATA=${1} - if [ -n "${DATA}" ] && [ "${OUTPUT_DETAILS}" == "detailed" ] ; then - ######################################################### - # Transform new lines to \\n, remove colours and colons # - ######################################################### - echo "${DATA}" | awk 'BEGIN{RS="\n";ORS="\\n"}1' | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" | tr ':' ' ' - fi + DATA=${1} + if [ -n "${DATA}" ] && [ "${OUTPUT_DETAILS}" == "detailed" ]; then + ######################################################### + # Transform new lines to \\n, remove colours and colons # + ######################################################### + echo "${DATA}" | awk 'BEGIN{RS="\n";ORS="\\n"}1' | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" | tr ':' ' ' + fi } ################################################################################ #### Function HeaderTap ######################################################## function HeaderTap() { - ################ - # Pull in Vars # - ################ - INDEX="${1}" # File being validated - OUTPUT_FILE="${2}" # Output location + ################ + # Pull in Vars # + ################ + INDEX="${1}" # File being validated + OUTPUT_FILE="${2}" # Output location - ################### - # Print the goods # - ################### - printf "TAP version 13\n1..%s\n" "${INDEX}" > "${OUTPUT_FILE}" + ################### + # Print the goods # + ################### + printf "TAP version 13\n1..%s\n" "${INDEX}" > "${OUTPUT_FILE}" } ################################################################################ #### Function OkTap ############################################################ function OkTap() { - ################ - # Pull in Vars # - ################ - INDEX="${1}" # Location - FILE="${2}" # File being validated - TEMP_FILE="${3}" # Temp file location + ################ + # Pull in Vars # + ################ + INDEX="${1}" # Location + FILE="${2}" # File being validated + TEMP_FILE="${3}" # Temp file location - ################### - # Print the goods # - ################### - echo "ok ${INDEX} - ${FILE}" >> "${TEMP_FILE}" + ################### + # Print the goods # + ################### + echo "ok ${INDEX} - ${FILE}" >> "${TEMP_FILE}" } ################################################################################ #### Function NotOkTap ######################################################### function NotOkTap() { - ################ - # Pull in Vars # - ################ - INDEX="${1}" # Location - FILE="${2}" # File being validated - TEMP_FILE="${3}" # Temp file location + ################ + # Pull in Vars # + ################ + INDEX="${1}" # Location + FILE="${2}" # File being validated + TEMP_FILE="${3}" # Temp file location - ################### - # Print the goods # - ################### - echo "not ok ${INDEX} - ${FILE}" >> "${TEMP_FILE}" + ################### + # Print the goods # + ################### + echo "not ok ${INDEX} - ${FILE}" >> "${TEMP_FILE}" } ################################################################################ #### Function AddDetailedMessageIfEnabled ###################################### function AddDetailedMessageIfEnabled() { - ################ - # Pull in Vars # - ################ - LINT_CMD="${1}" # Linter command - TEMP_FILE="${2}" # Temp file + ################ + # Pull in Vars # + ################ + LINT_CMD="${1}" # Linter command + TEMP_FILE="${2}" # Temp file - #################### - # Check the return # - #################### - DETAILED_MSG=$(TransformTAPDetails "${LINT_CMD}") - if [ -n "${DETAILED_MSG}" ] ; then - printf " ---\n message: %s\n ...\n" "${DETAILED_MSG}" >> "${TEMP_FILE}" - fi + #################### + # Check the return # + #################### + DETAILED_MSG=$(TransformTAPDetails "${LINT_CMD}") + if [ -n "${DETAILED_MSG}" ]; then + printf " ---\n message: %s\n ...\n" "${DETAILED_MSG}" >> "${TEMP_FILE}" + fi } From d49f6ce71f880141bcef618a63a1e930b8ab3b00 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 15:19:21 -0500 Subject: [PATCH 39/52] Remove sudo --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index e106dd0e..231fa185 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1037,7 +1037,7 @@ Footer() { cleanup() { local -ri EXIT_CODE=$? - sudo sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/${LOG_FILE}" || true + sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/${LOG_FILE}" || true exit ${EXIT_CODE} trap - 0 1 2 3 6 14 15 From a03fd743f1f00c8f9edc50d57193f21c81267446 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 15:26:01 -0500 Subject: [PATCH 40/52] Document new variables --- README.md | 71 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 7cc6f0ac..68c4c1ed 100644 --- a/README.md +++ b/README.md @@ -41,39 +41,39 @@ The design of the **Super-Linter** is currently to allow linting to occur in **G Developers on **GitHub** can call the **GitHub Action** to lint their code base with the following list of linters: -| _Language_ | _Linter_ | -| -------------------------------- | ------------------------------------------------------------------------------------ | -| **Ansible** | [ansible-lint](https://github.com/ansible/ansible-lint) | -| **Azure Resource Manager (ARM)** | [arm-ttk](https://github.com/azure/arm-ttk) | -| **AWS CloudFormation templates** | [cfn-lint](https://github.com/aws-cloudformation/cfn-python-lint/) | -| **CSS** | [stylelint](https://stylelint.io/) | -| **Clojure** | [clj-kondo](https://github.com/borkdude/clj-kondo) | -| **CoffeeScript** | [coffeelint](https://coffeelint.github.io/) | -| **Dart** | [dartanalyzer](https://dart.dev/guides/language/analysis-options) | -| **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) | -| **EDITORCONFIG** | [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) | -| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) | -| **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) | -| **Groovy** | [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) | -| **HTMLHint** | [HTMLHint](https://github.com/htmlhint/HTMLHint) | -| **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | -| **JSON** | [jsonlint](https://github.com/zaach/jsonlint) | -| **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | -| **Lua** | [luacheck](https://github.com/luarocks/luacheck) | -| **Markdown** | [markdownlint](https://github.com/igorshubovych/markdownlint-cli#readme) | -| **OpenAPI** | [spectral](https://github.com/stoplightio/spectral) | -| **Perl** | [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) | -| **PHP** | [PHP](https://www.php.net/) | -| **PowerShell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) | -| **Protocol Buffers** | [protolint](https://github.com/yoheimuta/protolint) | -| **Python3** | [pylint](https://www.pylint.org/) [flake8](https://flake8.pycqa.org/en/latest/) | -| **Raku** | [raku](https://raku.org) | -| **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) | -| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) | -| **Terraform** | [tflint](https://github.com/terraform-linters/tflint) [terrascan](https://github.com/accurics/terrascan) | -| **TypeScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | -| **XML** | [LibXML](http://xmlsoft.org/) | -| **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) | +| _Language_ | _Linter_ | +| -------------------------------- | -------------------------------------------------------------------------------------------------------- | +| **Ansible** | [ansible-lint](https://github.com/ansible/ansible-lint) | +| **Azure Resource Manager (ARM)** | [arm-ttk](https://github.com/azure/arm-ttk) | +| **AWS CloudFormation templates** | [cfn-lint](https://github.com/aws-cloudformation/cfn-python-lint/) | +| **CSS** | [stylelint](https://stylelint.io/) | +| **Clojure** | [clj-kondo](https://github.com/borkdude/clj-kondo) | +| **CoffeeScript** | [coffeelint](https://coffeelint.github.io/) | +| **Dart** | [dartanalyzer](https://dart.dev/guides/language/analysis-options) | +| **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) | +| **EDITORCONFIG** | [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) | +| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) | +| **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) | +| **Groovy** | [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) | +| **HTMLHint** | [HTMLHint](https://github.com/htmlhint/HTMLHint) | +| **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | +| **JSON** | [jsonlint](https://github.com/zaach/jsonlint) | +| **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | +| **Lua** | [luacheck](https://github.com/luarocks/luacheck) | +| **Markdown** | [markdownlint](https://github.com/igorshubovych/markdownlint-cli#readme) | +| **OpenAPI** | [spectral](https://github.com/stoplightio/spectral) | +| **Perl** | [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) | +| **PHP** | [PHP](https://www.php.net/) | +| **PowerShell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) | +| **Protocol Buffers** | [protolint](https://github.com/yoheimuta/protolint) | +| **Python3** | [pylint](https://www.pylint.org/) [flake8](https://flake8.pycqa.org/en/latest/) | +| **Raku** | [raku](https://raku.org) | +| **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) | +| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) | +| **Terraform** | [tflint](https://github.com/terraform-linters/tflint) [terrascan](https://github.com/accurics/terrascan) | +| **TypeScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | +| **XML** | [LibXML](http://xmlsoft.org/) | +| **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) | ## How to use @@ -176,6 +176,8 @@ and won't run anything unexpected. | **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. | | **JAVASCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [eslint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`) | | **LINTER_RULES_PATH** | `.github/linters` | Directory for all linter configuration rules. | +| **LOG_FILE** | `super-linter.log` | The file name for outputting logs. All output is sent to the log file regardless of `LOG_LEVEL`. | +| **LOG_LEVEL** | `VERBOSE` | How much output the script will generate to the console. One of `VERBOSE`, `DEBUG` or `TRACE`. | | **MULTI_STATUS** | `true` | A status API is made for each language that is linted to make visual parsing easier. | | **OUTPUT_FORMAT** | `none` | The report format to be generated, besides the stdout one. Output format of tap is currently using v13 of the specification. Supported formats: tap | | **OUTPUT_FOLDER** | `super-linter.report` | The location where the output reporting will be generated to. Output folder must not previously exist. | @@ -219,7 +221,7 @@ and won't run anything unexpected. | **VALIDATE_RUBY** | `true` | Flag to enable or disable the linting process of the Ruby language. | | **VALIDATE_STATES** | `true` | Flag to enable or disable the linting process for AWS States Language. | | **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the Terraform language. | -| **VALIDATE_TERRAFORM_TERRASCAN** | `false` | Flag to enable or disable the linting process of the Terraform language for security related issues. | +| **VALIDATE_TERRAFORM_TERRASCAN** | `false` | Flag to enable or disable the linting process of the Terraform language for security related issues. | | **VALIDATE_TSX** | `true` | Flag to enable or disable the linting process for tsx files (Utilizing: eslint) | | **VALIDATE_TYPESCRIPT_ES** | `true` | Flag to enable or disable the linting process of the Typescript language. (Utilizing: eslint) | | **VALIDATE_TYPESCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the Typescript language. (Utilizing: standard) | @@ -227,7 +229,6 @@ and won't run anything unexpected. | **VALIDATE_YAML** | `true` | Flag to enable or disable the linting process of the YAML language. | | **YAML_CONFIG_FILE** | `.yaml-lint.yml` | Filename for [Yamllint configuration](https://yamllint.readthedocs.io/en/stable/configuration.html) (ex: `.yaml-lint.yml`, `.yamllint.yml`) | - ### Template rules files You can use the **GitHub** **Super-Linter** _with_ or _without_ your own personal rules sets. This allows for greater flexibility for each individual code base. The Template rules all try to follow the standards we believe should be enabled at the basic level. From 0e547aa871176a6916f44b80a175a2c457185a4a Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 15:39:05 -0500 Subject: [PATCH 41/52] Format (fix indentation) --- lib/buildFileList.sh | 996 ++++++++++++------------ lib/linter.sh | 1748 +++++++++++++++++++++--------------------- lib/log.sh | 54 +- lib/termColors.sh | 32 +- lib/validation.sh | 316 ++++---- lib/worker.sh | 1596 +++++++++++++++++++------------------- 6 files changed, 2371 insertions(+), 2371 deletions(-) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index a98e885f..3e52de0f 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -10,522 +10,522 @@ ################################################################################ #### Function BuildFileList #################################################### function BuildFileList() { - # Need to build a list of all files changed - # This can be pulled from the GITHUB_EVENT_PATH payload + # Need to build a list of all files changed + # This can be pulled from the GITHUB_EVENT_PATH payload - ################ - # print header # - ################ - debug "----------------------------------------------" - debug "Pulling in code history and branches..." + ################ + # print header # + ################ + debug "----------------------------------------------" + debug "Pulling in code history and branches..." - ################################################################################# - # Switch codebase back to the default branch to get a list of all files changed # - ################################################################################# - SWITCH_CMD=$( - git -C "${GITHUB_WORKSPACE}" pull --quiet - git -C "${GITHUB_WORKSPACE}" checkout "${DEFAULT_BRANCH}" 2>&1 - ) + ################################################################################# + # Switch codebase back to the default branch to get a list of all files changed # + ################################################################################# + SWITCH_CMD=$( + git -C "${GITHUB_WORKSPACE}" pull --quiet + git -C "${GITHUB_WORKSPACE}" checkout "${DEFAULT_BRANCH}" 2>&1 + ) - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Error - info "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!" - fatal "[${SWITCH_CMD}]" - fi + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Error + info "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!" + fatal "[${SWITCH_CMD}]" + fi - ################ - # print header # - ################ - debug "----------------------------------------------" - debug "Generating Diff with:[git diff --name-only '${DEFAULT_BRANCH}..${GITHUB_SHA}' --diff-filter=d]" + ################ + # print header # + ################ + debug "----------------------------------------------" + debug "Generating Diff with:[git diff --name-only '${DEFAULT_BRANCH}..${GITHUB_SHA}' --diff-filter=d]" - ################################################# - # Get the Array of files changed in the commits # - ################################################# - mapfile -t RAW_FILE_ARRAY < <(git -C "${GITHUB_WORKSPACE}" diff --name-only "${DEFAULT_BRANCH}..${GITHUB_SHA}" --diff-filter=d 2>&1) + ################################################# + # Get the Array of files changed in the commits # + ################################################# + mapfile -t RAW_FILE_ARRAY < <(git -C "${GITHUB_WORKSPACE}" diff --name-only "${DEFAULT_BRANCH}..${GITHUB_SHA}" --diff-filter=d 2>&1) - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Error - error "Failed to gain a list of all files changed!" - fatal "[${RAW_FILE_ARRAY[*]}]" - fi + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Error + error "Failed to gain a list of all files changed!" + fatal "[${RAW_FILE_ARRAY[*]}]" + fi - ################################################ - # Iterate through the array of all files found # - ################################################ - info "----------------------------------------------" - info "Files that have been modified in the commit(s):" - for FILE in "${RAW_FILE_ARRAY[@]}"; do - ########################### - # Get the files extension # - ########################### - # Extract just the file extension - FILE_TYPE=${FILE##*.} - # To lowercase - FILE_TYPE=${FILE_TYPE,,} + ################################################ + # Iterate through the array of all files found # + ################################################ + info "----------------------------------------------" + info "Files that have been modified in the commit(s):" + for FILE in "${RAW_FILE_ARRAY[@]}"; do + ########################### + # Get the files extension # + ########################### + # Extract just the file extension + FILE_TYPE=${FILE##*.} + # To lowercase + FILE_TYPE=${FILE_TYPE,,} - ############## - # Print file # - ############## - info "File:[${FILE}], File_type:[${FILE_TYPE}]" + ############## + # Print file # + ############## + info "File:[${FILE}], File_type:[${FILE_TYPE}]" - ######### - # DEBUG # - ######### - debug "FILE_TYPE:[${FILE_TYPE}]" + ######### + # DEBUG # + ######### + debug "FILE_TYPE:[${FILE_TYPE}]" + ################################ + # Get the CLOUDFORMATION files # + ################################ + if [ "${FILE_TYPE}" == "yml" ] || [ "${FILE_TYPE}" == "yaml" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_YAML+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + + ##################################### + # Check if the file is CFN template # + ##################################### + if DetectCloudFormationFile "${FILE}"; then ################################ - # Get the CLOUDFORMATION files # + # Append the file to the array # ################################ - if [ "${FILE_TYPE}" == "yml" ] || [ "${FILE_TYPE}" == "yaml" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_YAML+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 + FILE_ARRAY_CLOUDFORMATION+=("${FILE}") - ##################################### - # Check if the file is CFN template # - ##################################### - if DetectCloudFormationFile "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_CLOUDFORMATION+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + fi + ###################### + # Get the JSON files # + ###################### + elif [ "${FILE_TYPE}" == "json" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_JSON+=("${FILE}") + ############################ + # Check if file is OpenAPI # + ############################ + if DetectOpenAPIFile "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_OPENAPI+=("${FILE}") + fi + ############################ + # Check if file is ARM # + ############################ + if DetectARMFile "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_ARM+=("${FILE}") + fi + ##################################### + # Check if the file is CFN template # + ##################################### + if DetectCloudFormationFile "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_CLOUDFORMATION+=("${FILE}") + fi + ############################################ + # Check if the file is AWS States Language # + ############################################ + if DetectAWSStatesFIle "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_STATES+=("${FILE}") + fi + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ##################### + # Get the XML files # + ##################### + elif [ "${FILE_TYPE}" == "xml" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_XML+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ########################## + # Get the MARKDOWN files # + ########################## + elif [ "${FILE_TYPE}" == "md" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_MARKDOWN+=("${FILE}") + ###################### + # Get the BASH files # + ###################### + elif [ "${FILE_TYPE}" == "sh" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_BASH+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### + # Get the PERL files # + ###################### + elif [ "${FILE_TYPE}" == "pl" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PERL+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### + # Get the RAKU files # + ###################### + elif [ "${FILE_TYPE}" == "raku" ] || [ "${FILE_TYPE}" == "rakumod" ] || + [ "${FILE_TYPE}" == "rakutest" ] || [ "${FILE_TYPE}" == "pm6" ] || + [ "${FILE_TYPE}" == "pl6" ] || [ "${FILE_TYPE}" == "p6" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_RAKU+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### + # Get the PHP files # + ###################### + elif [ "${FILE_TYPE}" == "php" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PHP+=("${FILE}") + FILE_ARRAY_PHP_PHPSTAN+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### + # Get the RUBY files # + ###################### + elif [ "${FILE_TYPE}" == "rb" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_RUBY+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ######################## + # Get the PYTHON files # + ######################## + elif [ "${FILE_TYPE}" == "py" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PYTHON_PYLINT+=("${FILE}") + FILE_ARRAY_PYTHON_FLAKE8+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ######################## + # Get the COFFEE files # + ######################## + elif [ "${FILE_TYPE}" == "coffee" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_COFFEESCRIPT+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ############################ + # Get the JavaScript files # + ############################ + elif [ "${FILE_TYPE}" == "js" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_JAVASCRIPT_ES+=("${FILE}") + FILE_ARRAY_JAVASCRIPT_STANDARD+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ############################ + # Get the JSX files # + ############################ + elif [ "${FILE_TYPE}" == "jsx" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_JSX+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ############################ + # Get the TSX files # + ############################ + elif [ "${FILE_TYPE}" == "tsx" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_TSX+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ######################## + # Get the Golang files # + ######################## + ############################ + # Get the TypeScript files # + ############################ + elif [ "${FILE_TYPE}" == "ts" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_TYPESCRIPT_ES+=("${FILE}") + FILE_ARRAY_TYPESCRIPT_STANDARD+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ######################## + # Get the Golang files # + ######################## + elif [ "${FILE_TYPE}" == "go" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_GO+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ########################### + # Get the Terraform files # + ########################### + elif [ "${FILE_TYPE}" == "tf" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_TERRAFORM+=("${FILE}") + FILE_ARRAY_TERRAFORM_TERRASCAN+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ########################### + # Get the Powershell files # + ########################### + elif [ "${FILE_TYPE}" == "ps1" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_POWERSHELL+=("${FILE}") + elif [ "${FILE_TYPE}" == "css" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_CSS+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "env" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_ENV+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "kt" ] || [ "${FILE_TYPE}" == "kts" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_KOTLIN+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "$FILE_TYPE" == "lua" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_LUA+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ############################ + # Get the Protocol Buffers files # + ############################ + elif [ "${FILE_TYPE}" == "dart" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_DART+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "proto" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PROTOBUF+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE}" == "dockerfile" ] || [ "${FILE_TYPE}" == "dockerfile" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_DOCKER+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "clj" ] || [ "${FILE_TYPE}" == "cljs" ] || [ "${FILE_TYPE}" == "cljc" ] || [ "${FILE_TYPE}" == "edn" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_CLOJURE+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "html" ]; then + ################################ + # Append the file to the array # + ##############################p## + FILE_ARRAY_HTML+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ] || [ "$FILE_TYPE" == "gradle" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_GROOVY+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + else + ############################################## + # Use file to see if we can parse what it is # + ############################################## + GET_FILE_TYPE_CMD=$(file "${FILE}" 2>&1) - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - fi - ###################### - # Get the JSON files # - ###################### - elif [ "${FILE_TYPE}" == "json" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_JSON+=("${FILE}") - ############################ - # Check if file is OpenAPI # - ############################ - if DetectOpenAPIFile "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_OPENAPI+=("${FILE}") - fi - ############################ - # Check if file is ARM # - ############################ - if DetectARMFile "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_ARM+=("${FILE}") - fi - ##################################### - # Check if the file is CFN template # - ##################################### - if DetectCloudFormationFile "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_CLOUDFORMATION+=("${FILE}") - fi - ############################################ - # Check if the file is AWS States Language # - ############################################ - if DetectAWSStatesFIle "${FILE}"; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_STATES+=("${FILE}") - fi - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ##################### - # Get the XML files # - ##################### - elif [ "${FILE_TYPE}" == "xml" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_XML+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ########################## - # Get the MARKDOWN files # - ########################## - elif [ "${FILE_TYPE}" == "md" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_MARKDOWN+=("${FILE}") - ###################### - # Get the BASH files # - ###################### - elif [ "${FILE_TYPE}" == "sh" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_BASH+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ###################### - # Get the PERL files # - ###################### - elif [ "${FILE_TYPE}" == "pl" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_PERL+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ###################### - # Get the RAKU files # - ###################### - elif [ "${FILE_TYPE}" == "raku" ] || [ "${FILE_TYPE}" == "rakumod" ] || - [ "${FILE_TYPE}" == "rakutest" ] || [ "${FILE_TYPE}" == "pm6" ] || - [ "${FILE_TYPE}" == "pl6" ] || [ "${FILE_TYPE}" == "p6" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_RAKU+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ###################### - # Get the PHP files # - ###################### - elif [ "${FILE_TYPE}" == "php" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_PHP+=("${FILE}") - FILE_ARRAY_PHP_PHPSTAN+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ###################### - # Get the RUBY files # - ###################### - elif [ "${FILE_TYPE}" == "rb" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_RUBY+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ######################## - # Get the PYTHON files # - ######################## - elif [ "${FILE_TYPE}" == "py" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_PYTHON_PYLINT+=("${FILE}") - FILE_ARRAY_PYTHON_FLAKE8+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ######################## - # Get the COFFEE files # - ######################## - elif [ "${FILE_TYPE}" == "coffee" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_COFFEESCRIPT+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 + ################# + # Check if bash # + ################# + if [[ ${GET_FILE_TYPE_CMD} == *"Bourne-Again shell script"* ]]; then + ####################### + # It is a bash script # + ####################### + warn "Found bash script without extension:[.sh]" + info "Please update file with proper extensions." + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_BASH+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + elif [[ ${GET_FILE_TYPE_CMD} == *"Ruby script"* ]]; then + ####################### + # It is a Ruby script # + ####################### + warn "Found ruby script without extension:[.rb]" + info "Please update file with proper extensions." + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_RUBY+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + else ############################ - # Get the JavaScript files # + # Extension was not found! # ############################ - elif [ "${FILE_TYPE}" == "js" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_JAVASCRIPT_ES+=("${FILE}") - FILE_ARRAY_JAVASCRIPT_STANDARD+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ############################ - # Get the JSX files # - ############################ - elif [ "${FILE_TYPE}" == "jsx" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_JSX+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ############################ - # Get the TSX files # - ############################ - elif [ "${FILE_TYPE}" == "tsx" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_TSX+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ######################## - # Get the Golang files # - ######################## - ############################ - # Get the TypeScript files # - ############################ - elif [ "${FILE_TYPE}" == "ts" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_TYPESCRIPT_ES+=("${FILE}") - FILE_ARRAY_TYPESCRIPT_STANDARD+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ######################## - # Get the Golang files # - ######################## - elif [ "${FILE_TYPE}" == "go" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_GO+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ########################### - # Get the Terraform files # - ########################### - elif [ "${FILE_TYPE}" == "tf" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_TERRAFORM+=("${FILE}") - FILE_ARRAY_TERRAFORM_TERRASCAN+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ########################### - # Get the Powershell files # - ########################### - elif [ "${FILE_TYPE}" == "ps1" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_POWERSHELL+=("${FILE}") - elif [ "${FILE_TYPE}" == "css" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_CSS+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "env" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_ENV+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "kt" ] || [ "${FILE_TYPE}" == "kts" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_KOTLIN+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "$FILE_TYPE" == "lua" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_LUA+=("$FILE") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - ############################ - # Get the Protocol Buffers files # - ############################ - elif [ "${FILE_TYPE}" == "dart" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_DART+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "proto" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_PROTOBUF+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE}" == "dockerfile" ] || [ "${FILE_TYPE}" == "dockerfile" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_DOCKER+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "clj" ] || [ "${FILE_TYPE}" == "cljs" ] || [ "${FILE_TYPE}" == "cljc" ] || [ "${FILE_TYPE}" == "edn" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_CLOJURE+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "${FILE_TYPE}" == "html" ]; then - ################################ - # Append the file to the array # - ##############################p## - FILE_ARRAY_HTML+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ] || [ "$FILE_TYPE" == "gradle" ]; then - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_GROOVY+=("$FILE") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - else - ############################################## - # Use file to see if we can parse what it is # - ############################################## - GET_FILE_TYPE_CMD=$(file "${FILE}" 2>&1) - - ################# - # Check if bash # - ################# - if [[ ${GET_FILE_TYPE_CMD} == *"Bourne-Again shell script"* ]]; then - ####################### - # It is a bash script # - ####################### - warn "Found bash script without extension:[.sh]" - info "Please update file with proper extensions." - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_BASH+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - elif [[ ${GET_FILE_TYPE_CMD} == *"Ruby script"* ]]; then - ####################### - # It is a Ruby script # - ####################### - warn "Found ruby script without extension:[.rb]" - info "Please update file with proper extensions." - ################################ - # Append the file to the array # - ################################ - FILE_ARRAY_RUBY+=("${FILE}") - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - else - ############################ - # Extension was not found! # - ############################ - warn "Failed to get filetype for:[${FILE}]!" - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 - fi - fi - done - - export READ_ONLY_CHANGE_FLAG # Workaround SC2034 - - ######################################### - # Need to switch back to branch of code # - ######################################### - SWITCH2_CMD=$(git -C "${GITHUB_WORKSPACE}" 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 - error "Failed to switch back to branch!" - fatal "[${SWITCH2_CMD}]" + warn "Failed to get filetype for:[${FILE}]!" + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + fi fi + done - ################ - # Footer print # - ################ - info "----------------------------------------------" - info "Successfully gathered list of files..." + export READ_ONLY_CHANGE_FLAG # Workaround SC2034 + + ######################################### + # Need to switch back to branch of code # + ######################################### + SWITCH2_CMD=$(git -C "${GITHUB_WORKSPACE}" 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 + error "Failed to switch back to branch!" + fatal "[${SWITCH2_CMD}]" + fi + + ################ + # Footer print # + ################ + info "----------------------------------------------" + info "Successfully gathered list of files..." } diff --git a/lib/linter.sh b/lib/linter.sh index 231fa185..6327f7cb 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -75,7 +75,7 @@ OPENAPI_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${OPENAPI_FILE_NAME}" # Path to PHPSTAN_FILE_NAME='phpstan.neon' # Name of the file PHPSTAN_LINTER_RULES="${GITHUB_WORKSPACE}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules in the repository if [ ! -f "$PHPSTAN_LINTER_RULES" ]; then - PHPSTAN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules + PHPSTAN_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PHPSTAN_FILE_NAME}" # Path to the PHPStan lint rules fi # Powershell Vars POWERSHELL_FILE_NAME='.powershell-psscriptanalyzer.psd1' # Name of the file @@ -106,19 +106,19 @@ 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' 'cfn-lint' 'clj-kondo' 'coffeelint' - 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'flake8' 'golangci-lint' 'htmlhint' - 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' - 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'terrascan' - 'tflint' 'xmllint' 'yamllint') + 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'flake8' 'golangci-lint' 'htmlhint' + 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' + 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'terrascan' + 'tflint' 'xmllint' 'yamllint') ############################# # Language array for prints # ############################# LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CSS' - 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' - 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP' 'PHP_PHPSTAN' 'POWERSHELL' - 'PROTOBUF' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' - 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YML') + 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' + 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP' 'PHP_PHPSTAN' 'POWERSHELL' + 'PROTOBUF' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' + 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YML') ############################################ # Array for all languages that were linted # @@ -360,502 +360,560 @@ export ERRORS_FOUND_YAML # Workaround SC2034 ################################################################################ #### Function Header ########################################################### Header() { - ############################### - # Give them the possum action # - ############################### - /bin/bash /action/lib/possum.sh + ############################### + # Give them the possum action # + ############################### + /bin/bash /action/lib/possum.sh - ########## - # Prints # - ########## - info "---------------------------------------------" - info "--- GitHub Actions Multi Language Linter ----" - info "---------------------------------------------" - info "---------------------------------------------" - info "The Super-Linter source code can be found at:" - info " - https://github.com/github/super-linter" - info "---------------------------------------------" + ########## + # Prints # + ########## + info "---------------------------------------------" + info "--- GitHub Actions Multi Language Linter ----" + info "---------------------------------------------" + info "---------------------------------------------" + info "The Super-Linter source code can be found at:" + info " - https://github.com/github/super-linter" + info "---------------------------------------------" } ################################################################################ #### Function GetLinterVersions ################################################ GetLinterVersions() { - ######################### - # Print version headers # - ######################### - debug "---------------------------------------------" - debug "Linter Version Info:" + ######################### + # Print version headers # + ######################### + debug "---------------------------------------------" + debug "Linter Version Info:" - ########################################################## - # Go through the array of linters and print version info # - ########################################################## - for LINTER in "${LINTER_ARRAY[@]}"; do - #################### - # Get the versions # - #################### - if [[ ${LINTER} == "arm-ttk" ]]; then - # Need specific command for ARM - mapfile -t GET_VERSION_CMD < <(grep -iE 'version' "${ARM_TTK_PSD1}" | xargs 2>&1) - elif [[ ${LINTER} == "protolint" ]]; then - # Need specific command for Protolint - mapfile -t GET_VERSION_CMD < <(echo "--version not supported") - else - # Standard version command - mapfile -t GET_VERSION_CMD < <("${LINTER}" --version 2>&1) - fi + ########################################################## + # Go through the array of linters and print version info # + ########################################################## + for LINTER in "${LINTER_ARRAY[@]}"; do + #################### + # Get the versions # + #################### + if [[ ${LINTER} == "arm-ttk" ]]; then + # Need specific command for ARM + mapfile -t GET_VERSION_CMD < <(grep -iE 'version' "${ARM_TTK_PSD1}" | xargs 2>&1) + elif [[ ${LINTER} == "protolint" ]]; then + # Need specific command for Protolint + mapfile -t GET_VERSION_CMD < <(echo "--version not supported") + else + # Standard version command + mapfile -t GET_VERSION_CMD < <("${LINTER}" --version 2>&1) + fi - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then - warn "[${LINTER}]: Failed to get version info for:" - else - ########################## - # Print the version info # - ########################## - debug "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}" - fi - done + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then + warn "[${LINTER}]: Failed to get version info for:" + else + ########################## + # Print the version info # + ########################## + debug "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}" + fi + done - ######################### - # Print version footers # - ######################### - debug "---------------------------------------------" + ######################### + # Print version footers # + ######################### + debug "---------------------------------------------" } ################################################################################ #### Function GetLinterRules ################################################### GetLinterRules() { - # Need to validate the rules files exist + # Need to validate the rules files exist - ################ - # Pull in vars # - ################ - LANGUAGE_NAME="${1}" # Name of the language were looking for + ################ + # Pull in vars # + ################ + LANGUAGE_NAME="${1}" # Name of the language were looking for - ####################################################### - # Need to create the variables for the real variables # - ####################################################### - LANGUAGE_FILE_NAME="${LANGUAGE_NAME}_FILE_NAME" - LANGUAGE_LINTER_RULES="${LANGUAGE_NAME}_LINTER_RULES" + ####################################################### + # Need to create the variables for the real variables # + ####################################################### + LANGUAGE_FILE_NAME="${LANGUAGE_NAME}_FILE_NAME" + LANGUAGE_LINTER_RULES="${LANGUAGE_NAME}_LINTER_RULES" - ##################################### - # Validate we have the linter rules # - ##################################### - if [ -f "${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" ]; then - info "----------------------------------------------" - info "User provided file:[${!LANGUAGE_FILE_NAME}], setting rules file..." + ##################################### + # Validate we have the linter rules # + ##################################### + if [ -f "${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" ]; then + info "----------------------------------------------" + info "User provided file:[${!LANGUAGE_FILE_NAME}], setting rules file..." - ######################################## - # Update the path to the file location # - ######################################## - eval "${LANGUAGE_LINTER_RULES}=${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" - else - ######################################################## - # No user default provided, using the template default # - ######################################################## - debug " -> Codebase does NOT have file:[${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]" - fi + ######################################## + # Update the path to the file location # + ######################################## + eval "${LANGUAGE_LINTER_RULES}=${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}" + else + ######################################################## + # No user default provided, using the template default # + ######################################################## + debug " -> Codebase does NOT have file:[${LINTER_RULES_PATH}/${!LANGUAGE_FILE_NAME}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]" + fi } ################################################################################ #### Function GetStandardRules ################################################# GetStandardRules() { - ################ - # Pull In Vars # - ################ - LINTER="${1}" # Type: javascript | typescript + ################ + # Pull In Vars # + ################ + LINTER="${1}" # Type: javascript | typescript - ######################################################################### - # Need to get the ENV vars from the linter rules to run in command line # - ######################################################################### - # Copy orig IFS to var - ORIG_IFS="${IFS}" - # Set the IFS to newline - IFS=$'\n' + ######################################################################### + # Need to get the ENV vars from the linter rules to run in command line # + ######################################################################### + # Copy orig IFS to var + ORIG_IFS="${IFS}" + # Set the IFS to newline + IFS=$'\n' - ######################################### - # Get list of all environment variables # - ######################################### - # Only env vars that are marked as true - GET_ENV_ARRAY=() - if [[ ${LINTER} == "javascript" ]]; then - mapfile -t GET_ENV_ARRAY < <(yq .env "${JAVASCRIPT_LINTER_RULES}" | grep true) - elif [[ ${LINTER} == "typescript" ]]; then - mapfile -t GET_ENV_ARRAY < <(yq .env "${TYPESCRIPT_LINTER_RULES}" | grep true) - fi + ######################################### + # Get list of all environment variables # + ######################################### + # Only env vars that are marked as true + GET_ENV_ARRAY=() + if [[ ${LINTER} == "javascript" ]]; then + mapfile -t GET_ENV_ARRAY < <(yq .env "${JAVASCRIPT_LINTER_RULES}" | grep true) + elif [[ ${LINTER} == "typescript" ]]; then + mapfile -t GET_ENV_ARRAY < <(yq .env "${TYPESCRIPT_LINTER_RULES}" | grep true) + fi - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # ERROR - error "Failed to gain list of ENV vars to load!" - fatal "[${GET_ENV_ARRAY[*]}]" - fi + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # ERROR + error "Failed to gain list of ENV vars to load!" + fatal "[${GET_ENV_ARRAY[*]}]" + fi - ########################## - # Set IFS back to normal # - ########################## - # Set IFS back to Orig - IFS="${ORIG_IFS}" + ########################## + # Set IFS back to normal # + ########################## + # Set IFS back to Orig + IFS="${ORIG_IFS}" - ###################### - # Set the env string # - ###################### - ENV_STRING='' + ###################### + # Set the env string # + ###################### + ENV_STRING='' + ############################# + # Pull out the envs to load # + ############################# + for ENV in "${GET_ENV_ARRAY[@]}"; do ############################# - # Pull out the envs to load # + # remove spaces from return # ############################# - for ENV in "${GET_ENV_ARRAY[@]}"; do - ############################# - # remove spaces from return # - ############################# - ENV="$(echo -e "${ENV}" | tr -d '[:space:]')" - ################################ - # Get the env to add to string # - ################################ - ENV="$(echo "${ENV}" | cut -d'"' -f2)" - debug "ENV:[${ENV}]" - ENV_STRING+="--env ${ENV} " - done + ENV="$(echo -e "${ENV}" | tr -d '[:space:]')" + ################################ + # Get the env to add to string # + ################################ + ENV="$(echo "${ENV}" | cut -d'"' -f2)" + debug "ENV:[${ENV}]" + ENV_STRING+="--env ${ENV} " + done - ######################################### - # Remove trailing and ending whitespace # - ######################################### - if [[ ${LINTER} == "javascript" ]]; then - JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" - elif [[ ${LINTER} == "typescript" ]]; then - TYPESCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" - fi + ######################################### + # Remove trailing and ending whitespace # + ######################################### + if [[ ${LINTER} == "javascript" ]]; then + JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + elif [[ ${LINTER} == "typescript" ]]; then + TYPESCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + fi } ################################################################################ #### Function DetectOpenAPIFile ################################################ DetectOpenAPIFile() { - ################ - # Pull in vars # - ################ - FILE="${1}" + ################ + # Pull in vars # + ################ + FILE="${1}" - ############################### - # Check the file for keywords # - ############################### - grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "${FILE}" > /dev/null + ############################### + # Check the file for keywords # + ############################### + grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "${FILE}" > /dev/null - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -eq 0 ]; then - ######################## - # Found string in file # - ######################## - return 0 - else - ################### - # No string match # - ################### - return 1 - fi + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -eq 0 ]; then + ######################## + # Found string in file # + ######################## + return 0 + else + ################### + # No string match # + ################### + return 1 + fi } ################################################################################ #### Function DetectARMFile #################################################### DetectARMFile() { - ################ - # Pull in vars # - ################ - FILE="${1}" # Name of the file/path we are validating + ################ + # Pull in vars # + ################ + FILE="${1}" # Name of the file/path we are validating - ############################### - # Check the file for keywords # - ############################### - grep -E 'schema.management.azure.com' "${FILE}" > /dev/null + ############################### + # Check the file for keywords # + ############################### + grep -E 'schema.management.azure.com' "${FILE}" > /dev/null - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -eq 0 ]; then - ######################## - # Found string in file # - ######################## - return 0 - else - ################### - # No string match # - ################### - return 1 - fi + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -eq 0 ]; then + ######################## + # Found string in file # + ######################## + return 0 + else + ################### + # No string match # + ################### + return 1 + fi } ################################################################################ #### Function DetectCloudFormationFile ######################################### DetectCloudFormationFile() { - ################ - # Pull in Vars # - ################ - FILE="${1}" # File that we need to validate + ################ + # Pull in Vars # + ################ + FILE="${1}" # File that we need to validate - # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-formats.html - # AWSTemplateFormatVersion is optional - ####################################### - # Check if file has AWS Template info # - ####################################### - if grep -q 'AWSTemplateFormatVersion' "${FILE}" > /dev/null; then - # Found it - return 0 - fi + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-formats.html + # AWSTemplateFormatVersion is optional + ####################################### + # Check if file has AWS Template info # + ####################################### + if grep -q 'AWSTemplateFormatVersion' "${FILE}" > /dev/null; then + # Found it + return 0 + fi - ##################################### - # See if it contains AWS References # - ##################################### - if grep -q -E '(AWS|Alexa|Custom)::' "${FILE}" > /dev/null; then - # Found it - return 0 - fi + ##################################### + # See if it contains AWS References # + ##################################### + if grep -q -E '(AWS|Alexa|Custom)::' "${FILE}" > /dev/null; then + # Found it + return 0 + fi - ##################################################### - # No identifiers of a CLOUDFORMATION template found # - ##################################################### - return 1 + ##################################################### + # No identifiers of a CLOUDFORMATION template found # + ##################################################### + return 1 } ################################################################################ #### Function DetectAWSStatesFIle ############################################## DetectAWSStatesFIle() { - ################ - # Pull in Vars # - ################ - FILE="${1}" # File that we need to validate + ################ + # Pull in Vars # + ################ + FILE="${1}" # File that we need to validate - # https://states-language.net/spec.html#example - ############################### - # check if file has resources # - ############################### - if grep '"Resource": *"arn"*' "${FILE}"; then - # Found it - return 0 - fi + # https://states-language.net/spec.html#example + ############################### + # check if file has resources # + ############################### + if grep '"Resource": *"arn"*' "${FILE}"; then + # Found it + return 0 + fi - ################################################# - # No identifiers of a AWS States Language found # - ################################################# - return 1 + ################################################# + # No identifiers of a AWS States Language found # + ################################################# + return 1 } ################################################################################ #### Function GetGitHubVars #################################################### GetGitHubVars() { - ########## - # Prints # - ########## - info "--------------------------------------------" - info "Gathering GitHub information..." + ########## + # Prints # + ########## + info "--------------------------------------------" + info "Gathering GitHub information..." - ############################### - # Get the Run test cases flag # - ############################### - if [ -z "${TEST_CASE_RUN}" ]; then - ################################## - # No flag passed, set to default # - ################################## - TEST_CASE_RUN="${DEFAULT_TEST_CASE_RUN}" + ############################### + # Get the Run test cases flag # + ############################### + if [ -z "${TEST_CASE_RUN}" ]; then + ################################## + # No flag passed, set to default # + ################################## + TEST_CASE_RUN="${DEFAULT_TEST_CASE_RUN}" + fi + + ############################### + # Convert string to lowercase # + ############################### + TEST_CASE_RUN="${TEST_CASE_RUN,,}" + + ########################## + # Get the run local flag # + ########################## + if [ -z "${RUN_LOCAL}" ]; then + ################################## + # No flag passed, set to default # + ################################## + RUN_LOCAL="${DEFAULT_RUN_LOCAL}" + fi + + ############################### + # Convert string to lowercase # + ############################### + RUN_LOCAL="${RUN_LOCAL,,}" + + ################################# + # Check if were running locally # + ################################# + if [[ ${RUN_LOCAL} != "false" ]]; then + ########################################## + # We are running locally for a debug run # + ########################################## + info "NOTE: ENV VAR [RUN_LOCAL] has been set to:[true]" + info "bypassing GitHub Actions variables..." + + ############################ + # Set the GITHUB_WORKSPACE # + ############################ + if [ -z "${GITHUB_WORKSPACE}" ]; then + GITHUB_WORKSPACE="${DEFAULT_WORKSPACE}" fi - ############################### - # Convert string to lowercase # - ############################### - TEST_CASE_RUN="${TEST_CASE_RUN,,}" - - ########################## - # Get the run local flag # - ########################## - if [ -z "${RUN_LOCAL}" ]; then - ################################## - # No flag passed, set to default # - ################################## - RUN_LOCAL="${DEFAULT_RUN_LOCAL}" + if [ ! -d "${GITHUB_WORKSPACE}" ]; then + fatal "Provided volume is not a directory!" fi - ############################### - # Convert string to lowercase # - ############################### - RUN_LOCAL="${RUN_LOCAL,,}" + info "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]" + + # No need to touch or set the GITHUB_SHA + # No need to touch or set the GITHUB_EVENT_PATH + # No need to touch or set the GITHUB_ORG + # No need to touch or set the GITHUB_REPO ################################# - # Check if were running locally # + # Set the VALIDATE_ALL_CODEBASE # ################################# - if [[ ${RUN_LOCAL} != "false" ]]; then - ########################################## - # We are running locally for a debug run # - ########################################## - info "NOTE: ENV VAR [RUN_LOCAL] has been set to:[true]" - info "bypassing GitHub Actions variables..." - - ############################ - # Set the GITHUB_WORKSPACE # - ############################ - if [ -z "${GITHUB_WORKSPACE}" ]; then - GITHUB_WORKSPACE="${DEFAULT_WORKSPACE}" - fi - - if [ ! -d "${GITHUB_WORKSPACE}" ]; then - fatal "Provided volume is not a directory!" - fi - - info "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]" - - # No need to touch or set the GITHUB_SHA - # No need to touch or set the GITHUB_EVENT_PATH - # No need to touch or set the GITHUB_ORG - # No need to touch or set the GITHUB_REPO - - ################################# - # Set the VALIDATE_ALL_CODEBASE # - ################################# - VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" + VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" + else + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_SHA}" ]; then + error "Failed to get [GITHUB_SHA]!" + fatal "[${GITHUB_SHA}]" else - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_SHA}" ]; then - error "Failed to get [GITHUB_SHA]!" - fatal "[${GITHUB_SHA}]" - else - info "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]" - fi - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_WORKSPACE}" ]; then - error "Failed to get [GITHUB_WORKSPACE]!" - fatal "[${GITHUB_WORKSPACE}]" - else - info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]" - fi - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_EVENT_PATH}" ]; then - error "Failed to get [GITHUB_EVENT_PATH]!" - fatal "[${GITHUB_EVENT_PATH}]" - else - info "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}" - fi - - ################################################## - # Need to pull the GitHub Vars from the env file # - ################################################## - - ###################### - # Get the GitHub Org # - ###################### - GITHUB_ORG=$(jq -r '.repository.owner.login' < "${GITHUB_EVENT_PATH}") - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_ORG}" ]; then - error "Failed to get [GITHUB_ORG]!" - fatal "[${GITHUB_ORG}]" - else - info "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]" - fi - - ####################### - # Get the GitHub Repo # - ####################### - GITHUB_REPO=$(jq -r '.repository.name' < "${GITHUB_EVENT_PATH}") - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_REPO}" ]; then - error "Failed to get [GITHUB_REPO]!" - fatal "[${GITHUB_REPO}]" - else - info "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]" - fi + info "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]" fi ############################ # Validate we have a value # ############################ - if [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then - error "Failed to get [GITHUB_TOKEN]!" - error "[${GITHUB_TOKEN}]" - error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!" - - ################################################################################ - # Need to set MULTI_STATUS to false as we cant hit API endpoints without token # - ################################################################################ - MULTI_STATUS='false' + if [ -z "${GITHUB_WORKSPACE}" ]; then + error "Failed to get [GITHUB_WORKSPACE]!" + fatal "[${GITHUB_WORKSPACE}]" else - info "Successfully found:${F[W]}[GITHUB_TOKEN]" + info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]" fi - ############################### - # Convert string to lowercase # - ############################### - MULTI_STATUS="${MULTI_STATUS,,}" - - ####################################################################### - # Check to see if the multi status is set, and we have a token to use # - ####################################################################### - if [ "${MULTI_STATUS}" == "true" ] && [ -n "${GITHUB_TOKEN}" ]; then - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_REPOSITORY}" ]; then - error "Failed to get [GITHUB_REPOSITORY]!" - fatal "[${GITHUB_REPOSITORY}]" - else - info "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]" - fi - - ############################ - # Validate we have a value # - ############################ - if [ -z "${GITHUB_RUN_ID}" ]; then - error "Failed to get [GITHUB_RUN_ID]!" - fatal "[${GITHUB_RUN_ID}]" - else - info "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]" - fi + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_EVENT_PATH}" ]; then + error "Failed to get [GITHUB_EVENT_PATH]!" + fatal "[${GITHUB_EVENT_PATH}]" + else + info "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}" fi + + ################################################## + # Need to pull the GitHub Vars from the env file # + ################################################## + + ###################### + # Get the GitHub Org # + ###################### + GITHUB_ORG=$(jq -r '.repository.owner.login' < "${GITHUB_EVENT_PATH}") + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_ORG}" ]; then + error "Failed to get [GITHUB_ORG]!" + fatal "[${GITHUB_ORG}]" + else + info "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]" + fi + + ####################### + # Get the GitHub Repo # + ####################### + GITHUB_REPO=$(jq -r '.repository.name' < "${GITHUB_EVENT_PATH}") + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_REPO}" ]; then + error "Failed to get [GITHUB_REPO]!" + fatal "[${GITHUB_REPO}]" + else + info "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]" + fi + fi + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then + error "Failed to get [GITHUB_TOKEN]!" + error "[${GITHUB_TOKEN}]" + error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!" + + ################################################################################ + # Need to set MULTI_STATUS to false as we cant hit API endpoints without token # + ################################################################################ + MULTI_STATUS='false' + else + info "Successfully found:${F[W]}[GITHUB_TOKEN]" + fi + + ############################### + # Convert string to lowercase # + ############################### + MULTI_STATUS="${MULTI_STATUS,,}" + + ####################################################################### + # Check to see if the multi status is set, and we have a token to use # + ####################################################################### + if [ "${MULTI_STATUS}" == "true" ] && [ -n "${GITHUB_TOKEN}" ]; then + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_REPOSITORY}" ]; then + error "Failed to get [GITHUB_REPOSITORY]!" + fatal "[${GITHUB_REPOSITORY}]" + else + info "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]" + fi + + ############################ + # Validate we have a value # + ############################ + if [ -z "${GITHUB_RUN_ID}" ]; then + error "Failed to get [GITHUB_RUN_ID]!" + fatal "[${GITHUB_RUN_ID}]" + else + info "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]" + fi + fi } ################################################################################ #### Function ValidatePowershellModules ######################################## function ValidatePowershellModules() { - VALIDATE_PSSA_MODULE=$(pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>&1) - # If module found, ensure Invoke-ScriptAnalyzer command is available - if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]]; then - VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1) - else - fatal "Failed to find module." - fi + VALIDATE_PSSA_MODULE=$(pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>&1) + # If module found, ensure Invoke-ScriptAnalyzer command is available + if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]]; then + VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1) + else + fatal "Failed to find module." + fi - ######################################### - # validate we found the script analyzer # - ######################################### - if [[ ${VALIDATE_PSSA_CMD} != "Invoke-ScriptAnalyzer" ]]; then - fatal "Failed to find module." - fi + ######################################### + # validate we found the script analyzer # + ######################################### + if [[ ${VALIDATE_PSSA_CMD} != "Invoke-ScriptAnalyzer" ]]; then + fatal "Failed to find module." + fi + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Failed + error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!" + fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]" + else + # Success + debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system" + debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system" + fi +} +################################################################################ +#### Function CallStatusAPI #################################################### +CallStatusAPI() { + #################### + # Pull in the vars # + #################### + LANGUAGE="${1}" # langauge that was validated + STATUS="${2}" # success | error + SUCCESS_MSG='No errors were found in the linting process' + FAIL_MSG='Errors were detected, please view logs' + MESSAGE='' # Message to send to status API + + ###################################### + # Check the status to create message # + ###################################### + if [ "${STATUS}" == "success" ]; then + # Success + MESSAGE="${SUCCESS_MSG}" + else + # Failure + MESSAGE="${FAIL_MSG}" + fi + + ########################################################## + # Check to see if were enabled for multi Status mesaages # + ########################################################## + if [ "${MULTI_STATUS}" == "true" ]; then + ############################################## + # Call the status API to create status check # + ############################################## + SEND_STATUS_CMD=$(curl -f -s -X POST \ + --url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}" \ + -H 'accept: application/vnd.github.v3+json' \ + -H "authorization: Bearer ${GITHUB_TOKEN}" \ + -H 'content-type: application/json' \ + -d "{ \"state\": \"${STATUS}\", + \"target_url\": \"https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\", + \"description\": \"${MESSAGE}\", \"context\": \"--> Linted: ${LANGUAGE}\" + }" 2>&1) ####################### # Load the error code # @@ -865,182 +923,124 @@ function ValidatePowershellModules() { ############################## # Check the shell for errors # ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Failed - error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!" - fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]" - else - # Success - debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system" - debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system" - fi -} -################################################################################ -#### Function CallStatusAPI #################################################### -CallStatusAPI() { - #################### - # Pull in the vars # - #################### - LANGUAGE="${1}" # langauge that was validated - STATUS="${2}" # success | error - SUCCESS_MSG='No errors were found in the linting process' - FAIL_MSG='Errors were detected, please view logs' - MESSAGE='' # Message to send to status API - - ###################################### - # Check the status to create message # - ###################################### - if [ "${STATUS}" == "success" ]; then - # Success - MESSAGE="${SUCCESS_MSG}" - else - # Failure - MESSAGE="${FAIL_MSG}" - fi - - ########################################################## - # Check to see if were enabled for multi Status mesaages # - ########################################################## - if [ "${MULTI_STATUS}" == "true" ]; then - ############################################## - # Call the status API to create status check # - ############################################## - SEND_STATUS_CMD=$(curl -f -s -X POST \ - --url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}" \ - -H 'accept: application/vnd.github.v3+json' \ - -H "authorization: Bearer ${GITHUB_TOKEN}" \ - -H 'content-type: application/json' \ - -d "{ \"state\": \"${STATUS}\", - \"target_url\": \"https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\", - \"description\": \"${MESSAGE}\", \"context\": \"--> Linted: ${LANGUAGE}\" - }" 2>&1) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ "${ERROR_CODE}" -ne 0 ]; then - # ERROR - info "ERROR! Failed to call GitHub Status API!" - info "ERROR:[${SEND_STATUS_CMD}]" - # Not going to fail the script on this yet... - fi + if [ "${ERROR_CODE}" -ne 0 ]; then + # ERROR + info "ERROR! Failed to call GitHub Status API!" + info "ERROR:[${SEND_STATUS_CMD}]" + # Not going to fail the script on this yet... fi + fi } ################################################################################ #### Function Reports ########################################################## Reports() { - info "----------------------------------------------" - info "----------------------------------------------" - info "Generated reports:" - info "----------------------------------------------" - info "----------------------------------------------" + info "----------------------------------------------" + info "----------------------------------------------" + info "Generated reports:" + info "----------------------------------------------" + info "----------------------------------------------" - ################################### - # Prints output report if enabled # - ################################### - if [ -z "${FORMAT_REPORT}" ]; then - info "Reports generated in folder ${REPORT_OUTPUT_FOLDER}" - fi + ################################### + # Prints output report if enabled # + ################################### + if [ -z "${FORMAT_REPORT}" ]; then + info "Reports generated in folder ${REPORT_OUTPUT_FOLDER}" + fi - ################################ - # Prints for warnings if found # - ################################ - for TEST in "${WARNING_ARRAY_TEST[@]}"; do - warn "Expected file to compare with was not found for ${TEST}" - done + ################################ + # Prints for warnings if found # + ################################ + for TEST in "${WARNING_ARRAY_TEST[@]}"; do + warn "Expected file to compare with was not found for ${TEST}" + done } ################################################################################ #### Function Footer ########################################################### Footer() { - info "----------------------------------------------" - info "----------------------------------------------" - info "The script has completed" - info "----------------------------------------------" - info "----------------------------------------------" + info "----------------------------------------------" + info "----------------------------------------------" + info "The script has completed" + info "----------------------------------------------" + info "----------------------------------------------" - #################################################### - # Need to clean up the lanuage array of duplicates # - #################################################### - mapfile -t UNIQUE_LINTED_ARRAY < <(echo "${LINTED_LANGUAGES_ARRAY[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ') + #################################################### + # Need to clean up the lanuage array of duplicates # + #################################################### + mapfile -t UNIQUE_LINTED_ARRAY < <(echo "${LINTED_LANGUAGES_ARRAY[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ') - ############################## - # Prints for errors if found # - ############################## - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - ########################### - # Build the error counter # - ########################### - ERROR_COUNTER="ERRORS_FOUND_${LANGUAGE}" + ############################## + # 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 - # We found errors in the language - ################### - # Print the goods # - ################### - error "ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]" + ################## + # Print if not 0 # + ################## + if [[ ${!ERROR_COUNTER} -ne 0 ]]; then + # We found errors in the language + ################### + # Print the goods # + ################### + error "ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]" - ######################################### - # Create status API for Failed language # - ######################################### - CallStatusAPI "${LANGUAGE}" "error" - ###################################### - # Check if we validated the langauge # - ###################################### - elif [[ ${!ERROR_COUNTER} -eq 0 ]] && [[ ${UNIQUE_LINTED_ARRAY[*]} =~ ${LANGUAGE} ]]; then - # No errors found when linting the language - CallStatusAPI "${LANGUAGE}" "success" - fi - done - - ################################## - # Exit with 0 if errors disabled # - ################################## - if [ "${DISABLE_ERRORS}" == "true" ]; then - warn "Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]" - exit 0 + ######################################### + # Create status API for Failed language # + ######################################### + CallStatusAPI "${LANGUAGE}" "error" + ###################################### + # Check if we validated the langauge # + ###################################### + elif [[ ${!ERROR_COUNTER} -eq 0 ]] && [[ ${UNIQUE_LINTED_ARRAY[*]} =~ ${LANGUAGE} ]]; then + # No errors found when linting the language + CallStatusAPI "${LANGUAGE}" "success" fi + done - ############################### - # Exit with 1 if errors found # - ############################### - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - ERRORS_FOUND_LANGUAGE="ERRORS_FOUND_${LANGUAGE}" - # Check if error was found - if [[ ${!ERRORS_FOUND_LANGUAGE} -ne 0 ]]; then - # Failed exit - fatal "Exiting with errors found!" - fi - done - - ######################## - # Footer prints Exit 0 # - ######################## - notice "All file(s) linted successfully with no errors detected" - info "----------------------------------------------" - # Successful exit + ################################## + # Exit with 0 if errors disabled # + ################################## + if [ "${DISABLE_ERRORS}" == "true" ]; then + warn "Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]" exit 0 + fi + + ############################### + # Exit with 1 if errors found # + ############################### + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + ERRORS_FOUND_LANGUAGE="ERRORS_FOUND_${LANGUAGE}" + # Check if error was found + if [[ ${!ERRORS_FOUND_LANGUAGE} -ne 0 ]]; then + # Failed exit + fatal "Exiting with errors found!" + fi + done + + ######################## + # Footer prints Exit 0 # + ######################## + notice "All file(s) linted successfully with no errors detected" + info "----------------------------------------------" + # Successful exit + exit 0 } ################################################################################ #### Function Cleanup ########################################################## cleanup() { - local -ri EXIT_CODE=$? + local -ri EXIT_CODE=$? - sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/${LOG_FILE}" || true + sh -c "cat ${LOG_TEMP} >> ${GITHUB_WORKSPACE}/${LOG_FILE}" || true - exit ${EXIT_CODE} - trap - 0 1 2 3 6 14 15 + exit ${EXIT_CODE} + trap - 0 1 2 3 6 14 15 } trap 'cleanup' 0 1 2 3 6 14 15 @@ -1057,10 +1057,10 @@ Header # check flag for validating the report folder does not exist # ############################################################## if [ -n "${OUTPUT_FORMAT}" ]; then - if [ -d "${REPORT_OUTPUT_FOLDER}" ]; then - error "ERROR! Found ${REPORT_OUTPUT_FOLDER}" - fatal "Please remove the folder and try again." - fi + if [ -d "${REPORT_OUTPUT_FOLDER}" ]; then + error "ERROR! Found ${REPORT_OUTPUT_FOLDER}" + fatal "Please remove the folder and try again." + fi fi ####################### @@ -1129,560 +1129,560 @@ GetLinterVersions ########################################### if [[ ${TEST_CASE_RUN} != "false" ]]; then - ############################################# - # Set the multi status to off for test runs # - ############################################# - MULTI_STATUS='false' + ############################################# + # Set the multi status to off for test runs # + ############################################# + MULTI_STATUS='false' - ########################### - # Run only the test cases # - ########################### - # Code will exit from inside this loop - RunTestCases + ########################### + # Run only the test cases # + ########################### + # Code will exit from inside this loop + RunTestCases fi ############################################# # check flag for validation of all codebase # ############################################# if [ "${VALIDATE_ALL_CODEBASE}" == "false" ]; then - ######################################## - # Get list of files changed if env set # - ######################################## - BuildFileList + ######################################## + # Get list of files changed if env set # + ######################################## + BuildFileList fi ################### # ANSIBLE LINTING # ################### if [ "${VALIDATE_ANSIBLE}" == "true" ]; then - ########################## - # Lint the Ansible files # - ########################## - # Due to the nature of how we want to validate Ansible, we cannot use the - # standard loop, since it looks for an ansible folder, excludes certain - # files, and looks for additional changes, it should be an outlier - LintAnsibleFiles "${ANSIBLE_LINTER_RULES}" # Passing rules but not needed, dont want to exclude unused var + ########################## + # Lint the Ansible files # + ########################## + # Due to the nature of how we want to validate Ansible, we cannot use the + # standard loop, since it looks for an ansible folder, excludes certain + # files, and looks for additional changes, it should be an outlier + LintAnsibleFiles "${ANSIBLE_LINTER_RULES}" # Passing rules but not needed, dont want to exclude unused var fi ######################## # ARM Template LINTING # ######################## if [ "${VALIDATE_ARM}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every json file is an ARM file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' + # If we are validating all codebase we need to build file list because not every json file is an ARM file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectARMFile "${FILE}"; then - FILE_ARRAY_ARM+=("${FILE}") - fi - done + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectARMFile "${FILE}"; then + FILE_ARRAY_ARM+=("${FILE}") + fi + done - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi - ############################### - # Lint the ARM Template files # - ############################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" "disabledfileext" "${FILE_ARRAY_ARM[@]}" + ############################### + # Lint the ARM Template files # + ############################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" "disabledfileext" "${FILE_ARRAY_ARM[@]}" fi ################ # BASH LINTING # ################ if [ "${VALIDATE_BASH}" == "true" ]; then - ####################### - # Lint the bash files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "BASH" "shellcheck" "shellcheck --color" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" + ####################### + # Lint the bash files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "BASH" "shellcheck" "shellcheck --color" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" fi ########################## # CLOUDFORMATION LINTING # ########################## if [ "${VALIDATE_CLOUDFORMATION}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every yml/json file is an CLOUDFORMATION file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' + # If we are validating all codebase we need to build file list because not every yml/json file is an CLOUDFORMATION file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectCloudFormationFile "${FILE}"; then - FILE_ARRAY_CLOUDFORMATION+=("${FILE}") - fi - done + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectCloudFormationFile "${FILE}"; then + FILE_ARRAY_CLOUDFORMATION+=("${FILE}") + fi + done - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi - ################################# - # Lint the CloudFormation files # - ################################# - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "CLOUDFORMATION" "cfn-lint" "cfn-lint --config-file ${CLOUDFORMATION_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_CLOUDFORMATION[@]}" + ################################# + # Lint the CloudFormation files # + ################################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "CLOUDFORMATION" "cfn-lint" "cfn-lint --config-file ${CLOUDFORMATION_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_CLOUDFORMATION[@]}" fi ################### # CLOJURE LINTING # ################### if [ "${VALIDATE_CLOJURE}" == "true" ]; then - ################################# - # Get Clojure standard rules # - ################################# - GetStandardRules "clj-kondo" - ######################### - # Lint the Clojure files # - ######################### - LintCodebase "CLOJURE" "clj-kondo" "clj-kondo --config ${CLOJURE_LINTER_RULES} --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$" "${FILE_ARRAY_CLOJURE[@]}" + ################################# + # Get Clojure standard rules # + ################################# + GetStandardRules "clj-kondo" + ######################### + # Lint the Clojure files # + ######################### + LintCodebase "CLOJURE" "clj-kondo" "clj-kondo --config ${CLOJURE_LINTER_RULES} --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$" "${FILE_ARRAY_CLOJURE[@]}" fi ######################## # COFFEESCRIPT LINTING # ######################## if [ "${VALIDATE_COFFEE}" == "true" ]; then - ######################### - # Lint the coffee files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f ${COFFEESCRIPT_LINTER_RULES}" ".*\.\(coffee\)\$" "${FILE_ARRAY_COFFEESCRIPT[@]}" + ######################### + # Lint the coffee files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f ${COFFEESCRIPT_LINTER_RULES}" ".*\.\(coffee\)\$" "${FILE_ARRAY_COFFEESCRIPT[@]}" fi ############### # CSS LINTING # ############### if [ "${VALIDATE_CSS}" == "true" ]; then - ################################# - # Get CSS standard rules # - ################################# - GetStandardRules "stylelint" - ############################# - # Lint the CSS files # - ############################# - LintCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}" + ################################# + # Get CSS standard rules # + ################################# + GetStandardRules "stylelint" + ############################# + # Lint the CSS files # + ############################# + LintCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}" fi ################ # DART LINTING # ################ if [ "${VALIDATE_DART}" == "true" ]; then - ####################### - # Lint the Dart files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "${FILE_ARRAY_DART[@]}" + ####################### + # Lint the Dart files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "${FILE_ARRAY_DART[@]}" fi ################## # DOCKER LINTING # ################## if [ "${VALIDATE_DOCKER}" == "true" ]; then - ######################### - # Lint the docker files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - # NOTE: dockerfilelint's "-c" option expects the folder *containing* the DOCKER_LINTER_RULES file - LintCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c $(dirname ${DOCKER_LINTER_RULES})" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}" + ######################### + # Lint the docker files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + # NOTE: dockerfilelint's "-c" option expects the folder *containing* the DOCKER_LINTER_RULES file + LintCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c $(dirname ${DOCKER_LINTER_RULES})" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}" fi ######################## # EDITORCONFIG LINTING # ######################## if [ "${VALIDATE_EDITORCONFIG}" == "true" ]; then - #################################### - # Lint the files with editorconfig # - #################################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" "^.*$" "${FILE_ARRAY_ENV[@]}" + #################################### + # Lint the files with editorconfig # + #################################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" "^.*$" "${FILE_ARRAY_ENV[@]}" fi ############### # ENV LINTING # ############### if [ "${VALIDATE_ENV}" == "true" ]; then - ####################### - # Lint the env files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$" "${FILE_ARRAY_ENV[@]}" + ####################### + # Lint the env files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$" "${FILE_ARRAY_ENV[@]}" fi ################## # GOLANG LINTING # ################## if [ "${VALIDATE_GO}" == "true" ]; then - ######################### - # Lint the golang files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "${FILE_ARRAY_GO[@]}" + ######################### + # Lint the golang files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "${FILE_ARRAY_GO[@]}" fi ################## # GROOVY LINTING # ################## if [ "$VALIDATE_GROOVY" == "true" ]; then - ######################### - # Lint the groovy files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}" + ######################### + # Lint the groovy files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}" fi ################ # HTML LINTING # ################ if [ "${VALIDATE_HTML}" == "true" ]; then - ########################### - # Get HTML standard rules # - ########################### - GetStandardRules "htmlhint" - ####################### - # Lint the HTML files # - ####################### - LintCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "${FILE_ARRAY_HTML[@]}" + ########################### + # Get HTML standard rules # + ########################### + GetStandardRules "htmlhint" + ####################### + # Lint the HTML files # + ####################### + LintCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "${FILE_ARRAY_HTML[@]}" fi ###################### # JAVASCRIPT LINTING # ###################### if [ "${VALIDATE_JAVASCRIPT_ES}" == "true" ]; then - ############################# - # Lint the Javascript files # - ############################# - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_ES[@]}" + ############################# + # Lint the Javascript files # + ############################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_ES[@]}" fi ###################### # JAVASCRIPT LINTING # ###################### if [ "${VALIDATE_JAVASCRIPT_STANDARD}" == "true" ]; then - ################################# - # Get Javascript standard rules # - ################################# - GetStandardRules "javascript" - ############################# - # Lint the Javascript files # - ############################# - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_STANDARD[@]}" + ################################# + # Get Javascript standard rules # + ################################# + GetStandardRules "javascript" + ############################# + # Lint the Javascript files # + ############################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_STANDARD[@]}" fi ################ # JSON LINTING # ################ if [ "${VALIDATE_JSON}" == "true" ]; then - ####################### - # Lint the json files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "${FILE_ARRAY_JSON[@]}" + ####################### + # Lint the json files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "${FILE_ARRAY_JSON[@]}" fi ############### # JSX LINTING # ############### if [ "${VALIDATE_JSX}" == "true" ]; then - ###################### - # Lint the JSX files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "JSX" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(jsx\)\$" "${FILE_ARRAY_JSX[@]}" + ###################### + # Lint the JSX files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JSX" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(jsx\)\$" "${FILE_ARRAY_JSX[@]}" fi ################## # KOTLIN LINTING # ################## if [ "${VALIDATE_KOTLIN}" == "true" ]; then - ####################### - # Lint the Kotlin files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}" + ####################### + # Lint the Kotlin files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}" fi ############### # LUA LINTING # ############### if [ "${VALIDATE_LUA}" == "true" ]; then - ###################### - # Lint the Lua files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "LUA" "lua" "luacheck --config ${LUA_LINTER_RULES}" ".*\.\(lua\)\$" "${FILE_ARRAY_LUA[@]}" + ###################### + # Lint the Lua files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "LUA" "lua" "luacheck --config ${LUA_LINTER_RULES}" ".*\.\(lua\)\$" "${FILE_ARRAY_LUA[@]}" fi #################### # MARKDOWN LINTING # #################### if [ "${VALIDATE_MARKDOWN}" == "true" ]; then - ########################### - # Lint the Markdown Files # - ########################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "${FILE_ARRAY_MARKDOWN[@]}" + ########################### + # Lint the Markdown Files # + ########################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "${FILE_ARRAY_MARKDOWN[@]}" fi ################### # OPENAPI LINTING # ################### if [ "${VALIDATE_OPENAPI}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' + # If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectOpenAPIFile "${FILE}"; then - FILE_ARRAY_OPENAPI+=("${FILE}") - fi - done + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectOpenAPIFile "${FILE}"; then + FILE_ARRAY_OPENAPI+=("${FILE}") + fi + done - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi - ########################## - # Lint the OpenAPI files # - ########################## - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_OPENAPI[@]}" + ########################## + # Lint the OpenAPI files # + ########################## + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_OPENAPI[@]}" fi ################ # PERL LINTING # ################ if [ "${VALIDATE_PERL}" == "true" ]; then - ####################### - # Lint the perl files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}" + ####################### + # Lint the perl files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}" fi ################ # PHP LINTING # ################ if [ "${VALIDATE_PHP}" == "true" ]; then - ####################### - # Lint the PHP files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "${FILE_ARRAY_PHP[@]}" + ####################### + # Lint the PHP files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "${FILE_ARRAY_PHP[@]}" fi ################### # PHPStan LINTING # ################### if [ "${VALIDATE_PHP_PHPSTAN}" == "true" ]; then - ####################### - # Lint the PHP files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PHP_PHPSTAN" "phpstan" "phpstan analyse --no-progress --no-ansi -c ${PHPSTAN_LINTER_RULES}" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PHPSTAN[@]}" + ####################### + # Lint the PHP files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PHP_PHPSTAN" "phpstan" "phpstan analyse --no-progress --no-ansi -c ${PHPSTAN_LINTER_RULES}" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PHPSTAN[@]}" fi ###################### # POWERSHELL LINTING # ###################### if [ "${VALIDATE_POWERSHELL}" == "true" ]; then - ############################################################### - # For POWERSHELL, ensure PSScriptAnalyzer module is available # - ############################################################### - ValidatePowershellModules + ############################################################### + # For POWERSHELL, ensure PSScriptAnalyzer module is available # + ############################################################### + ValidatePowershellModules - ############################# - # Lint the powershell files # - ############################# - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" + ############################# + # Lint the powershell files # + ############################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi #################### # PROTOBUF LINTING # #################### if [ "${VALIDATE_PROTOBUF}" == "true" ]; then - ####################### - # Lint the Protocol Buffers files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "${FILE_ARRAY_PROTOBUF[@]}" + ####################### + # Lint the Protocol Buffers files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "${FILE_ARRAY_PROTOBUF[@]}" fi ################## # PYTHON LINTING # ################## if [ "${VALIDATE_PYTHON_PYLINT}" == "true" ]; then - ######################### - # Lint the python files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_PYLINT[@]}" + ######################### + # Lint the python files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_PYLINT[@]}" fi ################## # PYTHON LINTING # ################## if [ "${VALIDATE_PYTHON_FLAKE8}" == "true" ]; then - ######################### - # Lint the python files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config=${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_FLAKE8[@]}" + ######################### + # Lint the python files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config=${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_FLAKE8[@]}" fi ################ # RAKU LINTING # ################ if [ "${VALIDATE_RAKU}" == "true" ]; then - ####################### - # Lint the raku files # - ####################### - info "${GITHUB_WORKSPACE}/META6.json" - if [ -e "${GITHUB_WORKSPACE}/META6.json" ]; then - cd "${GITHUB_WORKSPACE}" && zef install --deps-only --/test . - fi - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "RAKU" "raku" "raku -I ${GITHUB_WORKSPACE}/lib -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "${FILE_ARRAY_RAKU[@]}" + ####################### + # Lint the raku files # + ####################### + info "${GITHUB_WORKSPACE}/META6.json" + if [ -e "${GITHUB_WORKSPACE}/META6.json" ]; then + cd "${GITHUB_WORKSPACE}" && zef install --deps-only --/test . + fi + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "RAKU" "raku" "raku -I ${GITHUB_WORKSPACE}/lib -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "${FILE_ARRAY_RAKU[@]}" fi ################ # RUBY LINTING # ################ if [ "${VALIDATE_RUBY}" == "true" ]; then - ####################### - # Lint the ruby files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES} --force-exclusion" ".*\.\(rb\)\$" "${FILE_ARRAY_RUBY[@]}" + ####################### + # Lint the ruby files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES} --force-exclusion" ".*\.\(rb\)\$" "${FILE_ARRAY_RUBY[@]}" fi ###################### # AWS STATES LINTING # ###################### if [ "${VALIDATE_STATES}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every json file is an aws states file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' + # If we are validating all codebase we need to build file list because not every json file is an aws states file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectAWSStatesFIle "${FILE}"; then - FILE_ARRAY_STATES+=("${FILE}") - fi - done + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectAWSStatesFIle "${FILE}"; then + FILE_ARRAY_STATES+=("${FILE}") + fi + done - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi - ######################### - # Lint the STATES files # - ######################### - LintCodebase "STATES" "asl-validator" "asl-validator --json-path" "disabledfileext" "${FILE_ARRAY_STATES[@]}" + ######################### + # Lint the STATES files # + ######################### + LintCodebase "STATES" "asl-validator" "asl-validator --json-path" "disabledfileext" "${FILE_ARRAY_STATES[@]}" fi ##################### # TERRAFORM LINTING # ##################### if [ "${VALIDATE_TERRAFORM}" == "true" ]; then - ############################ - # Lint the Terraform files # - ############################ - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM[@]}" + ############################ + # Lint the Terraform files # + ############################ + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM[@]}" fi ############################### # TERRAFORM TERRASCAN LINTING # ############################### if [ "${VALIDATE_TERRAFORM_TERRASCAN}" == "true" ]; then - ############################ - # Lint the Terraform files # - ############################ - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM_TERRASCAN[@]}" + ############################ + # Lint the Terraform files # + ############################ + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM_TERRASCAN[@]}" fi ############### # TSX LINTING # ############### if [ "${VALIDATE_TSX}" == "true" ]; then - ###################### - # Lint the TSX files # - ###################### - LintCodebase "TSX" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(tsx\)\$" "${FILE_ARRAY_TSX[@]}" + ###################### + # Lint the TSX files # + ###################### + LintCodebase "TSX" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(tsx\)\$" "${FILE_ARRAY_TSX[@]}" fi ###################### # TYPESCRIPT LINTING # ###################### if [ "${VALIDATE_TYPESCRIPT_ES}" == "true" ]; then - ############################# - # Lint the Typescript files # - ############################# - LintCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_ES[@]}" + ############################# + # Lint the Typescript files # + ############################# + LintCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_ES[@]}" fi ###################### # TYPESCRIPT LINTING # ###################### if [ "${VALIDATE_TYPESCRIPT_STANDARD}" == "true" ]; then - ################################# - # Get Typescript standard rules # - ################################# - GetStandardRules "typescript" - ############################# - # Lint the Typescript files # - ############################# - LintCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_STANDARD[@]}" + ################################# + # Get Typescript standard rules # + ################################# + GetStandardRules "typescript" + ############################# + # Lint the Typescript files # + ############################# + LintCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_STANDARD[@]}" fi ############### # XML LINTING # ############### if [ "${VALIDATE_XML}" == "true" ]; then - ###################### - # Lint the XML Files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "${FILE_ARRAY_XML[@]}" + ###################### + # Lint the XML Files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "${FILE_ARRAY_XML[@]}" fi ############### # YAML LINTING # ############### if [ "${VALIDATE_YAML}" == "true" ]; then - ###################### - # Lint the Yml Files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "${FILE_ARRAY_YAML[@]}" + ###################### + # Lint the Yml Files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "${FILE_ARRAY_YAML[@]}" fi ########### diff --git a/lib/log.sh b/lib/log.sh index f6bd73a2..a7ab55d9 100644 --- a/lib/log.sh +++ b/lib/log.sh @@ -1,24 +1,24 @@ #!/usr/bin/env bash declare -Agr B=( - [B]=$(echo -e "\e[44m") - [C]=$(echo -e "\e[46m") - [G]=$(echo -e "\e[42m") - [K]=$(echo -e "\e[40m") - [M]=$(echo -e "\e[45m") - [R]=$(echo -e "\e[41m") - [W]=$(echo -e "\e[47m") - [Y]=$(echo -e "\e[43m") + [B]=$(echo -e "\e[44m") + [C]=$(echo -e "\e[46m") + [G]=$(echo -e "\e[42m") + [K]=$(echo -e "\e[40m") + [M]=$(echo -e "\e[45m") + [R]=$(echo -e "\e[41m") + [W]=$(echo -e "\e[47m") + [Y]=$(echo -e "\e[43m") ) declare -Agr F=( - [B]=$(echo -e "\e[0;34m") - [C]=$(echo -e "\e[0;36m") - [G]=$(echo -e "\e[0;32m") - [K]=$(echo -e "\e[0;30m") - [M]=$(echo -e "\e[0;35m") - [R]=$(echo -e "\e[0;31m") - [W]=$(echo -e "\e[0;37m") - [Y]=$(echo -e "\e[0;33m") + [B]=$(echo -e "\e[0;34m") + [C]=$(echo -e "\e[0;36m") + [G]=$(echo -e "\e[0;32m") + [K]=$(echo -e "\e[0;30m") + [M]=$(echo -e "\e[0;35m") + [R]=$(echo -e "\e[0;31m") + [W]=$(echo -e "\e[0;37m") + [Y]=$(echo -e "\e[0;33m") ) readonly NC=$(echo -e "\e[0m") @@ -31,15 +31,15 @@ LOG_TEMP=$(mktemp) || echo "Failed to create temporary log file." export LOG_TEMP echo "super-linter Log" > "${LOG_TEMP}" log() { - local TOTERM=${1:-} - local MESSAGE=${2:-} - echo -e "${MESSAGE:-}" | ( - if [[ -n ${TOTERM} ]]; then - tee -a "${LOG_TEMP}" >&2 - else - cat >> "${LOG_TEMP}" 2>&1 - fi - ) + local TOTERM=${1:-} + local MESSAGE=${2:-} + echo -e "${MESSAGE:-}" | ( + if [[ -n ${TOTERM} ]]; then + tee -a "${LOG_TEMP}" >&2 + else + cat >> "${LOG_TEMP}" 2>&1 + fi + ) } trace() { log "${LOG_TRACE:-}" "${NC}$(date +"%F %T") ${F[B]}[TRACE ]${NC} $*${NC}"; } debug() { log "${LOG_DEBUG:-}" "${NC}$(date +"%F %T") ${F[B]}[DEBUG ]${NC} $*${NC}"; } @@ -48,6 +48,6 @@ notice() { log "true" "${NC}$(date +"%F %T") ${F[G]}[NOTICE]${NC} $*${NC}"; } warn() { log "true" "${NC}$(date +"%F %T") ${F[Y]}[WARN ]${NC} $*${NC}"; } error() { log "true" "${NC}$(date +"%F %T") ${F[R]}[ERROR ]${NC} $*${NC}"; } fatal() { - log "true" "${NC}$(date +"%F %T") ${B[R]}${F[W]}[FATAL ]${NC} $*${NC}" - exit 1 + log "true" "${NC}$(date +"%F %T") ${B[R]}${F[W]}[FATAL ]${NC} $*${NC}" + exit 1 } diff --git a/lib/termColors.sh b/lib/termColors.sh index ce3e0e66..8f22a26c 100755 --- a/lib/termColors.sh +++ b/lib/termColors.sh @@ -1,24 +1,24 @@ #!/usr/bin/env bash declare -Agr B=( - [B]=$(echo -e "\e[44m") - [C]=$(echo -e "\e[46m") - [G]=$(echo -e "\e[42m") - [K]=$(echo -e "\e[40m") - [M]=$(echo -e "\e[45m") - [R]=$(echo -e "\e[41m") - [W]=$(echo -e "\e[47m") - [Y]=$(echo -e "\e[43m") + [B]=$(echo -e "\e[44m") + [C]=$(echo -e "\e[46m") + [G]=$(echo -e "\e[42m") + [K]=$(echo -e "\e[40m") + [M]=$(echo -e "\e[45m") + [R]=$(echo -e "\e[41m") + [W]=$(echo -e "\e[47m") + [Y]=$(echo -e "\e[43m") ) declare -Agr F=( - [B]=$(echo -e "\e[0;34m") - [C]=$(echo -e "\e[0;36m") - [G]=$(echo -e "\e[0;32m") - [K]=$(echo -e "\e[0;30m") - [M]=$(echo -e "\e[0;35m") - [R]=$(echo -e "\e[0;31m") - [W]=$(echo -e "\e[0;37m") - [Y]=$(echo -e "\e[0;33m") + [B]=$(echo -e "\e[0;34m") + [C]=$(echo -e "\e[0;36m") + [G]=$(echo -e "\e[0;32m") + [K]=$(echo -e "\e[0;30m") + [M]=$(echo -e "\e[0;35m") + [R]=$(echo -e "\e[0;31m") + [W]=$(echo -e "\e[0;37m") + [Y]=$(echo -e "\e[0;33m") ) readonly NC=$(echo -e "\e[0m") diff --git a/lib/validation.sh b/lib/validation.sh index fcbcd4ac..6e4105b0 100755 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -10,175 +10,175 @@ ################################################################################ #### Function GetValidationInfo ################################################ function GetValidationInfo() { - ############################################ - # Print headers for user provided env vars # - ############################################ - info "--------------------------------------------" - info "Gathering user validation information..." + ############################################ + # Print headers for user provided env vars # + ############################################ + info "--------------------------------------------" + info "Gathering user validation information..." - ########################################### - # Skip validation if were running locally # - ########################################### - if [[ ${RUN_LOCAL} != "true" ]]; then - ############################### - # Convert string to lowercase # - ############################### - VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE,,}" - ###################################### - # Validate we should check all files # - ###################################### - if [[ ${VALIDATE_ALL_CODEBASE} != "false" ]]; then - # Set to true - VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" - info "- Validating ALL files in code base..." - else - # Its false - info "- Only validating [new], or [edited] files in code base..." - fi - fi - - ###################### - # Create Print Array # - ###################### - PRINT_ARRAY=() - - ################################ - # Convert strings to lowercase # - ################################ - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" - # Set the value of the var to lowercase - eval "${VALIDATE_LANGUAGE}=${!VALIDATE_LANGUAGE,,}" - done - - ################################################ - # Determine if any linters were explicitly set # - ################################################ - ANY_SET="false" - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" - # Check to see if the variable was set - if [ -n "${!VALIDATE_LANGUAGE}" ]; then - # It was set, need to set flag - ANY_SET="true" - fi - done - - ################################################### - # Validate if we should check individual lanuages # - ################################################### - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" - # Check if ANY_SET was set - if [[ ${ANY_SET} == "true" ]]; then - # Check to see if the variable was set - if [ -z "${!VALIDATE_LANGUAGE}" ]; then - # Flag was not set, default to false - eval "${VALIDATE_LANGUAGE}='false'" - fi - else - # No linter flags were set - default all to true - eval "${VALIDATE_LANGUAGE}='true'" - fi - done - - ####################################### - # Print which linters we are enabling # - ####################################### - # Loop through all languages - for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do - # build the variable - VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" - if [[ ${!VALIDATE_LANGUAGE} == "true" ]]; then - # We need to validate - PRINT_ARRAY+=("- Validating [$LANGUAGE] files in code base...") - else - # We are skipping the language - PRINT_ARRAY+=("- Excluding [$LANGUAGE] files in code base...") - fi - done - - ############################## - # Validate Ansible Directory # - ############################## - if [ -z "${ANSIBLE_DIRECTORY}" ]; then - # No Value, need to default - ANSIBLE_DIRECTORY="${DEFAULT_ANSIBLE_DIRECTORY}" + ########################################### + # Skip validation if were running locally # + ########################################### + if [[ ${RUN_LOCAL} != "true" ]]; then + ############################### + # Convert string to lowercase # + ############################### + VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE,,}" + ###################################### + # Validate we should check all files # + ###################################### + if [[ ${VALIDATE_ALL_CODEBASE} != "false" ]]; then + # Set to true + VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" + info "- Validating ALL files in code base..." else - # Check if first char is '/' - if [[ ${ANSIBLE_DIRECTORY:0:1} == "/" ]]; then - # Remove first char - ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY:1}" - fi - # Need to give it full path - TEMP_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/${ANSIBLE_DIRECTORY}" - # Set the value - ANSIBLE_DIRECTORY="${TEMP_ANSIBLE_DIRECTORY}" + # Its false + info "- Only validating [new], or [edited] files in code base..." fi + fi - ############################### - # Get the disable errors flag # - ############################### - if [ -z "${DISABLE_ERRORS}" ]; then - ################################## - # No flag passed, set to default # - ################################## - DISABLE_ERRORS="${DEFAULT_DISABLE_ERRORS}" + ###################### + # Create Print Array # + ###################### + PRINT_ARRAY=() + + ################################ + # Convert strings to lowercase # + ################################ + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" + # Set the value of the var to lowercase + eval "${VALIDATE_LANGUAGE}=${!VALIDATE_LANGUAGE,,}" + done + + ################################################ + # Determine if any linters were explicitly set # + ################################################ + ANY_SET="false" + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" + # Check to see if the variable was set + if [ -n "${!VALIDATE_LANGUAGE}" ]; then + # It was set, need to set flag + ANY_SET="true" fi + done - ############################### - # Convert string to lowercase # - ############################### - DISABLE_ERRORS="${DISABLE_ERRORS,,}" - - ############################ - # Set to false if not true # - ############################ - if [ "${DISABLE_ERRORS}" != "true" ]; then - DISABLE_ERRORS="false" + ################################################### + # Validate if we should check individual lanuages # + ################################################### + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" + # Check if ANY_SET was set + if [[ ${ANY_SET} == "true" ]]; then + # Check to see if the variable was set + if [ -z "${!VALIDATE_LANGUAGE}" ]; then + # Flag was not set, default to false + eval "${VALIDATE_LANGUAGE}='false'" + fi + else + # No linter flags were set - default all to true + eval "${VALIDATE_LANGUAGE}='true'" fi + done - ############################ - # Get the run verbose flag # - ############################ - if [ -z "${ACTIONS_RUNNER_DEBUG}" ]; then - ################################## - # No flag passed, set to default # - ################################## - ACTIONS_RUNNER_DEBUG="${DEFAULT_ACTIONS_RUNNER_DEBUG}" + ####################################### + # Print which linters we are enabling # + ####################################### + # Loop through all languages + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do + # build the variable + VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}" + if [[ ${!VALIDATE_LANGUAGE} == "true" ]]; then + # We need to validate + PRINT_ARRAY+=("- Validating [$LANGUAGE] files in code base...") + else + # We are skipping the language + PRINT_ARRAY+=("- Excluding [$LANGUAGE] files in code base...") fi + done - ############################### - # Convert string to lowercase # - ############################### - ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG,,}" - - ############################ - # Set to true if not false # - ############################ - if [ "${ACTIONS_RUNNER_DEBUG}" != "false" ]; then - ACTIONS_RUNNER_DEBUG="true" + ############################## + # Validate Ansible Directory # + ############################## + if [ -z "${ANSIBLE_DIRECTORY}" ]; then + # No Value, need to default + ANSIBLE_DIRECTORY="${DEFAULT_ANSIBLE_DIRECTORY}" + else + # Check if first char is '/' + if [[ ${ANSIBLE_DIRECTORY:0:1} == "/" ]]; then + # Remove first char + ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY:1}" fi + # Need to give it full path + TEMP_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/${ANSIBLE_DIRECTORY}" + # Set the value + ANSIBLE_DIRECTORY="${TEMP_ANSIBLE_DIRECTORY}" + fi - ########################### - # Print the validate info # - ########################### - for LINE in "${PRINT_ARRAY[@]}"; do - debug "${LINE}" - done + ############################### + # Get the disable errors flag # + ############################### + if [ -z "${DISABLE_ERRORS}" ]; then + ################################## + # No flag passed, set to default # + ################################## + DISABLE_ERRORS="${DEFAULT_DISABLE_ERRORS}" + fi - debug "--- DEBUG INFO ---" - debug "---------------------------------------------" - RUNNER=$(whoami) - debug "Runner:[${RUNNER}]" - PRINTENV=$(printenv) - debug "ENV:" - debug "${PRINTENV}" - debug "---------------------------------------------" + ############################### + # Convert string to lowercase # + ############################### + DISABLE_ERRORS="${DISABLE_ERRORS,,}" + + ############################ + # Set to false if not true # + ############################ + if [ "${DISABLE_ERRORS}" != "true" ]; then + DISABLE_ERRORS="false" + fi + + ############################ + # Get the run verbose flag # + ############################ + if [ -z "${ACTIONS_RUNNER_DEBUG}" ]; then + ################################## + # No flag passed, set to default # + ################################## + ACTIONS_RUNNER_DEBUG="${DEFAULT_ACTIONS_RUNNER_DEBUG}" + fi + + ############################### + # Convert string to lowercase # + ############################### + ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG,,}" + + ############################ + # Set to true if not false # + ############################ + if [ "${ACTIONS_RUNNER_DEBUG}" != "false" ]; then + ACTIONS_RUNNER_DEBUG="true" + fi + + ########################### + # Print the validate info # + ########################### + for LINE in "${PRINT_ARRAY[@]}"; do + debug "${LINE}" + done + + debug "--- DEBUG INFO ---" + debug "---------------------------------------------" + RUNNER=$(whoami) + debug "Runner:[${RUNNER}]" + PRINTENV=$(printenv) + debug "ENV:" + debug "${PRINTENV}" + debug "---------------------------------------------" } diff --git a/lib/worker.sh b/lib/worker.sh index 929b3ff9..3dbdb83c 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -10,883 +10,883 @@ ################################################################################ #### Function LintCodebase ##################################################### function LintCodebase() { - #################### - # Pull in the vars # - #################### - FILE_TYPE="${1}" && shift # Pull the variable and remove from array path (Example: JSON) - LINTER_NAME="${1}" && shift # Pull the variable and remove from array path (Example: jsonlint) - LINTER_COMMAND="${1}" && shift # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) - 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}) + #################### + # Pull in the vars # + #################### + FILE_TYPE="${1}" && shift # Pull the variable and remove from array path (Example: JSON) + LINTER_NAME="${1}" && shift # Pull the variable and remove from array path (Example: jsonlint) + LINTER_COMMAND="${1}" && shift # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) + 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=() + ###################### + # Create Print Array # + ###################### + PRINT_ARRAY=() - ################ - # print header # - ################ - PRINT_ARRAY+=("") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("Linting [${FILE_TYPE}] files...") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("----------------------------------------------") + ################ + # print header # + ################ + PRINT_ARRAY+=("") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("Linting [${FILE_TYPE}] files...") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") - ##################################### - # Validate we have linter installed # - ##################################### - VALIDATE_INSTALL_CMD=$(command -v "${LINTER_NAME}" 2>&1) + ##################################### + # Validate we have linter installed # + ##################################### + VALIDATE_INSTALL_CMD=$(command -v "${LINTER_NAME}" 2>&1) - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Failed - error "Failed to find [${LINTER_NAME}] in system!" - fatal "[${VALIDATE_INSTALL_CMD}]" - else - # Success - debug "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" - fi + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Failed + error "Failed to find [${LINTER_NAME}] in system!" + fatal "[${VALIDATE_INSTALL_CMD}]" + else + # Success + debug "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" + fi - ########################## - # Initialize empty Array # - ########################## - LIST_FILES=() + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() - ################ - # Set the flag # - ################ - SKIP_FLAG=0 + ################ + # 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 - SKIP_FLAG=1 - debug " - No files found in changeset 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 - else - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' - - ################################# - # Get list of all files to lint # - ################################# - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex "${FILE_EXTENSIONS}" 2>&1) - - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - - ############################################################ - # 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 # - ###################### - for LINE in "${PRINT_ARRAY[@]}"; do - ######################### - # Print the header info # - ######################### - info "${LINE}" - done - - ######################################## - # Prepare context if TAP format output # - ######################################## - if IsTAP; then - TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") - INDEX=0 - mkdir -p "${REPORT_OUTPUT_FOLDER}" - REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" - fi - - ################## - # Lint the files # - ################## - for FILE in "${LIST_FILES[@]}"; do - ################################### - # Get the file name and directory # - ################################### - FILE_NAME=$(basename "${FILE}" 2>&1) - DIR_NAME=$(dirname "${FILE}" 2>&1) - - ##################################################### - # 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 - elif [[ ${FILE} == *".git"* ]]; then - # This is likely the .git folder and shouldnt be parsed - continue - fi - - ################################## - # Increase the linted file index # - ################################## - (("INDEX++")) - - ############## - # File print # - ############## - info "---------------------------" - info "File:[${FILE}]" - - ################################# - # Add the language to the array # - ################################# - LINTED_LANGUAGES_ARRAY+=("${FILE_TYPE}") - - #################### - # Set the base Var # - #################### - LINT_CMD='' - - #################################### - # Corner case for pwsh subshell # - # - PowerShell (PSScriptAnalyzer) # - # - ARM (arm-ttk) # - #################################### - if [[ ${FILE_TYPE} == "POWERSHELL" ]] || [[ ${FILE_TYPE} == "ARM" ]]; then - ################################ - # Lint the file with the rules # - ################################ - # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}" || exit - pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" - exit $? 2>&1 - ) - ############################################################################### - # Corner case for groovy as we have to pass it as path and file in ant format # - ############################################################################### - elif [[ ${FILE_TYPE} == "GROOVY" ]]; then - ####################################### - # Lint the file with the updated path # - ####################################### - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}" || exit - ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 - ) - else - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}" || exit - ${LINTER_COMMAND} "${FILE}" 2>&1 - ) - fi - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # 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}++")) - - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP; then - NotOkTap "${INDEX}" "${FILE}" "${TMPFILE}" - AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" - fi - else - ########### - # Success # - ########### - info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" - - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP; then - OkTap "${INDEX}" "${FILE}" "${TMPFILE}" - fi - fi - done - - ################################# - # Generate report in TAP format # - ################################# - if IsTAP && [ ${INDEX} -gt 0 ]; then - HeaderTap "${INDEX}" "${REPORT_OUTPUT_FILE}" - cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" - fi - fi -} -################################################################################ -#### Function TestCodebase ##################################################### -function TestCodebase() { - #################### - # Pull in the vars # - #################### - FILE_TYPE="${1}" # Pull the variable and remove from array path (Example: JSON) - LINTER_NAME="${2}" # Pull the variable and remove from array path (Example: jsonlint) - LINTER_COMMAND="${3}" # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) - FILE_EXTENSIONS="${4}" # Pull the variable and remove from array path (Example: *.json) - INDVIDUAL_TEST_FOLDER="${5}" # Folder for specific tests - TESTS_RAN=0 # Incremented when tests are ran, this will help find failed finds - - ################ - # print header # - ################ - info "----------------------------------------------" - info "----------------------------------------------" - info "Testing Codebase [${FILE_TYPE}] files..." - info "----------------------------------------------" - info "----------------------------------------------" - - ##################################### - # Validate we have linter installed # - ##################################### - 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 - error "Failed to find [${LINTER_NAME}] in system!" - fatal "[${VALIDATE_INSTALL_CMD}]" - else - # Success - info "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" - fi - - ########################## - # Initialize empty Array # - ########################## - LIST_FILES=() + ############################################################ + # 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 + SKIP_FLAG=1 + debug " - No files found in changeset 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 + else + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' ################################# # Get list of all files to lint # ################################# - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" -type f -regex "${FILE_EXTENSIONS}" ! -path "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/ansible/ghe-initialize/*" | sort 2>&1) + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex "${FILE_EXTENSIONS}" 2>&1) + + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + + ############################################################ + # 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 # + ###################### + for LINE in "${PRINT_ARRAY[@]}"; do + ######################### + # Print the header info # + ######################### + info "${LINE}" + done ######################################## - # Prepare context if TAP output format # + # Prepare context if TAP format output # ######################################## if IsTAP; then - TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") - mkdir -p "${REPORT_OUTPUT_FOLDER}" - REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" + TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") + INDEX=0 + mkdir -p "${REPORT_OUTPUT_FOLDER}" + REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" fi ################## # Lint the files # ################## for FILE in "${LIST_FILES[@]}"; do - ##################### - # Get the file name # - ##################### - FILE_NAME=$(basename "${FILE}" 2>&1) - DIR_NAME=$(dirname "${FILE}" 2>&1) + ################################### + # Get the file name and directory # + ################################### + FILE_NAME=$(basename "${FILE}" 2>&1) + DIR_NAME=$(dirname "${FILE}" 2>&1) - ############################ - # Get the file pass status # - ############################ - # Example: markdown_good_1.md -> good - FILE_STATUS=$(echo "${FILE_NAME}" | cut -f2 -d'_') + ##################################################### + # 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 + elif [[ ${FILE} == *".git"* ]]; then + # This is likely the .git folder and shouldnt be parsed + continue + fi - ######################################################### - # If not found, assume it should be linted successfully # - ######################################################### - if [ -z "${FILE_STATUS}" ] || [[ ${FILE} == *"README"* ]]; then - ################################## - # Set to good for proper linting # - ################################## - FILE_STATUS="good" - fi + ################################## + # Increase the linted file index # + ################################## + (("INDEX++")) - ############## - # File print # - ############## - info "---------------------------" - info "File:[${FILE}]" + ############## + # File print # + ############## + info "---------------------------" + info "File:[${FILE}]" - ######################## - # Set the lint command # - ######################## - LINT_CMD='' + ################################# + # Add the language to the array # + ################################# + LINTED_LANGUAGES_ARRAY+=("${FILE_TYPE}") + #################### + # Set the base Var # + #################### + LINT_CMD='' + + #################################### + # Corner case for pwsh subshell # + # - PowerShell (PSScriptAnalyzer) # + # - ARM (arm-ttk) # + #################################### + if [[ ${FILE_TYPE} == "POWERSHELL" ]] || [[ ${FILE_TYPE} == "ARM" ]]; then + ################################ + # Lint the file with the rules # + ################################ + # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" + exit $? 2>&1 + ) + ############################################################################### + # Corner case for groovy as we have to pass it as path and file in ant format # + ############################################################################### + elif [[ ${FILE_TYPE} == "GROOVY" ]]; then ####################################### - # Check if docker and get folder name # + # Lint the file with the updated path # ####################################### - if [[ ${FILE_TYPE} == "DOCKER" ]]; then - if [[ ${FILE} == *"good"* ]]; then - ############# - # Good file # - ############# - FILE_STATUS='good' - else - ############ - # Bad file # - ############ - FILE_STATUS='bad' - fi + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 + ) + else + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + ${LINTER_COMMAND} "${FILE}" 2>&1 + ) + fi + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # 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}++")) + + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + NotOkTap "${INDEX}" "${FILE}" "${TMPFILE}" + AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" fi + else + ########### + # Success # + ########### + info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" - ##################### - # Check for ansible # - ##################### - if [[ ${FILE_TYPE} == "ANSIBLE" ]]; then - ######################################## - # Make sure we dont lint certain files # - ######################################## - if [[ ${FILE} == *"vault.yml"* ]] || [[ ${FILE} == *"galaxy.yml"* ]]; then - # This is a file we dont look at - continue - fi - - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" || exit - ${LINTER_COMMAND} "${FILE}" 2>&1 - ) - elif [[ ${FILE_TYPE} == "POWERSHELL" ]] || [[ ${FILE_TYPE} == "ARM" ]]; then - ################################ - # Lint the file with the rules # - ################################ - # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}" || exit - pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" - exit $? 2>&1 - ) - ############################################################################### - # Corner case for groovy as we have to pass it as path and file in ant format # - ############################################################################### - elif [[ ${FILE_TYPE} == "GROOVY" ]]; then - ####################################### - # Lint the file with the updated path # - ####################################### - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}" || exit - ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 - ) - else - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$( - cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}" || exit - ${LINTER_COMMAND} "${FILE}" 2>&1 - ) - fi - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ######################################## - # Increment counter that check was ran # - ######################################## - (("TESTS_RAN++")) - - ######################################## - # Check for if it was supposed to pass # - ######################################## - if [[ ${FILE_STATUS} == "good" ]]; then - ############################## - # 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}++")) - else - ########### - # Success # - ########### - info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" - fi - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP; then - OkTap "${TESTS_RAN}" "${FILE_NAME}" "${TMPFILE}" - fi - else - ####################################### - # File status = bad, this should fail # - ####################################### - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -eq 0 ]; then - ######### - # Error # - ######### - error "Found errors in [${LINTER_NAME}] linter!" - error "This file should have failed test case!" - error "Command run:${NC}[\$${LINT_CMD}]" - error "[${LINT_CMD}]" - error "Linter CMD:[${LINTER_COMMAND} ${FILE}]" - # Increment the error count - (("ERRORS_FOUND_${FILE_TYPE}++")) - else - ########### - # Success # - ########### - info " - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" - fi - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP; then - NotOkTap "${TESTS_RAN}" "${FILE_NAME}" "${TMPFILE}" - AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" - fi + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + OkTap "${INDEX}" "${FILE}" "${TMPFILE}" fi + fi done - ########################################################################### - # Generate report in TAP format and validate with the expected TAP output # - ########################################################################### - if IsTAP && [ ${TESTS_RAN} -gt 0 ]; then - HeaderTap "${TESTS_RAN}" "${REPORT_OUTPUT_FILE}" - cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" - - ######################################################################## - # If expected TAP report exists then compare with the generated report # - ######################################################################## - EXPECTED_FILE="${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}/reports/expected-${FILE_TYPE}.tap" - if [ -e "${EXPECTED_FILE}" ]; then - TMPFILE=$(mktemp -q "/tmp/diff-${FILE_TYPE}.XXXXXX") - ## Ignore white spaces, case sensitive - if ! diff -a -w -i "${EXPECTED_FILE}" "${REPORT_OUTPUT_FILE}" > "${TMPFILE}" 2>&1; then - ############################################# - # We failed to compare the reporting output # - ############################################# - error "Failed to assert TAP output:[${LINTER_NAME}]"! - info "Please validate the asserts!" - cat "${TMPFILE}" - exit 1 - else - # Success - info "Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]" - fi - else - warn "No TAP expected file found at:[${EXPECTED_FILE}]" - info "skipping report assertions" - ##################################### - # Append the file type to the array # - ##################################### - WARNING_ARRAY_TEST+=("${FILE_TYPE}") - fi - fi - - ############################## - # Validate we ran some tests # - ############################## - if [ "${TESTS_RAN}" -eq 0 ]; then - ################################################# - # We failed to find files and no tests were ran # - ################################################# - error "Failed to find any tests ran for the Linter:[${LINTER_NAME}]"! - fatal "Please validate logic or that tests exist!" + ################################# + # Generate report in TAP format # + ################################# + if IsTAP && [ ${INDEX} -gt 0 ]; then + HeaderTap "${INDEX}" "${REPORT_OUTPUT_FILE}" + cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" fi + fi } ################################################################################ -#### Function RunTestCases ##################################################### -function RunTestCases() { - # This loop will run the test cases and exclude user code - # This is called from the automation process to validate new code - # When a PR is opened, the new code is validated with the default branch - # version of linter.sh, and a new container is built with the latest codebase - # for testing. That container is spun up, and ran, - # with the flag: TEST_CASE_RUN=true - # So that the new code can be validated against the test cases +#### Function TestCodebase ##################################################### +function TestCodebase() { + #################### + # Pull in the vars # + #################### + FILE_TYPE="${1}" # Pull the variable and remove from array path (Example: JSON) + LINTER_NAME="${2}" # Pull the variable and remove from array path (Example: jsonlint) + LINTER_COMMAND="${3}" # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) + FILE_EXTENSIONS="${4}" # Pull the variable and remove from array path (Example: *.json) + INDVIDUAL_TEST_FOLDER="${5}" # Folder for specific tests + TESTS_RAN=0 # Incremented when tests are ran, this will help find failed finds - ################# - # Header prints # - ################# - info "----------------------------------------------" - info "-------------- TEST CASE RUN -----------------" - info "----------------------------------------------" + ################ + # print header # + ################ + info "----------------------------------------------" + info "----------------------------------------------" + info "Testing Codebase [${FILE_TYPE}] files..." + info "----------------------------------------------" + info "----------------------------------------------" - ####################### - # Test case languages # - ####################### - # TestCodebase "Language" "Linter" "Linter-command" "Regex to find files" "Test Folder" - 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" ".*\.\(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" - TestCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "css" - TestCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "dart" - TestCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c ${DOCKER_LINTER_RULES}" ".*\(Dockerfile\)\$" "docker" - TestCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" ".*\.ext$" "editorconfig-checker" - TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "env" - TestCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "golang" - TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" - TestCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "html" - TestCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "javascript" - TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript" - TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json" - TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin" - TestCodebase "LUA" "lua" "luacheck" ".*\.\(lua\)\$" "lua" - TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown" - TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl" - TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php" - TestCodebase "PHP_PHPSTAN" "phpstan" "phpstan analyse --no-progress --no-ansi -c ${PHPSTAN_LINTER_RULES}" ".*\.\(php\)\$" "php" - TestCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi" - TestCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "powershell" - TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "protobuf" - TestCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "python" - TestCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config ${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "python" - TestCodebase "RAKU" "raku" "raku -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "raku" - TestCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES}" ".*\.\(rb\)\$" "ruby" - TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states" - TestCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "terraform" - TestCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "terraform_terrascan" - TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" - TestCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" - TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "xml" - TestCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "yml" + ##################################### + # Validate we have linter installed # + ##################################### + VALIDATE_INSTALL_CMD=$(command -v "${LINTER_NAME}" 2>&1) - ################# - # Footer prints # - ################# - # Call the footer to display run information - # and exit with error code - Footer -} -################################################################################ -#### Function LintAnsibleFiles ################################################# -function LintAnsibleFiles() { - ###################### - # Create Print Array # - ###################### - PRINT_ARRAY=() + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? - ################ - # print header # - ################ - PRINT_ARRAY+=("") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("Linting [Ansible] files...") - PRINT_ARRAY+=("----------------------------------------------") - PRINT_ARRAY+=("----------------------------------------------") + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Failed + error "Failed to find [${LINTER_NAME}] in system!" + fatal "[${VALIDATE_INSTALL_CMD}]" + else + # Success + info "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" + fi - ###################### - # Name of the linter # - ###################### - LINTER_NAME="ansible-lint" + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() - ########################################### - # Validate we have ansible-lint installed # - ########################################### - VALIDATE_INSTALL_CMD=$(command -v "${LINTER_NAME}" 2>&1) + ################################# + # Get list of all files to lint # + ################################# + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" -type f -regex "${FILE_EXTENSIONS}" ! -path "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/ansible/ghe-initialize/*" | sort 2>&1) + + ######################################## + # Prepare context if TAP output format # + ######################################## + if IsTAP; then + TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") + mkdir -p "${REPORT_OUTPUT_FOLDER}" + REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" + fi + + ################## + # Lint the files # + ################## + for FILE in "${LIST_FILES[@]}"; do + ##################### + # Get the file name # + ##################### + FILE_NAME=$(basename "${FILE}" 2>&1) + DIR_NAME=$(dirname "${FILE}" 2>&1) + + ############################ + # Get the file pass status # + ############################ + # Example: markdown_good_1.md -> good + FILE_STATUS=$(echo "${FILE_NAME}" | cut -f2 -d'_') + + ######################################################### + # If not found, assume it should be linted successfully # + ######################################################### + if [ -z "${FILE_STATUS}" ] || [[ ${FILE} == *"README"* ]]; then + ################################## + # Set to good for proper linting # + ################################## + FILE_STATUS="good" + fi + + ############## + # File print # + ############## + info "---------------------------" + info "File:[${FILE}]" + + ######################## + # Set the lint command # + ######################## + LINT_CMD='' + + ####################################### + # Check if docker and get folder name # + ####################################### + if [[ ${FILE_TYPE} == "DOCKER" ]]; then + if [[ ${FILE} == *"good"* ]]; then + ############# + # Good file # + ############# + FILE_STATUS='good' + else + ############ + # Bad file # + ############ + FILE_STATUS='bad' + fi + fi + + ##################### + # Check for ansible # + ##################### + if [[ ${FILE_TYPE} == "ANSIBLE" ]]; then + ######################################## + # Make sure we dont lint certain files # + ######################################## + if [[ ${FILE} == *"vault.yml"* ]] || [[ ${FILE} == *"galaxy.yml"* ]]; then + # This is a file we dont look at + continue + fi + + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" || exit + ${LINTER_COMMAND} "${FILE}" 2>&1 + ) + elif [[ ${FILE_TYPE} == "POWERSHELL" ]] || [[ ${FILE_TYPE} == "ARM" ]]; then + ################################ + # Lint the file with the rules # + ################################ + # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}" || exit + pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" + exit $? 2>&1 + ) + ############################################################################### + # Corner case for groovy as we have to pass it as path and file in ant format # + ############################################################################### + elif [[ ${FILE_TYPE} == "GROOVY" ]]; then + ####################################### + # Lint the file with the updated path # + ####################################### + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 + ) + else + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}" || exit + ${LINTER_COMMAND} "${FILE}" 2>&1 + ) + fi ####################### # Load the error code # ####################### ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Failed - error "Failed to find ${LINTER_NAME} in system!" - fatal "[${VALIDATE_INSTALL_CMD}]" + ######################################## + # Increment counter that check was ran # + ######################################## + (("TESTS_RAN++")) + + ######################################## + # Check for if it was supposed to pass # + ######################################## + if [[ ${FILE_STATUS} == "good" ]]; then + ############################## + # 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}++")) + else + ########### + # Success # + ########### + info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" + fi + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + OkTap "${TESTS_RAN}" "${FILE_NAME}" "${TMPFILE}" + fi else + ####################################### + # File status = bad, this should fail # + ####################################### + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -eq 0 ]; then + ######### + # Error # + ######### + error "Found errors in [${LINTER_NAME}] linter!" + error "This file should have failed test case!" + error "Command run:${NC}[\$${LINT_CMD}]" + error "[${LINT_CMD}]" + error "Linter CMD:[${LINTER_COMMAND} ${FILE}]" + # Increment the error count + (("ERRORS_FOUND_${FILE_TYPE}++")) + else + ########### + # Success # + ########### + info " - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" + fi + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + NotOkTap "${TESTS_RAN}" "${FILE_NAME}" "${TMPFILE}" + AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" + fi + fi + done + + ########################################################################### + # Generate report in TAP format and validate with the expected TAP output # + ########################################################################### + if IsTAP && [ ${TESTS_RAN} -gt 0 ]; then + HeaderTap "${TESTS_RAN}" "${REPORT_OUTPUT_FILE}" + cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" + + ######################################################################## + # If expected TAP report exists then compare with the generated report # + ######################################################################## + EXPECTED_FILE="${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}/reports/expected-${FILE_TYPE}.tap" + if [ -e "${EXPECTED_FILE}" ]; then + TMPFILE=$(mktemp -q "/tmp/diff-${FILE_TYPE}.XXXXXX") + ## Ignore white spaces, case sensitive + if ! diff -a -w -i "${EXPECTED_FILE}" "${REPORT_OUTPUT_FILE}" > "${TMPFILE}" 2>&1; then + ############################################# + # We failed to compare the reporting output # + ############################################# + error "Failed to assert TAP output:[${LINTER_NAME}]"! + info "Please validate the asserts!" + cat "${TMPFILE}" + exit 1 + else # Success - debug "Successfully found binary in system" - debug "Location:[${VALIDATE_INSTALL_CMD}]" - fi - - ########################## - # Initialize empty Array # - ########################## - LIST_FILES=() - - ####################### - # Create flag to skip # - ####################### - SKIP_FLAG=0 - - ###################################################### - # Only go into ansible linter if we have base folder # - ###################################################### - if [ -d "${ANSIBLE_DIRECTORY}" ]; then - - ################################# - # Get list of all files to lint # - ################################# - mapfile -t LIST_FILES < <(ls "${ANSIBLE_DIRECTORY}"/*.{yaml,yml} 2>&1) - - ############################################################### - # Set the list to empty if only MD and TXT files were changed # - ############################################################### - # No need to run the full ansible checks on read only file changes - if [ "${READ_ONLY_CHANGE_FLAG}" -eq 0 ]; then - ########################## - # Set the array to empty # - ########################## - LIST_FILES=() - ################################### - # Send message that were skipping # - ################################### - debug "- 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 # - ######################### - info "${LINE}" - done - fi - - ######################################## - # Prepare context if TAP output format # - ######################################## - if IsTAP; then - TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") - INDEX=0 - mkdir -p "${REPORT_OUTPUT_FOLDER}" - REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" - fi - - ################## - # Lint the files # - ################## - for FILE in "${LIST_FILES[@]}"; do - - ######################################## - # Make sure we dont lint certain files # - ######################################## - if [[ ${FILE} == *"vault.yml"* ]] || [[ ${FILE} == *"galaxy.yml"* ]]; then - # This is a file we dont look at - continue - fi - - ################################## - # Increase the linted file index # - ################################## - (("INDEX++")) - - #################### - # Get the filename # - #################### - FILE_NAME=$(basename "${ANSIBLE_DIRECTORY}/${FILE}" 2>&1) - - ############## - # File print # - ############## - info "---------------------------" - info "File:[${FILE}]" - - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$("${LINTER_NAME}" -v -c "${ANSIBLE_LINTER_RULES}" "${ANSIBLE_DIRECTORY}/${FILE}" 2>&1) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - ######### - # Error # - ######### - error "Found errors in [${LINTER_NAME}] linter!" - error "[${LINT_CMD}]" - # Increment error count - ((ERRORS_FOUND_ANSIBLE++)) - - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP; then - NotOkTap "${INDEX}" "${FILE}" "${TMPFILE}" - AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" - fi - - else - ########### - # Success # - ########### - info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" - - ####################################################### - # Store the linting as a temporary file in TAP format # - ####################################################### - if IsTAP; then - OkTap "${INDEX}" "${FILE}" "${TMPFILE}" - fi - fi - done - - ################################# - # Generate report in TAP format # - ################################# - if IsTAP && [ ${INDEX} -gt 0 ]; then - HeaderTap "${INDEX}" "${REPORT_OUTPUT_FILE}" - cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" - fi + info "Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]" + fi else - ######################## - # No Ansible dir found # - ######################## - warn "No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]" - debug "skipping ansible lint" + warn "No TAP expected file found at:[${EXPECTED_FILE}]" + info "skipping report assertions" + ##################################### + # Append the file type to the array # + ##################################### + WARNING_ARRAY_TEST+=("${FILE_TYPE}") fi + fi + + ############################## + # Validate we ran some tests # + ############################## + if [ "${TESTS_RAN}" -eq 0 ]; then + ################################################# + # We failed to find files and no tests were ran # + ################################################# + error "Failed to find any tests ran for the Linter:[${LINTER_NAME}]"! + fatal "Please validate logic or that tests exist!" + fi +} +################################################################################ +#### Function RunTestCases ##################################################### +function RunTestCases() { + # This loop will run the test cases and exclude user code + # This is called from the automation process to validate new code + # When a PR is opened, the new code is validated with the default branch + # version of linter.sh, and a new container is built with the latest codebase + # for testing. That container is spun up, and ran, + # with the flag: TEST_CASE_RUN=true + # So that the new code can be validated against the test cases + + ################# + # Header prints # + ################# + info "----------------------------------------------" + info "-------------- TEST CASE RUN -----------------" + info "----------------------------------------------" + + ####################### + # Test case languages # + ####################### + # TestCodebase "Language" "Linter" "Linter-command" "Regex to find files" "Test Folder" + 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" ".*\.\(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" + TestCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "css" + TestCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "dart" + TestCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c ${DOCKER_LINTER_RULES}" ".*\(Dockerfile\)\$" "docker" + TestCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" ".*\.ext$" "editorconfig-checker" + TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "env" + TestCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "golang" + TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" + TestCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "html" + TestCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "javascript" + TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript" + TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json" + TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin" + TestCodebase "LUA" "lua" "luacheck" ".*\.\(lua\)\$" "lua" + TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown" + TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl" + TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php" + TestCodebase "PHP_PHPSTAN" "phpstan" "phpstan analyse --no-progress --no-ansi -c ${PHPSTAN_LINTER_RULES}" ".*\.\(php\)\$" "php" + TestCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi" + TestCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "powershell" + TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "protobuf" + TestCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "python" + TestCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config ${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "python" + TestCodebase "RAKU" "raku" "raku -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "raku" + TestCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES}" ".*\.\(rb\)\$" "ruby" + TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states" + TestCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "terraform" + TestCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "terraform_terrascan" + TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" + TestCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" + TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "xml" + TestCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "yml" + + ################# + # Footer prints # + ################# + # Call the footer to display run information + # and exit with error code + Footer +} +################################################################################ +#### Function LintAnsibleFiles ################################################# +function LintAnsibleFiles() { + ###################### + # Create Print Array # + ###################### + PRINT_ARRAY=() + + ################ + # print header # + ################ + PRINT_ARRAY+=("") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("Linting [Ansible] files...") + PRINT_ARRAY+=("----------------------------------------------") + PRINT_ARRAY+=("----------------------------------------------") + + ###################### + # Name of the linter # + ###################### + LINTER_NAME="ansible-lint" + + ########################################### + # Validate we have ansible-lint installed # + ########################################### + 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 + error "Failed to find ${LINTER_NAME} in system!" + fatal "[${VALIDATE_INSTALL_CMD}]" + else + # Success + debug "Successfully found binary in system" + debug "Location:[${VALIDATE_INSTALL_CMD}]" + fi + + ########################## + # Initialize empty Array # + ########################## + LIST_FILES=() + + ####################### + # Create flag to skip # + ####################### + SKIP_FLAG=0 + + ###################################################### + # Only go into ansible linter if we have base folder # + ###################################################### + if [ -d "${ANSIBLE_DIRECTORY}" ]; then + + ################################# + # Get list of all files to lint # + ################################# + mapfile -t LIST_FILES < <(ls "${ANSIBLE_DIRECTORY}"/*.{yaml,yml} 2>&1) + + ############################################################### + # Set the list to empty if only MD and TXT files were changed # + ############################################################### + # No need to run the full ansible checks on read only file changes + if [ "${READ_ONLY_CHANGE_FLAG}" -eq 0 ]; then + ########################## + # Set the array to empty # + ########################## + LIST_FILES=() + ################################### + # Send message that were skipping # + ################################### + debug "- 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 # + ######################### + info "${LINE}" + done + fi + + ######################################## + # Prepare context if TAP output format # + ######################################## + if IsTAP; then + TMPFILE=$(mktemp -q "/tmp/super-linter-${FILE_TYPE}.XXXXXX") + INDEX=0 + mkdir -p "${REPORT_OUTPUT_FOLDER}" + REPORT_OUTPUT_FILE="${REPORT_OUTPUT_FOLDER}/super-linter-${FILE_TYPE}.${OUTPUT_FORMAT}" + fi + + ################## + # Lint the files # + ################## + for FILE in "${LIST_FILES[@]}"; do + + ######################################## + # Make sure we dont lint certain files # + ######################################## + if [[ ${FILE} == *"vault.yml"* ]] || [[ ${FILE} == *"galaxy.yml"* ]]; then + # This is a file we dont look at + continue + fi + + ################################## + # Increase the linted file index # + ################################## + (("INDEX++")) + + #################### + # Get the filename # + #################### + FILE_NAME=$(basename "${ANSIBLE_DIRECTORY}/${FILE}" 2>&1) + + ############## + # File print # + ############## + info "---------------------------" + info "File:[${FILE}]" + + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$("${LINTER_NAME}" -v -c "${ANSIBLE_LINTER_RULES}" "${ANSIBLE_DIRECTORY}/${FILE}" 2>&1) + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + ######### + # Error # + ######### + error "Found errors in [${LINTER_NAME}] linter!" + error "[${LINT_CMD}]" + # Increment error count + ((ERRORS_FOUND_ANSIBLE++)) + + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + NotOkTap "${INDEX}" "${FILE}" "${TMPFILE}" + AddDetailedMessageIfEnabled "${LINT_CMD}" "${TMPFILE}" + fi + + else + ########### + # Success # + ########### + info " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully" + + ####################################################### + # Store the linting as a temporary file in TAP format # + ####################################################### + if IsTAP; then + OkTap "${INDEX}" "${FILE}" "${TMPFILE}" + fi + fi + done + + ################################# + # Generate report in TAP format # + ################################# + if IsTAP && [ ${INDEX} -gt 0 ]; then + HeaderTap "${INDEX}" "${REPORT_OUTPUT_FILE}" + cat "${TMPFILE}" >> "${REPORT_OUTPUT_FILE}" + fi + else + ######################## + # No Ansible dir found # + ######################## + warn "No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]" + debug "skipping ansible lint" + fi } ################################################################################ #### Function IsTap ############################################################ function IsTAP() { - if [ "${OUTPUT_FORMAT}" == "tap" ]; then - return 0 - else - return 1 - fi + if [ "${OUTPUT_FORMAT}" == "tap" ]; then + return 0 + else + return 1 + fi } ################################################################################ #### Function TransformTAPDetails ############################################## function TransformTAPDetails() { - DATA=${1} - if [ -n "${DATA}" ] && [ "${OUTPUT_DETAILS}" == "detailed" ]; then - ######################################################### - # Transform new lines to \\n, remove colours and colons # - ######################################################### - echo "${DATA}" | awk 'BEGIN{RS="\n";ORS="\\n"}1' | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" | tr ':' ' ' - fi + DATA=${1} + if [ -n "${DATA}" ] && [ "${OUTPUT_DETAILS}" == "detailed" ]; then + ######################################################### + # Transform new lines to \\n, remove colours and colons # + ######################################################### + echo "${DATA}" | awk 'BEGIN{RS="\n";ORS="\\n"}1' | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" | tr ':' ' ' + fi } ################################################################################ #### Function HeaderTap ######################################################## function HeaderTap() { - ################ - # Pull in Vars # - ################ - INDEX="${1}" # File being validated - OUTPUT_FILE="${2}" # Output location + ################ + # Pull in Vars # + ################ + INDEX="${1}" # File being validated + OUTPUT_FILE="${2}" # Output location - ################### - # Print the goods # - ################### - printf "TAP version 13\n1..%s\n" "${INDEX}" > "${OUTPUT_FILE}" + ################### + # Print the goods # + ################### + printf "TAP version 13\n1..%s\n" "${INDEX}" > "${OUTPUT_FILE}" } ################################################################################ #### Function OkTap ############################################################ function OkTap() { - ################ - # Pull in Vars # - ################ - INDEX="${1}" # Location - FILE="${2}" # File being validated - TEMP_FILE="${3}" # Temp file location + ################ + # Pull in Vars # + ################ + INDEX="${1}" # Location + FILE="${2}" # File being validated + TEMP_FILE="${3}" # Temp file location - ################### - # Print the goods # - ################### - echo "ok ${INDEX} - ${FILE}" >> "${TEMP_FILE}" + ################### + # Print the goods # + ################### + echo "ok ${INDEX} - ${FILE}" >> "${TEMP_FILE}" } ################################################################################ #### Function NotOkTap ######################################################### function NotOkTap() { - ################ - # Pull in Vars # - ################ - INDEX="${1}" # Location - FILE="${2}" # File being validated - TEMP_FILE="${3}" # Temp file location + ################ + # Pull in Vars # + ################ + INDEX="${1}" # Location + FILE="${2}" # File being validated + TEMP_FILE="${3}" # Temp file location - ################### - # Print the goods # - ################### - echo "not ok ${INDEX} - ${FILE}" >> "${TEMP_FILE}" + ################### + # Print the goods # + ################### + echo "not ok ${INDEX} - ${FILE}" >> "${TEMP_FILE}" } ################################################################################ #### Function AddDetailedMessageIfEnabled ###################################### function AddDetailedMessageIfEnabled() { - ################ - # Pull in Vars # - ################ - LINT_CMD="${1}" # Linter command - TEMP_FILE="${2}" # Temp file + ################ + # Pull in Vars # + ################ + LINT_CMD="${1}" # Linter command + TEMP_FILE="${2}" # Temp file - #################### - # Check the return # - #################### - DETAILED_MSG=$(TransformTAPDetails "${LINT_CMD}") - if [ -n "${DETAILED_MSG}" ]; then - printf " ---\n message: %s\n ...\n" "${DETAILED_MSG}" >> "${TEMP_FILE}" - fi + #################### + # Check the return # + #################### + DETAILED_MSG=$(TransformTAPDetails "${LINT_CMD}") + if [ -n "${DETAILED_MSG}" ]; then + printf " ---\n message: %s\n ...\n" "${DETAILED_MSG}" >> "${TEMP_FILE}" + fi } From 09a51babdf63766f8608839be8e757eb76bcba9c Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 15:46:14 -0500 Subject: [PATCH 42/52] Cleanup --- .automation/cleanup-docker.sh | 6 ++++++ .automation/upload-docker.sh | 6 ++++++ lib/termColors.sh | 27 --------------------------- 3 files changed, 12 insertions(+), 27 deletions(-) delete mode 100755 lib/termColors.sh diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index d9eb6312..a91cdcd2 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -13,6 +13,12 @@ # - System with Docker installed # - Global variables met +######################### +# Source Function Files # +######################### +# shellcheck source=/dev/null +source /action/lib/log.sh # Source the function script(s) + ########### # Globals # ########### diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index f9557959..ae819fdb 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -14,6 +14,12 @@ # - System with Docker installed # - Global variables met +######################### +# Source Function Files # +######################### +# shellcheck source=/dev/null +source /action/lib/log.sh # Source the function script(s) + ########### # Globals # ########### diff --git a/lib/termColors.sh b/lib/termColors.sh deleted file mode 100755 index 8f22a26c..00000000 --- a/lib/termColors.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -declare -Agr B=( - [B]=$(echo -e "\e[44m") - [C]=$(echo -e "\e[46m") - [G]=$(echo -e "\e[42m") - [K]=$(echo -e "\e[40m") - [M]=$(echo -e "\e[45m") - [R]=$(echo -e "\e[41m") - [W]=$(echo -e "\e[47m") - [Y]=$(echo -e "\e[43m") -) -declare -Agr F=( - [B]=$(echo -e "\e[0;34m") - [C]=$(echo -e "\e[0;36m") - [G]=$(echo -e "\e[0;32m") - [K]=$(echo -e "\e[0;30m") - [M]=$(echo -e "\e[0;35m") - [R]=$(echo -e "\e[0;31m") - [W]=$(echo -e "\e[0;37m") - [Y]=$(echo -e "\e[0;33m") -) -readonly NC=$(echo -e "\e[0m") - -export B -export F -export NC From 3c6a680bd617ac31d825d6f5b17c5725331b3962 Mon Sep 17 00:00:00 2001 From: Gabo Date: Thu, 30 Jul 2020 16:43:35 -0500 Subject: [PATCH 43/52] Fix yaml --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 09647ad9..60f02a22 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -118,7 +118,7 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP' 'PHP_PHPSTAN' 'POWERSHELL' 'PROTOBUF' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' - 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YML') + 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML') ############################################ # Array for all languages that were linted # From 4a2bf935b7d423955364d3e3fd3326f22701fe77 Mon Sep 17 00:00:00 2001 From: Gabo Date: Thu, 30 Jul 2020 18:12:17 -0500 Subject: [PATCH 44/52] Remane tests --- .automation/test/{yml => yaml}/README.md | 4 ++-- .automation/test/{yml => yaml}/reports/expected-YML.tap | 0 .automation/test/{yml => yaml}/yml_bad_1.yml | 0 .automation/test/{yml => yaml}/yml_good_1.yml | 0 lib/worker.sh | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename .automation/test/{yml => yaml}/README.md (87%) rename .automation/test/{yml => yaml}/reports/expected-YML.tap (100%) rename .automation/test/{yml => yaml}/yml_bad_1.yml (100%) rename .automation/test/{yml => yaml}/yml_good_1.yml (100%) diff --git a/.automation/test/yml/README.md b/.automation/test/yaml/README.md similarity index 87% rename from .automation/test/yml/README.md rename to .automation/test/yaml/README.md index 8016e848..3f42a5fa 100644 --- a/.automation/test/yml/README.md +++ b/.automation/test/yaml/README.md @@ -1,6 +1,6 @@ -# Yml Test Cases +# Yaml Test Cases -This folder holds the test cases for **Yml**. +This folder holds the test cases for **Yaml**. ## Additional Docs diff --git a/.automation/test/yml/reports/expected-YML.tap b/.automation/test/yaml/reports/expected-YML.tap similarity index 100% rename from .automation/test/yml/reports/expected-YML.tap rename to .automation/test/yaml/reports/expected-YML.tap diff --git a/.automation/test/yml/yml_bad_1.yml b/.automation/test/yaml/yml_bad_1.yml similarity index 100% rename from .automation/test/yml/yml_bad_1.yml rename to .automation/test/yaml/yml_bad_1.yml diff --git a/.automation/test/yml/yml_good_1.yml b/.automation/test/yaml/yml_good_1.yml similarity index 100% rename from .automation/test/yml/yml_good_1.yml rename to .automation/test/yaml/yml_good_1.yml diff --git a/lib/worker.sh b/lib/worker.sh index 3dbdb83c..31617599 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -604,7 +604,7 @@ function RunTestCases() { TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" TestCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "typescript" TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "xml" - TestCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "yml" + TestCodebase "YAML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "yaml" ################# # Footer prints # From 3de60e71cc5278b9be88f18c387688c9bbff96a5 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 30 Jul 2020 18:27:34 -0500 Subject: [PATCH 45/52] Fix log sources in docker scripts --- .automation/cleanup-docker.sh | 2 +- .automation/upload-docker.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index a91cdcd2..3115fa84 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -17,7 +17,7 @@ # Source Function Files # ######################### # shellcheck source=/dev/null -source /action/lib/log.sh # Source the function script(s) +source ../lib/log.sh # Source the function script(s) ########### # Globals # diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index ae819fdb..c31ffbde 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -18,7 +18,7 @@ # Source Function Files # ######################### # shellcheck source=/dev/null -source /action/lib/log.sh # Source the function script(s) +source ../lib/log.sh # Source the function script(s) ########### # Globals # From 94ab073fe31eb865a047ad0c2cdca9a9a7f9495e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2020 05:22:25 +0000 Subject: [PATCH 46/52] Bump eslint-plugin-jest from 23.19.0 to 23.20.0 in /dependencies Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 23.19.0 to 23.20.0. - [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases) - [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/master/CHANGELOG.md) - [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v23.19.0...v23.20.0) Signed-off-by: dependabot[bot] --- dependencies/package-lock.json | 6 +++--- dependencies/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dependencies/package-lock.json b/dependencies/package-lock.json index 8bf1fc2f..53ab1099 100644 --- a/dependencies/package-lock.json +++ b/dependencies/package-lock.json @@ -1925,9 +1925,9 @@ } }, "eslint-plugin-jest": { - "version": "23.19.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.19.0.tgz", - "integrity": "sha512-l5PLflALqnODl8Yy0H5hDs18aKJS1KTf66VZGXRpIhmbLbPLaTuMB2P+65fBpkdseSpnTVcIlBYvTvJSBi/itg==", + "version": "23.20.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.20.0.tgz", + "integrity": "sha512-+6BGQt85OREevBDWCvhqj1yYA4+BFK4XnRZSGJionuEYmcglMZYLNNBBemwzbqUAckURaHdJSBcjHPyrtypZOw==", "requires": { "@typescript-eslint/experimental-utils": "^2.5.0" }, diff --git a/dependencies/package.json b/dependencies/package.json index 3cec01fc..77513b78 100644 --- a/dependencies/package.json +++ b/dependencies/package.json @@ -9,7 +9,7 @@ "dockerfilelint": "^1.5.0", "eslint": "^7.5.0", "eslint-config-prettier": "^6.11.0", - "eslint-plugin-jest": "^23.19.0", + "eslint-plugin-jest": "^23.20.0", "htmlhint": "^0.14.1", "jsonlint": "^1.6.3", "markdownlint-cli": "^0.23.2", From a6e4fc879b37dae2316b5827cd78bc120cbd26cf Mon Sep 17 00:00:00 2001 From: Michikawa Masayoshi Date: Fri, 31 Jul 2020 19:56:36 +0900 Subject: [PATCH 47/52] Add rubocop-rspec to ruby linter dependencies --- dependencies/Gemfile | 1 + dependencies/Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+) diff --git a/dependencies/Gemfile b/dependencies/Gemfile index ab2a0684..ea9d82b6 100644 --- a/dependencies/Gemfile +++ b/dependencies/Gemfile @@ -8,3 +8,4 @@ gem "rubocop", "~> 0.82.0" gem "rubocop-github", "~> 0.16.0" gem "rubocop-performance", "~>1.7.1" gem "rubocop-rails", "~> 2.5" +gem "rubocop-rspec", "~> 1.41.0" diff --git a/dependencies/Gemfile.lock b/dependencies/Gemfile.lock index 9df0518b..076e8a5e 100644 --- a/dependencies/Gemfile.lock +++ b/dependencies/Gemfile.lock @@ -37,6 +37,8 @@ GEM activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 0.82.0) + rubocop-rspec (1.41.0) + rubocop (>= 0.68.1) ruby-progressbar (1.10.1) thread_safe (0.3.6) tzinfo (1.2.7) @@ -52,6 +54,7 @@ DEPENDENCIES rubocop-github (~> 0.16.0) rubocop-performance (~> 1.7.1) rubocop-rails (~> 2.5) + rubocop-rspec (~> 1.41.0) BUNDLED WITH 2.1.4 From 8d8bc80de18354467551a60bed846643306e1f61 Mon Sep 17 00:00:00 2001 From: Lukas Gravley Date: Fri, 31 Jul 2020 09:07:44 -0500 Subject: [PATCH 48/52] Update linter.sh --- lib/linter.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linter.sh b/lib/linter.sh index de9d129b..88bec682 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -23,6 +23,7 @@ source /action/lib/worker.sh # Source the function script(s) ########### # Default Vars DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location +GITHUB_API_URL='https://api.github.com' # GitHub API root url # Ansible Vars ANSIBLE_FILE_NAME='.ansible-lint.yml' # Name of the file ANSIBLE_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${ANSIBLE_FILE_NAME}" # Path to the Ansible lint rules From d1827a81f7882d176f70baef09d80380103f3719 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 31 Jul 2020 09:17:04 -0500 Subject: [PATCH 49/52] fixin it --- lib/linter.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 8e3d9e10..3d4eb9ef 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -268,7 +268,6 @@ FILE_ARRAY_LUA=() # Array of files to check FILE_ARRAY_MARKDOWN=() # Array of files to check FILE_ARRAY_OPENAPI=() # Array of files to check FILE_ARRAY_PERL=() # Array of files to check -FILE_ARRAY_PHP=() # Array of files to check FILE_ARRAY_PHP_BUILTIN=() # Array of files to check FILE_ARRAY_PHP_PHPCS=() # Array of files to check FILE_ARRAY_PHP_PSALM=() # Array of files to check From 84926171fb98a5d17246bc01b7b2d7c9778d6648 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 31 Jul 2020 09:54:58 -0500 Subject: [PATCH 50/52] fix arrays and add tests --- lib/buildFileList.sh | 4 +++- lib/possum.sh | 12 ++++++------ lib/worker.sh | 2 ++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 3e52de0f..b9b3de27 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -230,7 +230,9 @@ function BuildFileList() { ################################ # Append the file to the array # ################################ - FILE_ARRAY_PHP+=("${FILE}") + FILE_ARRAY_PHP_BUILTIN+=("${FILE}") + FILE_ARRAY_PHP_PHPCS+=("${FILE}") + FILE_ARRAY_PHP_PSALM+=("${FILE}") FILE_ARRAY_PHP_PHPSTAN+=("${FILE}") ########################################################## # Set the READ_ONLY_CHANGE_FLAG since this could be exec # diff --git a/lib/possum.sh b/lib/possum.sh index d867332b..172ccc00 100755 --- a/lib/possum.sh +++ b/lib/possum.sh @@ -8,12 +8,12 @@ cat << EOF @///////@///////////////@@@@ ( @, @/(&/@//////////////////// @ @////////////////////////@@ @ - @%////////(//////////%/////&@ @@ *,@ - @@@@@/@/#/////(&////////////////// .@ - *@@@@@. .%///(//@//////////////////&. .@@, @% - @@% .&@&&/@.@//&/////(////////// @@@@@@@@@ .. &@ - @@% @@@@@ @&/////////////////# @/ V @@/ ,@@@ @ -@@@% @@@@ .%@@@@//////#@ @ @@ @ .,. + @%////////(//////////%/////&@ @@ *,@ ______________ + @@@@@/@/#/////(&////////////////// .@ / \ + *@@@@@. .%///(//@//////////////////&. .@@, @% / Don't mind me \ + @@% .&@&&/@.@//&/////(////////// @@@@@@@@@ .. &@ / I'm just looking \ + @@% @@@@@ @&/////////////////# @/ V @@/ ,@@@ @ < for some trash... | +@@@% @@@@ .%@@@@//////#@ @ @@ @ .,. \__________________/ @@@/@( (@@@@% @/\ % @@@@( . .@@/\ # @ %@% diff --git a/lib/worker.sh b/lib/worker.sh index 31617599..3d35f1c7 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -590,6 +590,8 @@ function RunTestCases() { TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown" TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl" TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php" + TestCodebase "PHP_PHPCS" "phpcs" "phpcs --standard=${PHP_PHPCS_LINTER_RULES}" ".*\.\(php\)\$" "php" + TestCodebase "PHP_PSALM" "psalm" "psalm --config=${PHP_PSALM_LINTER_RULES}" ".*\.\(php\)\$" "php" TestCodebase "PHP_PHPSTAN" "phpstan" "phpstan analyse --no-progress --no-ansi -c ${PHPSTAN_LINTER_RULES}" ".*\.\(php\)\$" "php" TestCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi" TestCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "powershell" From 56894ef49a2388137fe3ead1bd4bef743e7a4584 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 3 Aug 2020 14:14:54 -0500 Subject: [PATCH 51/52] fixed the cool guy --- lib/possum.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/possum.sh b/lib/possum.sh index 172ccc00..92944cdd 100755 --- a/lib/possum.sh +++ b/lib/possum.sh @@ -9,11 +9,11 @@ cat << EOF @/(&/@//////////////////// @ @////////////////////////@@ @ @%////////(//////////%/////&@ @@ *,@ ______________ - @@@@@/@/#/////(&////////////////// .@ / \ - *@@@@@. .%///(//@//////////////////&. .@@, @% / Don't mind me \ - @@% .&@&&/@.@//&/////(////////// @@@@@@@@@ .. &@ / I'm just looking \ + @@@@@/@/#/////(&////////////////// .@ / \\ + *@@@@@. .%///(//@//////////////////&. .@@, @% / Don't mind me \\ + @@% .&@&&/@.@//&/////(////////// @@@@@@@@@ .. &@ / I'm just looking \\ @@% @@@@@ @&/////////////////# @/ V @@/ ,@@@ @ < for some trash... | -@@@% @@@@ .%@@@@//////#@ @ @@ @ .,. \__________________/ +@@@% @@@@ .%@@@@//////#@ @ @@ @ .,. \\__________________/ @@@/@( (@@@@% @/\ % @@@@( . .@@/\ # @ %@% From 12a064d4097813139d8f82ef9c380b75ca56da57 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 3 Aug 2020 14:17:54 -0500 Subject: [PATCH 52/52] add lib --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9e1a9559..22d9a952 100644 --- a/Dockerfile +++ b/Dockerfile @@ -65,7 +65,7 @@ RUN apk add --update --no-cache \ npm nodejs-current \ openjdk8-jre \ perl \ - php7 php7-phar php7-json php7-mbstring \ + php7 php7-phar php7-json php7-mbstring php-xmlwriter \ php7-tokenizer php7-ctype php7-curl php7-dom \ py3-setuptools \ readline-dev \